Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Script] Spawn Default Token Thread 2

Hey David,  Something that I noticed, and I may be doing wrong, is that when I spawn a token for a character sheet that has a default token that is a drawing, the spawned token no longer is and snaps to the grid.  Is there a way to prevent that behavior? Thanks!
1628339511
David M.
Pro
API Scripter
Erik, try using the --isdrawing command. --isDrawing| < yes/true/1/no/false/0 > //DEFAULT = false. Sets the isdrawing property of spawned token So you would want to use: --isDrawing|true             Note you can turn non-drawing tokens into drawings with this, too.
Ah perfect! Thanks!
First of all, this is amazing! I've been playing with this all week, and I have so many fun commands and macros made spawning monsters from rollable tables, expanding, and all sorts of fun stuff! You're awesome! Secondly, I'm trying to set up a way for the !spawn command to work without selecting a token on the map manually. This is particularly useful on big maps, or in my case, when I'm using other tabs often. I've been trying to experiment with @{target|xx}, and tried using the token_id, but I'm a bit stumped. I want it to look something like this:  !spawn *--location*|@{token_id/charName/character_id}  --name|funmonsters --etc... I'm still new to the whole API thing so please forgive me if its formatted wrong or impossible.  Thanks!
1628509497
David M.
Pro
API Scripter
Daniel, it's not you. The script currently doesn't support that, but it has been brought up enough times that I should probably do some thing about it :) I'll see what I can come up with when I get a chance to work on it - hopefully this evening.
1628513053
timmaugh
Pro
API Scripter
daniel e. said: Secondly, I'm trying to set up a way for the !spawn command to work without selecting a token on the map manually. This is particularly useful on big maps, or in my case, when I'm using other tabs often. I've been trying to experiment with @{target|xx}, and tried using the token_id, but I'm a bit stumped You can use SelectManager in addition to Spawn. SelectManager can "virtually" select a token for the purposes of a message command. {& select Bob} {& select -M1234567890abcdef} {& select @{target|token_id}} It takes a comma-separated list of tokens you want to select. The first formation (above) will find the first "Bob" it sees on the current page. The next 2 are obviously specific to the ID of the token you are passing. Add the formation you need anywhere in your Spawn command line... it will process and be removed before Spawn sees the line.
1628515772
David M.
Pro
API Scripter
Thanks, Tim, I had forgotten about that trick! Daniel, here is a working example of what Tim is talking about: !Spawn {& select @{target|token_id}} {{   --name|imp   --offset|1,0 }}
Hi, David! This is a fantastic script, so thank you for making it available to the community. I'm having some difficulty with the --light command. What I would like to do is get a spawned token to emanate bright light to 20 feet, and then dim light to an additional 20 feet, for a total of 40 feet of illumination. I'm using UDL, which your post here seems to indicate is supported, using the syntax --light|x,y, where X is bright light and Y is dim light. When I trigger my !Spawn command, though, I get a radius of 20 feet bright, 0 feet dim. The default token is set up for 20 ft/20 ft., and as you can see from the snippet I have pasted below, I also am explicitly setting 20ft/20ft. Neither method works. If I drag my token from the journal to the map, my default settings are preserved, so I am reasonably sure that this is an issue with the script. Any insight would be greatly appreciated. Here's my command: !Spawn {{ --name|Dancing Lights --qty|4 --offset|2,0 --size|1 --placement|cross 1 --light|20,20 }}
1628529262

Edited 1628529306
David M.
Pro
API Scripter
Edward, sounds like you are running into Roll20's UDL bug relating to api-generated tokens that was kinda fixed but is still somewhat broken. See my post here on the UDL bugs forum. Hopefully the Devs can take care of this soon. If this doesn't describe your problem, post back here and we'll see if we can figure it out.
I think we're looking at the same bug, yes. Thank you for pointing out your UDL bug post.
Hello everyone! Thank you for answering my other question about using {& select 'x'}!!! I now have a wonderful new question to bother you with. So using spawndefaulttoken, you can manually change the size of the token, but is there a way to make the tokens spawn in their default state? For instance, I'm using a roll table to choose a random monster, and spawn it in a random location on the map:  ///!Spawn{{{& select SB}  --name|#randmed  --qty|[[ 1d3 ]] --placement|grid 3 --offset|[[(2*(1d2-1)-1)*1d6]],[[(2*(1d2-1)-1)*1d4]] }} &{template:default} {{name=Chat Spawned a Monster!}}/// Is there a way to make the token size match what it should normally be? I tried messing around and looking up the expand command, but it just made them appear expanding. Once again, feel free to assume I know absolutely nothing, because I sure feel like I don't! Secondly, I want to have in the template chat box: {{template:whatever}} {{name=whatever}} {{ xQTY of xMonster have been spawned}} I tried copying my roll table, but it spat out a different monster, because it rolled again, instead of outputting the name of the roll before. 
1628949241
David M.
Pro
API Scripter
Daniel, the default token size info is actually not stored in the api graphic object(!). For 5e OGL character sheets, there is a token_size attribute, but it would be different for every sheet (if included at all). If using 5e, you could assign the default token size with something like this: --size|@{Kobold|token_size}  However, you won't be able to dynamically generate this for any given (e.g. queried, rolled) character name***, since attribute values get expanded before being passed to the api. Can only hardcode like I have in the example. ***If timmaugh is lurking, there is a decent chance that some meta-script magic can make this dynamic! If not, and you are willing to install Scriptcards and SelectManager , there is a kind of kludgy workaround, but it would require a bit of data entry to set up, and I'm not sure how much this would slow things down if a bunch of possible creatures were added. Basically, use a query to return the character_id, then use scriptcards notation to grab the name and token_size. Then dynamically build a Spawn command (using a forselected from SelectManager).   See example below choosing between a behir and a kobold, lol. Again, you'd have to pre-identify what creatures you'd want the scriptcard to handle. Not super ideal, but it works. Another note: when spawning multiple qtys of larger tokens using --placement, they will overlap somewhat and will need to be repositioned. !script {{ --#title|Chat Spawned a Monster! --&id|?{Enter a name|Behir,@{Behir|character_id}|Kobold,@{Kobold|character_id}} --&name|[*[&id]:name] --=tokenSize|[*[&id]:token_size] --=qty|?{Enter a Qty|6} --@forselected|Spawn _name|[&name] _offset|1,0 _qty|[$qty] _size|[$tokenSize] _placement|grid 3 --+Result|[$qty] [&name](s) Spawned }} Also note that I'm outputting a scriptcard line in the example above with the info that you wanted the default template to have. It looks something like this:
David,  Thank you for the tip, I am looking into using the Scriptcards API to get this setup, but I'm a little unfamiliar with it so I'm just going to stumble through the commands a bit. After looking on the scriptcards wiki, and using your example as a reference, I think I might be able to get the random monster element worked in. Thanks for your help! I'm sure I will have more questions in the future, so sorry in advance!!!
1629120948

Edited 1629175876
timmaugh
Pro
API Scripter
David M. said: If using 5e, you could assign the default token size with something like this: --size|@{Kobold|token_size}  However, you won't be able to dynamically generate this for any given (e.g. queried, rolled) character name***, since attribute values get expanded before being passed to the api. Can only hardcode like I have in the example. ***If timmaugh is lurking, there is a decent chance that some meta-script magic can make this dynamic! Yep, there is! Although my lurksomeness wasn't very lurksome this weekend... but I'm here now. =D I can think of a couple ways to do it with metascripts. The basic concept we're trying to solve is that Daniel wants to have a random monster derived from his table, and then use the particular parameters of that monster to populate the Spawn commands. Like David said, the Roll20 order of operations will resolve a query before the roll against the table, so we need to stack up our steps on the backside of the roll. That means we need a way to extract the information from the roll. ZeroFrame can help with that: [[1t[Monsters]]].value Any inline roll appended with .value will extract the value in that position of the command line. It works for re-using rolls, too: $[[0]].value That much will be required for any of the below options. Option 1 - Fetch & ZeroFrame If you are playing in 5E (to make use of the token_size attribute David mentioned), or you want to add that attribute to your monster character sheets, you can use Fetch. Assuming your rollable table returns the name of the monster you wish to spawn: @($[[0]].value.token_size[1]) ZeroFrame extracts the value of the roll first, leaving a valid Fetch call when it does. As long as your rollable table of monsters returned the name of a monster that matched your a character sheet, and each of those characters had an attribute named "token_size" you could use this method. That means you could expand it beyond 5E, but you'd have to manually add the field to each monster character sheet. If Fetch doesn't find the attribute you ask for, it returns the default value you provide (in the above example, I supplied 1 as the default). Working Example: !Spawn {{ {&select SB} --name|[[1t[Monsters]]].value --size|@($[[0]].value.token_size[1]) --qty|[[1d3]] --placement|grid 3 --offset|[[(2*(1d2-1)-1)*1d6]],[[(2*(1d2-1)-1)*1d4]] }} Option 2 - Fetch & ZeroFrame Another option using Fetch would be to have a single character sheet that housed all of the token sizes you might need, and have them named according to a pattern. If the character were named "GameData", and the attributes were named token_size_Kobold , token_size_Calamari , etc., you could do: @(GameData.token_size_$[[0]].value[1]) Now you have a single place to store all of the sizes you need, and you don't have to store an individual size for each character (if all of the humans are going to be the same size, just have a single entry). Working Example: !Spawn {{ {&select SB} --name|[[1t[Monsters]]].value --size|@(GameData.token_size_$[[0]].value[1]) --qty|[[1d3]] --placement|grid 3 --offset|[[(2*(1d2-1)-1)*1d6]],[[(2*(1d2-1)-1)*1d4]] }} Option 3 - Muler Muler sets up character abilities to be tables of information. This would be much like Option 2, above, except that instead of a bunch of different attributes on a character, it would be a series of entries in the same ability. The same "GameData" character can work for this; it can serve multiple purposes (if you had a reason to use the Option 2 method for one problem, you could still use it as a Mule character for Muler). On that character, if you name an ability TokenSizes, and you structure the contents of that ability like this: Human=1 Kobold=2 Calamari=3 ...(making the sizes appropriate to your system), then you could do this in your Spawn command: get.GameData.TokenSizes.$[[0]].value/get That would retrieve the size for the monster that resulted from rolling against your table. Working Example: !Spawn {{ {&select SB} {& mule GameData.TokenSizes} --name|[[1t[Monsters]]].value --size|get.GameData.TokenSizes.$[[0]].value/get --qty|[[1d3]] --placement|grid 3 --offset|[[(2*(1d2-1)-1)*1d6]],[[(2*(1d2-1)-1)*1d4]] }} Note: There is an additional bit of syntax (included on the first line) to tell Muler to load the Mule that holds the variables you want to retrieve. In this case, we needed to return data from the TokenSizes Mule, so we told it to load that one. Note, the second: While this option might seem less intuitive at the beginning, having a little more syntax in the command line and having all of the token size information in a single ability rather than individual attributes, it begins to pay for itself if you have multiple pieces of information you want to return for a given monster. To illustrate that, imagine wanting to return 4 pieces of information about a monster that aren't tracked on the normal character sheet for that monster. Now imagine tracking those 4 pieces of information for 9 monsters. Even tracking all of that on a single character sheet can get painful if they each are housed in different attributes. Instead, Muler gives you the ability to have all of the information together... you could have 9 mules (monsters) with 4 pieces of information, or you could have 4 mules (information characteristics) that list an entry for each of 9 monsters. While there might not be multiple datapoints you need for a given monster just for the Spawn command, if you begin to spread into ScriptCards to launch things like Spawn, TokenMod, etc., then you may very well arrive at multiple pieces of information you need only *after* you determine what kind of monster you are dealing with. That's where this method can really shine.
I'm having some difficulties, and I hope someone can help me figure out what's going awry. I am using the following Spawn command line: !Spawn {{ --name|Spiritual Weapon --qty| 1 --sheet|Spiritual Weapon --ability|SummonDuration --placement|surround --offset| 0,0 --force| yes --order |toFront }} And as you can see, I'm spawning a Spiritual Weapon, calling the "SummonDuration" ability from its sheet. SummonDuration is a ChatSetAttr command, as follows: !setattr --charid -MWVRFrtIemdokQHcODw --SummonDuration|[[@{selected|CL_Cleric}]]|[[@{selected|CL_Cleric}]] What is intended to happen is that the spawn command detailed above will spawn a Spiritual Weapon. In the process, it fires the SummonDuration ability, which assigns the newly spawned Spiritual Weapon a duration equal to the caster level of the character that creates it. So if @CL_Cleric is 3, then we get 3/3 for SummonDuration. As of yesterday, this command worked. Today, it doesn't; instead I get an error report: (From SpawnAPI):  Unhandled exception: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-] or [0-9] but "s" found. Digging deeper, I also get the following output in the API output console: "!setattr --charid -MWVRFrtIemdokQHcODw --SummonDuration|[[@{selected|CL_Cleric}]]|[[@{selected|CL_Cleric}]]" "ERROR: Unable to find character selected in chat command." "Error     at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:165:1), <anonymous>:637:11)     at String.replace (<anonymous>)     at Object.d20.textchat.doChatInput (eval at <anonymous> (/home/node/d20-api-server/api.js:165:1), <anonymous>:549:29)     at sendChat (/home/node/d20-api-server/api.js:1880:16)     at processCommands (apiscript.js:12553:17)     at handleInput (apiscript.js:12729:36)     at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:161:1), <anonymous>:65:16)     at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:161:1), <anonymous>:70:8)     at /home/node/d20-api-server/api.js:1722:12     at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560" I have found that if I manually activate the SummonDuration ability, it works correctly, so I know that there's nothing incorrect happening with the !SetAttr command line. If I modify the !SetAttr line so that I replace "selected" portion of @{selected|CL_Cleric} with the name of the character e.g. "@{Bob|CL_Cleric}", then the !Spawn command above works correctly. So it appears that SpawnAPI doesn't like "selected" values in an ability. But surely that isn't normal or expected behavior. Am I missing something?
1629587408
David M.
Pro
API Scripter
Hmm, can't say I know exactly what is going on here. At first, I was surprised that it used to work before, as the api is pretty squirrely when it comes to remembering which token is selected. The call ability functionality of Spawn is something that I thought would be more useful than it actually was in practice. Certain things never worked right (like whispers, queries, and chat menus in abilities seem to break things), even though the approach is very simple: Spawn just grabs the text of the ability and regurgitates it to the chat window with a sendChat from the original player. I can confirm that I'm getting the same behavior that you described. Again, not sure what is happening now that would have been different a day (or two) ago. While the following isn't a satisfying answer, I was able to get it to do what you want by eliminating the --sheet and --ability commands, and just tacking the !setattr line at the bottom of my macro, like this: !Spawn {{ --name|Spiritual Weapon --qty| 1 --placement|surround --offset| 0,0 --force| yes --order |toFront }} !setattr --charid -MWVRFrtIemdokQHcODw --SummonDuration|[[@{selected|CL_Cleric}]]|[[@{selected|CL_Cleric}]] Maybe someone else might be able to chime in with an explanation with what is actually going on with the original setup (e.g. maybe something changed on the Roll20 back-end, or some kind of timing issue that is now causing problems?).
Your solution is what I ended up doing. It's not perfect, but it's still a pretty major lifestyle upgrade versus having the whole process execute manually. The main cause of sadness on this (for me, anyway) is that when the macro fired appropriately, I could assign a value to @SummonDuration via the SummonDuration ability and include a "--mook|yes" argument. That got me a duration bar that would count down separately for each entity summoned, which was super cool.
1629660116
David M.
Pro
API Scripter
Ah, ok if your goal was just to populate a bar value, you can use a bar override command which will only affect that instance of the token. By default, when you override a bar value with Spawn it removes that linked character attribute without needing --mook|yes (btw, you can keep the link by adding the KeepLink keyword, though we won't be doing that obviously). Here's an example of a Spawn macro that I think has the effect you are looking for. I used bar3 in this example. I reduced some extraneous commands also, as --qty|1 is the default, and a --placement|surround with --offset|0,0 is the same as just using --offset|0,-1. If there were other bar values you wanted to de-link then you could add the --mook command. !Spawn {{ --name|Spiritual Weapon --offset|0,-1 --force|yes --order|toFront --bar3|@{selected|CL_Cleric}/@{selected|CL_Cleric} }}
That is fantastic. You are a gentleman and a scholar.
1631488341

Edited 1631489684
David M. said: Thanks, Tim, I had forgotten about that trick! Daniel, here is a working example of what Tim is talking about: !Spawn {& select @{target|token_id}} {{   --name|imp   --offset|1,0 }} David, this is cool!  I will have to go back an update my targetted spells with this trick!  Any idea how to make this work within Scriptcards?  I know that we got Spawn working in Scriptcards using --forselected|spawn ... But is there a way to use this trick within Scriptcards, calling Spawn Token on a targetted token?  I'm thinking for things like Fireball.  The player puts a target token out on the map.  He casts Fireball (using a Scriptcards).  But finding a way to also spawn in the Fireball spell token and eat the target token would be great. UPDATE:  I did get this working by adding a dummy variable to my Scriptcards.  Similar to how I got this working with the Concentration script when casting a spell on a target token.   --=NotUsed|{&select @{target|token_id}}
1631531113
David M.
Pro
API Scripter
Great!
Hey David! This API is really useful, but I'm having trouble doing something with it. I'm trying to summon a creature, then randomize its health. The command I'm using is this: !Spawn {{ --name|Troll --offset|-1,-2 --mook|yes --force|yes --fx|explode-magic --size|2,2 --expand|20,50 --placement|random,3 --bar3|[[d50+25]]/[[d50+25]] --sheet|Troll --ability|Health }} But, a problem with this is the health bar comes out to something like 60/42 or something like that. If I were to just to bar3|[[d50+25]], it doesn't show the health bar since the max is blanked out, or it's whatever value/50, which I had as the default link to the character sheet. I've tried tokenmod's bar3_reset command, and that's what the ability is, but nothing happens. It seems like the command doesn't even run (when I try to use it with --ability. It works fine if I manually use bar3_reset). 
1631756814

Edited 1631756848
David M.
Pro
API Scripter
Version Update: v0.22 (bug fix for bar override commands) -  Development gist Thanks to Camden S. for pointing this one out!   Now, when bar override commands are used and no max is specified, the max  will default to the bar value specified Examples: --bar3|10                        //bar3 set to 10, max set to 10 --bar1|10 / 20                   //bar1 set to 10, max set to 20 --bar2|[[8d8+16]]                //bar2 set to whatever was rolled, max set to that same value --bar2|[[8d8+16]] / 100          //bar2 set to whatever was rolled, max set to 100
1631757002
David M.
Pro
API Scripter
Thanks, Camden! Sorry for the trouble. Let me know if you have any issues with the update :) You'll need to manually install v0.22 until I can get a pull request through to update the 1-click version.
Thank you! It's no trouble. I'm pretty new to API scripts and really roll20 in general, so it's really mere of a hobby than anything else.
Hey man I've been getting a lot of use from your script and I've been trying to use it in conjunction with another script to name spawned multi-sided tokens according to their side. I know your script uses the name of the token off of the character sheet so I found a script written by another user a few years ago that adds the table item name from the rollable table to the token name and changes when the side is changed. on('ready',function(){ "use strict"; let nameFromSide = function(token,prev){ let imgs=_.map(token.get('sides').split(/\|/),(i)=>{ return i.replace(/%([a-zA-Z0-9]{2})/g,(m,n)=>String.fromCharCode(parseInt(`0x${n}`))); }), img=token.get('imgsrc'), tableItem=_.chain(findObjs({type:'tableitem'})) .reduce( (m,i)=>{ m[i.get('rollabletableid')] = m[i.get('rollabletableid')]||[]; m[i.get('rollabletableid')].push(i); return m; },{}) .filter( (t)=>{ return _.keys(t).length===imgs.length;}) .reduce( (m,t)=>{ let count=_.reduce(t,(cnt,ti)=>{ if(_.contains(imgs,ti.get('avatar'))){ cnt++; } return cnt; },0); if(count===imgs.length){ m.push(t); } return m; },[]) .first() .filter(t=>t.get('avatar')===img) .value()[0]; if(tableItem && tableItem.get){ token.set({ name: tableItem.get('name'), showname: true }); } }; on('change:token:currentSide',nameFromSide); on('add:token',function(obj,prev){ if(obj.get('sides').length){ nameFromSide(obj,prev); } }); }); I was wondering if there was a way I could easily implement this such that when I spawn a token with !Spawn --name| --side|random it will rename the token to the table name entry. I'm not really familiar with Javascript so I've been trying to add a few lines to your script to get this to work to no success.
1632745992
David M.
Pro
API Scripter
@Inky, sorry for the delay. I was hoping I'd get some flash of inspiration for a solution. Sadly, it hasn't come. This is actually a more complicated problem for Spawn. When setting a random side, the script isn't actually rolling on the rollable table. It generates a random integer based on the number of "sides" the default token has. When you create a rollable table token and set as the default token, the "link" between the rollable table and the default token is lost. The default token object only stores a list of image files and the "current side" of the token. The "name" of the side is not stored with the default token. Also, if you were to update the rollable table, the default token is unaffected until you go through the whole setup process again (create a new multi-sided token from the table, then set as default). The only way I can think to do what you are asking is to ask for the rollable table name from which the default token was created. However, this would often lead to problems because of the lack of synchronization mentioned above. This would lead to mis-named tokens or out-of-range errors (e.g. asking for the 11th item in a 10-item table if an entry was deleted).  A foolproof solution for Spawn is not apparent to me at this time. I think it would be possible to write a Scriptcard that could dynamically generate your Spawn syntax to set the --tokenName override parameter, but you'd have to hardcode the lookup in the scriptcard and have a new scriptcard for each multi-sided token you wanted to spawn in this way. You'd also still have to manually maintain this scriptcard macro every time you updated the rollable table. Given these caveats it's probably not be worth it, but if you really want to go down that route you can PM me and I can see if we can come up with something.
Hi, I'd like to know if there's a possibility to resize a token by half. For example I have a black pudding that i have enlarged to be 4x4 size. But i'd like to be able to reduce it for example twice. First time it is slashed, it goes down to 2x2 size, and then slashed again to 1x1 size (and why not to 0.5x0.5 on the next....) Is there a possibility to spawn a size|/2,/2 (or maybe *0.5) from the selected token (and resize source to half of what it was with something like resizesource|/2,/2 ?? Don't know if it's possible though, as it would need to recall the actual size of the token. Thanks for your help.
1633086663

Edited 1633086835
David M.
Pro
API Scripter
Here's an easy way to do what you're looking for, Lionel. Using this earlier post as a starting point, I added a query for the new sizes of the spawned and original pudding. Had to include html replacements for the commas in the query return values, so they return something like "2,2' without breaking the query. This spawns a new pudding with half hp and reduces the size and hp of the original one (selected). !Spawn {{ --name|Black Pudding --offset|1,0 --expand|20,50 --size|?{New size?|3x3,3,3|2x2,2,2|1x1,1,1} --resizeSource|?{New size?} --bar1| [[floor(@{selected|bar1}/2)]] / [[floor(@{selected|bar1}/2)]] }} !token-mod --set bar1|[[floor(@{selected|bar1}/2)]]
Thanks a lot David.  Yes on my side too I thought about prompting the sizes. I was wondering if it could be automated but this version works fine too.  Thanks à lot for your help, as always! 
It seems to like you could do it dynamically by calling the current token size and doing division from there.
1633098032

Edited 1633098473
David M.
Pro
API Scripter
Yeah, I thought about that, but it looks like the @{selected|token_size} property doesn't automatically change when you resize the token! Think maybe it is tied to the default token size?  EDIT -   see this explanation of the attribute from one of the devs. It is a compendium setting that seems to be read-only. You could also make a scriptcard to do it (grabbing the selected token width/height and dynamically generating the Spawn syntax), but it seemed a simple enough solution with a single query.
1633104297

Edited 1633114771
timmaugh
Pro
API Scripter
You could store that value in a Mule, and cycle through the various sizes... If the mule (ability) were on a character named "Donkey", and the mule was named "SpawnSizes", you could store various spawned tokens by their name. In this case "Black Pudding". Black Pudding=4 Then the Spawn portion from what David posted, just above, would be (I think): !Spawn {{ --name|Black Pudding --offset|1,0 --expand|20,50 --size|get.Black Pudding/get,get.Black Pudding/get --resizeSource|get.Black Pudding/get,get.Black Pudding/get --bar1| [[floor(@{selected|bar1}/2)]] / [[floor(@{selected|bar1}/2)]] }} set.Black Pudding={&math round(get.Black Pudding/get/2,2)}/set{& mule Donkey.SpawnSizes} Then you might want a "reset" for the Black Pudding as a separate macro: !set.Black Pudding=?{New value|4}/set {& mule Donkey.SpawnSizes} That would get the token's spawn size reset to whatever you wanted. REQUIRED SCRIPTS: Spawn, Muler, MathOps, SelectManager, ZeroFrame EDIT: Had a typo in the script; fixed at 3pm EST
Wow OK. That's a full configuration lol.  Thank you. On my mobile now but I'll give it a try.  David's solution might be the easiest way but Tim's is a demonstration that everything is actually possible. 
i might have already asked you this so sorry if so: is there a way to set  --placement|  to randomly distribute over a given radius? I'm sure i remember this being possible but can't see it as an option
1634916394
David M.
Pro
API Scripter
@lark --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 this----------> // 'random,rand #' : randomly populates tokens within a (# by #) square grid so something like --placement|random, 5
I'm having a bit of issues getting this script to work with Scriptcards as of late, I'm not quite sure what happened since it used to work fine and I haven't found anything in the updates of either to necessarily cause this to stop working. I figured I'd poke about it and see if I'm not missing something: !scriptcard {{     --@forselected+|!Spawn _name|Fungal Infestation _offset|0,-1 _qty|1 _fx|burst-death }} Executing the command on its own works but now it does nothing. I was hoping for an error message at the least but I'm getting nothing.
1636923951
David M.
Pro
API Scripter
Hey non, the scriptcard macro you posted works for me (after I substituted the name for a character in my journal). What happens when you just run this? !Spawn --name|Fungal Infestation --offset|0,-1 --qty|1 --fx|burst-death
Two things to check: You shouldn't need the ! in your content line You probably need a {&select } tag in your content line non said: I'm having a bit of issues getting this script to work with Scriptcards as of late, I'm not quite sure what happened since it used to work fine and I haven't found anything in the updates of either to necessarily cause this to stop working. I figured I'd poke about it and see if I'm not missing something: !scriptcard {{     --@forselected+|!Spawn _name|Fungal Infestation _offset|0,-1 _qty|1 _fx|burst-death }} Executing the command on its own works but now it does nothing. I was hoping for an error message at the least but I'm getting nothing.
1637006253
David M.
Pro
API Scripter
Non's scriptcard worked for me as written, however, so I suspect something else is going on other than scriptcard syntax.  
1637013253
timmaugh
Pro
API Scripter
I can confirm that syntax for forselected (as used in a ScriptCard), though as Colin mentions you shouldn't need the exclamation point before Spawn. If David's suggested test works (just running the Spawn command with the token selected), then you could try running the forselected version NOT in a ScriptCard: !forselected Spawn --name|Fungal Infestation --offset|0,-1 --qty|1 --fx|burst-death (you shouldn't need the +, that implements an automatic replacement which you're not making use of in your downstream command line anyway).
Apologies for the late response, but for some reason my original macro works now? I swear things always start working the second you ask for help. Thanks for the suggestions!
Hi, first of all - awesome work! I intend use this script for my expanse game, among other things to spawn torpedos launched from a ship. Currently I do: !Spawn --name| Torpedo --qty|?{how many?|1|2|3|4} --placement| rand 4 --offset| 0,-5 --bar3|/@{selected|Skill-Sensoren} I store the "Sensor" Rating of the firing ship in the torpedos Bar3-max so I can use it later, when someone tries to evade/shoot down the torpedo. Now, what I also would like to do - and I haven't figured out if that's possible at all currently - is to either rename the spawned tokens based on the source token, or better yet, put something in the tooltip of the token. Torpedos are spawned relatively small and I'd like to have them no nameplate. However, it might be interesting whose torp I am looking at, so my idea was to put it in the tooltip as in "Torpedo fired by ship XY (at ship ZZ)" As I have no way of getting the token_id of the spawned token, I thought it might be possible with the --ability - e.g. call an ability on the spawned torpedo to call token-mod to set the tooltip. But it seems that I have no luck there, as macros don't get expanded. Any other idea?  Regards Thomas
1637153973
David M.
Pro
API Scripter
Ah yes, support for the new tooltip feature is a good idea. I'll add it soon.
That would indeed be wonderful! Thanks :)
1637437048

Edited 1637437282
hi! i'm trying to summon 2 toekns at the target location with scriptcard but i keep getting this error: NO TOKENS No selected tokens to use for that command. Please select some tokens then try again. i tried doing what i found in other forum posts, but to no avail, do you have a solution? thank yoi very much! ! script {{ --/| Script Name : 5 E Magic Missile --/| Version : 2.0 --/| Requires SC : 1.4 . 0 +, alterbars or token - mod to apply damage ( Optional ) --/| Author : Kurt Jaegers --/| Description : Handles the D & D 5 E spell Magic Missile , with the ability to select a dynamic --/| number of targets . --/| --/| You can optionally have damage applied to impacted tokens . The script defaults to using --/| TokenMod to update Bar 3. These can be changed by altering the settings below . --/| If you use one die roll for Magic Missile , update the damageMode variable below . --/| Set this to either "token-mod" , "alterbars" , or anything else to not apply damage --& damageApplyScript | token - mod --/| Set this to the bar number you use to track hit points --& hitPointsBar | 1 --/| If damageMode is 1 , a separate die will be rolled for each missile . Set this variable to 0 to , --/| only have a single damage die roll applied to each missile . --& damageMode | 1 --/| Magic Missile by the book does Force damage . --& damageType | elettrico --/|===================== There are no customization options below this line ===================== --# title | Meduse --# sourceToken |@{ selected | token_id } --> GetAndCheckAp --= SlotLevel | 40 --= SkillLevel |[* S : ms_4_lv ] --= MissileCount |[ $SkillLevel ] + 1 --= OneMissileDamage |[ $SkillDmg ] --> BuildAndAskTargets |[ $MissileCount . Total ] --= DisplayCount | 1 --= MissileDamage | 0 --# leftsub | Ap [ $SlotLevel ] --# rightsub | Ranged Attack --# emoteText |@{ selected | character_name } usa [ $SlotLevel . Total ] AP per lanciare [ $MissileCount . Total ] meduse elettrificate ! --: GetAndCheckAp | --= ApCost | 30 --= ApDisp |[* S : Ap ] --?[ $ApCost . Total ] - gt [ $ApDisp . Total ]| NoSlotsLeft --<| --/| Determine damage subroutine . Start by assuming we aren 't going to apply damag e --& damageRoutine | DontApplyDamage --?[& damageApplyScript ] - eq "token-mod" |& damageRoutine ; ApplyDamageTokenmod --?[& damageApplyScript ] - eq "alterbars" |& damageRoutine ; ApplyDamageAlterbars --: MissileLoop | --> FireMissile |[ $DisplayCount . Total ] --= DisplayCount |[ $DisplayCount ] + 1 --?[ $DisplayCount ] - le [ $MissileCount ]| MissileLoop --> UsaAp | --# rightsub | Paralizza + Veleno -- X | --: FireMissile | --& ThisTarget |[& target [% 1 %]] --= SkillAtk |( 1 d4 + 1 + [* S : totale_intelligenza ] ) * 10 --= EnemyDef |( 10 + { 0 , [ * [ & ThisTarget]:t - bar3_max] } kh1) --=SkillDmg|( [$SkillAtk] / [$EnemyDef] ) {FLOOR} --@forselected+| Spawn _name|Surtur _offset|0,-1 _qty|1 --?[ & damageMode] -eq 1|=ThisMissile;[$SkillDmg]|=ThisMissile;[$OneMissileDamage] --=MissileDamage|[$MissileDamage] + [$ThisMissile] --+Medusa|[$DisplayCount.Total]: [ $ThisMissile ] danni base . --> PlayEffects |@{ selected | token_id };[& ThisTarget ]; none ; bomb - holy ; none ; none --= ResultantDamage |[ $ThisMissile . Raw ] --? "[*[&ThisTarget]:npc_immunities]" - inc "[&damageType]" | Immune --? "[*[&ThisTarget]:npc_resistances]" - inc "[&damageType]" | Resistant --? "[*[&ThisTarget]:npc_vulnerabilities]" - inc "[&damageType]" | Vulnerable --^ DoneResist | --: Immune | --= ResultantDamage | 0 --+ La Medusa |[ $DisplayCount . Total ] colpisce con i suoi tentacoli [*[& ThisTarget ]: t - name ], ma questo sembra ignorarla ! --^ DoneResist | --: Resistant | --= ResultantDamage |[ $ThisMissile ] \ 2 --+ Medusa |[ $DisplayCount . Total ] colpisce [*[& ThisTarget ]: t - name ] per [ $ResultantDamage ] danni [ b ] elettrici [/ b ] --^ DoneResist | --: Vulnerable | --= ResultantDamage |[ $ThisMissile ] * 2 --+ Medusa |[ $DisplayCount . Total ] colpisce [*[& ThisTarget ]: t - name ] per [ $ResultantDamage ] danni [ b ] elettrici [/ b ] --^ DoneResist | --: DoneResist | -->[& damageRoutine ]|[& ThisTarget ];[& hitPointsBar ];[ $ResultantDamage . Raw ] --<| --: BuildAndAskTargets | --& TargetString | --= targetCount | 1 --: TargetLoop | --& TargetString |+ t ; target [ $targetCount . Raw ]; Missile [ $targetCount . Raw ] Target --= targetCount |[ $targetCount . Raw ] + 1 --?[ $targetCount ] - le [% 1 %]|> AddSeparator --?[ $targetCount ] - le [% 1 %]| TargetLoop -- iPlease click the button below to select magic missile targets . The same target can be selected multiple times ; Select [% 1 %] Targets |[& TargetString ] --/| --<| --: AddSeparator | --& TargetString |+|| --<| --: NoSlotsLeft | --+|[* S : character_name ] non ha abbastanza AP . [ $ApDisp . Total ] AP disponibili . -- X | --/|===================== Subroutines ===================== --: ApplyDamageTokenmod | Parameters are tokenid ; bar #; amount --@ token - mod | _ignore - selected _ids [% 1 %] _set statusmarkers | Paralizzato | Poisoned bar [% 2 %] _value |-[% 3 %] --<| --/| Just a dummy routine that doesn 't do anything, but it is easier to do it this way than adding logic to see if we ar e --/| skipping applying damage in the main routine . --: DontApplyDamage | --<| --: UsaAp | --= ApDisp |[ $ApDisp ] - [ $ApCost ] --@ modattr | _charid [* S : character_id ] _Ap |-[ $ApCost ] --<| --: PlayEffects | Parameters are : sourcetoken ; targettoken ; source effect ; target effect ; line effect ; sound effect -- vtoken |[% 1 %] [% 3 %] -- vtoken |[% 2 %] [% 4 %] -- vbetweentokens |[% 1 %] [% 2 %] [% 5 %] --@ roll20AM | _audio , play ,nomenu| [ % 6 % ] --<| }}
1637448477
David M.
Pro
API Scripter
Andrea, that error message looks like it is coming from SelectManager. If I remove all of your other code, the Spawn syntax works correctly for me, for example: !script {{   --#hidecard|1   --@forselected+|Spawn _name|Surtur _offset|0,-1 _qty|1 }}  So, my guess is it has something to do with the reentrant function in your script (when the scriptcard pauses and you query for targets with the chat button before resuming the script). SelectManager might be losing track of the selected token along the way? Maybe timmaugh and/or Kurt will come across this and have some deeper insight on the scriptcard/SelectManager interaction with reentrant scriptcards.
David M. said: Andrea, that error message looks like it is coming from SelectManager. If I remove all of your other code, the Spawn syntax works correctly for me, for example: !script {{   --#hidecard|1   --@forselected+|Spawn _name|Surtur _offset|0,-1 _qty|1 }}  So, my guess is it has something to do with the reentrant function in your script (when the scriptcard pauses and you query for targets with the chat button before resuming the script). SelectManager might be losing track of the selected token along the way? Maybe timmaugh and/or Kurt will come across this and have some deeper insight on the scriptcard/SelectManager interaction with reentrant scriptcards. thanks David, i feared as much, i tried to do the same and it worked, but since my scripting is more ofa trial and error approach, i wasn't sure if i made some mistake or if it was an API problem! thank you so much again!
I think you can do something like  --@forselected+|Spawn _name|Surtur _offset|0,-1 _qty|1 {^&select @{selected|token_id}} What should happen is: @{selected|token_id} gets parsed out through the Roll20 chat server ScriptCards runs until you get to the reentry button ScriptCards runs again, stripping out the ^  character in the {^&select structure, which then processes to virtually select the same original selected token ... PROFIT!
IT WORKS!!!!! GENIUS!!! thank you so much!!! now i have to ask, do you know if i can also find a way to summon those two tokens to the target location? or is asking too much? i mean i can drag the tokens but it would be cool to be able to summon them there! thank you again!! Colin C. said: I think you can do something like  --@forselected+|Spawn _name|Surtur _offset|0,-1 _qty|1 {^&select @{selected|token_id}} What should happen is: @{selected|token_id} gets parsed out through the Roll20 chat server ScriptCards runs until you get to the reentry button ScriptCards runs again, stripping out the ^  character in the {^&select structure, which then processes to virtually select the same original selected token ... PROFIT!