So this started out as a simple script to help automate KeithCurtis' cool trick using rollable table tokens and !token-mod to generate spell effects, illustrated here , but kind of expanded from there. I first looked at King's excellent !Summon script, but it seemed like it did not support setting sides of rollable table tokens or some other features I was looking for, so I thought it would be a fun project. Kind of went down a rabbit hole with options, but it was a fun learning experience. Thought I would share in case others found a use for it or had any suggestions for new or existing features, or just had general feedback like "...but why?". Many thanks to TheAaron, timmaugh, GiGs, and others who helped me through a few technical roadblocks along the way! I'm sure it is a hot mess as I was learning stuff as I went, but it seems to work and was fun so I'm ok with that. Concept Like !Summon, !Spawn can be used for spell effects, monster summoning, cataclysmic terrain changes, or any similar type application. The general idea is to automatically spawn the default token for a given "character" with various options for token qty, location/arrangement, and certain token properties such as size, side (for rollable table tokens), light emission, and "represents" property. In addition, I wanted to be able to automatically call a character "Ability" after the spawn event. This last part has a few caveats, which I will address later in the post. Example: Click image to see Animated gif of a baddy raising 8 minions/mooks (appearing as random sides of a rollable table token) around each of two targets: Version History --v0.2 fixes bug that prevented non rollable table tokens from spawning correctly --v0.3 provides UDL support for the --light command. See updated command notes for differences in use of this command between LDL & UDL --v0.4 supports floating point (decimal) --size parameters for partial square token sizes --v0.5 added limited support for triggering FX at spawn origin points. See updated command notes. Currently no custom FX or those that require directional input. --v0.6 now compatible with the TheAaron's TokenNameNumber script (v0.5.12 or later). Spawned tokens whose default token has the text %%NUMBERED%% somewhere in the name will have a sequential number appended to their name. --v0.7 added new placement option --placement|cross # , which distributes spawned tokens similar to "burst,", but in a vertical & horizontal reticle arrangement. # is radius (in squares) of the innermost spawned tokens relative to the origin token(s). --v0.8 added ability to override the token bar values. --bar1| <current> / <max> . Max is optional. If command is used, then the corresponding bar "link" will be removed, if present. Values for current & max can be formulas using attributes and/or queries. e.g. --bar1| [[ @{charName|constitution}+10*?{Spell Level?|1} ]] --v0.9 added new command --expand| #,# , which causes the token to spawn first as a point, and then expand to full size based on user configurable number of frames and delay between frames (determining frame rate). --v0.10 bug fix for certain cases where the default token does not have layer information. Now explicitly sets the spawn layer to that of the origin token(s). Side benefit: can now spawn on non-object layers (e.g. GM layer). Get the code here: <a href="https://github.com/djmoorehead/roll20-api-scripts/blob/master/Spawn%20Default%20Token/SpawnDefaultToken.js" rel="nofollow">https://github.com/djmoorehead/roll20-api-scripts/blob/master/Spawn%20Default%20Token/SpawnDefaultToken.js</a> Instructions Case 1: Selected token is the basis for spawn origin To use, select one or more tokens on the map, and call the script with at minimum the name of the "character" to summon. The following will simply spawn 1 of the default character tokens in the center of each selected token. !Spawn --name|charName Case 2: Target token is the basis for spawn origin Initial token selection is still required (as it is used for some defaults), but you can optionally cause the tokens to spawn at targeted token(s), with a little trickery. Roll20 has a standing bug that if both selected and target tokens are passed to an api script, the selected tokens are not retained. To get around this, after the initial call, the script will generate a chat button to prompt for a number of targets and will call itself again with the now complete set of information. !Spawn --name|charName --targets|2 A complete description of commands is included below. Note: I put < > around each of the parameters for readability. Don't include < > for actual use. ! Spawn {{
-- name | < charName > //(REQUIRED) name of the character whose target we want to spawn
-- targets | < # > //Destination override. Instead of using selected token(s) as origin, use target token(s)
-- qty | < # > // DEFAULT = 1 . How many tokens to spawn at each origin point. MAX = 20
//supports hardcoded and rollable table inline rolls such as [[ 1d6 ]] and [[ 1t[tableName] ]]
-- offset | < #,# > //X,Y pos or neg shift in position of the spawn origin point(s) relative to the origin token(s), in number of SQUARES
//DEFAULT = 0,0 // (NOTE: a POSITIVE Y offset means LOWER on the map)
--placement| < option > //How to arrange the tokens relative to the origin point (+ offset). Options are:
//' stack ' : (DEFAULT) All tokens will be stacked on top of each other
//' row ' : A horizontal row of tokens
//' column , col ' : A vertical column of tokens
//' surround ' : A clockwise spiral placement around origin token, starting at top (NOTE: any supplied offset will be ignored)
//' grid #' : A square grid with "#" tokens per row. Raster left to right
//' burst #' : An expanding diagonal distribution of tokens starting "#" squares from the 4 origin token corners. Large qty will form an "X" pattern
// 'cross #' = "evenly" distributed vert/horiz cross pattern, starting directly above origin by # squares. Large qty will form a "+" pattern
-- size | < #,# > // DEFAULT = 1,1 (X,Y) - How many SQUARES wide and tall are the spawned tokens?
-- side | < # or rand > // DEFAULT = 1 . Sets the side of a rollable table token.
// # : Sets the side of all spawned tokens to "#"
// 'rand,random' : Each spawned token will be set to a random side
-- order | < option > //The z-order of the token. (NOTE: a recent Roll20 "feature" will always put character tokens with sight above those without, so YMMV.)
// toFront,front,top,above : Spawn token moved to front
// toBack,back,bottom,below : Spawn token moved to back
-- light | < #,# > //Set light radius that all players can see.
// For Legacy Dynamic Lighting (LDL):
//First # is the total radius of the light (light_radius) //Second # is the start of dim light (light_dimradius) (so: 10,5 will be 10 ft of total light, with dim radius starting at 5ft)
// For Updated Dynamic Lighting (UDL):
//First # is the radius of bright light (bright_light_distance)
//Second # is the additional radius of dim light (so: 10,5 will be 10ft of bright light + 5ft of dim light)
-- mook | < yes/no > // DEFAULT = false (the "represents" characteristic of the token is removed so changes to one linked attribute, e.g. hp, will not propagate to other associated tokens.
//If set to true, linked attributes will affect all tokens associated with that sheet
-- force | < yes/no > // DEFAULT = false . The origin point is by default relative to the geometric center of the origin token
//Origin tokens of larger than 1x1 may spawn tokens in between squares, which may be strange depending on the specific case
//Set to true in order to force the token to spawn in a full square
-- sheet | < charName2 > // DEFAULT = selected character . The character sheet in which to look for the supplied ability
//useful if the ability exists on a "macro mule", etc.
-- ability | < abilityName > //The ability to trigger after spawning occurs. With caveats as described below
--fx| < type-color > //Trigger FX at each origin point.
//Supported types are: bomb,bubbling,burn,burst,explode,glow,missile,nova,splatter
//Supported colors are: acid,blood,charm,death,fire,frost,holy,magic,slime,smoke,water
--bar1| < currentVal/optionalMax > //overrides the token's bar1 current and max values. Max is optional. If overridden, bar1_link will be removed
--bar2| < currentVal/optionalMax > //overrides the token's bar2 current and max values. Max is optional. If overridden, bar2_link will be removed
--bar3| < currentVal/optionalMax > //overrides the token's bar3 current and max values. Max is optional. If overridden, bar3_link will be removed
-- expand| < #frames, delay > //Animates the token during spawn. Expands from size = 0 to max size
//#frames: how many frames the expansion animation will use. Start with something like 20
//delay: how many milliseconds between triggering each frame? Start with something like 50. Any less than 30 may appear instant
}} The --placement option is the trickiest one to describe, so here is a reference chart to show how --placement and --offset relate to each other for multiple tokens. Note how the --offset command is ignored for the --placement|surround option. Here is a completely unrealistic example from a game mechanics standpoint, spawning 1d4+1 Dancing Lights or Flaming Spheres in a burst 1 pattern originating three squares below a target token, then triggering the "SpellTemplate" ability on the "Yelric" character sheet. !Spawn supports multi-line commands using the double bracket syntax. Also, will support case insensitive search and allows extra spaces between commands, parameters and delimiting characters ("--", "|", and ","), so the following will still work: !Spawn {{
--naMe | GenericSpellAoE
--targeTs |1
--qty| [[ 1d4 + 1 ]]
--offset | 0 , 3
--placement| buRst 1
-- size|1,1
--side| ?{Spell?|Dancing Lights,7 |Flaming Sphere,2}
--order | toFront
--light| 10,-5
--force|yes
--sheet|YeLriC
--ability|SpellteMplAte
}} Caveats/Known Issues 1) Like with any other scripts that affect images, Roll20 limits api access to only images found in the user's personal art library . Annoying. So, if you have purchased Marketplace content, you will have to go through the arduous process of getting those images into your "My Library". Select token, press Z, right-click, save image locally, then re-upload to Roll20. 2) Also not currently accessible by the api are: Bar position & bar styles . So, no compact bottom overlapping bars for your spawned mooks until Roll20 allows that to happen. 3) The Ability triggered after spawning is currently pretty temperamental. This is irritating because it was one of the main features I was looking for. The following seem to cause problems: a) When the ability contains a query, things break. b) When the ability is whispered, it just gets ignored (?!). I don't fully understand this. I have a cheesy workaround that kinda works but is not yet implemented, as it forces the whisper to the player that made the api call. This probably would be ok for 99% of cases, but I'd like it to be more generic. There is a forum thread here that discusses the issue. c) If the ability calls another ability or macro either directly or via chat buttons, things break. Chat buttons will be created, but will fail when clicked NOTE: If anybody wants to wade through any of these Ability issues, it is found at the very bottom of the processCommands function. Search for the comment " automatic trigger of a supplied ability " to jump directly to that portion of the code. I think I went overkill on the error handling, so I haven't encountered anything that will crash the sandbox (yet) :) That's about it for now. This post is long enough, so thanks for getting this far! I can include some other examples in later posts.