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 .
×

Help - Scriptcard commands to apply damage to a set group needed

1771984381

Edited 1771985087
Kofi
Pro
In its simplest form - I would like to hit a button and it applies damage to the same 5 designated tokens no matter where they are on the battlefield.  I would like to do that without needing to select the 5 every time.  Long form: I have a battle coming up 60 on 40.  the good guys (team 40) are broken up into 4 groups (lets call them A, B, C, D).  Each round, each of the allied groups will take damage until the PCs complete certain actions.   My theory: I remember reading that each token has an ID number.  Is there a way to get it? How do I add it to an apply damage command?  What does the add damage scriptcard command look like?  Using D&D 2014 character sheets if that makes a difference. 
1772023699
timmaugh
Roll20 Production Team
API Scripter
If you're going to hardcode the token IDs, you can first collect them just by selecting each token individually and running: @{selected|token_id} Or, if you have the Metascript Toolbox installed, you can select each of your "squads" as a group and run: !forselected(^) @^(selected.token_id) {^&simple} However, allow me to introduce you to a couple of scripts that can help automate this part... Install the MetascriptToolbox, and you'll get a script called SelectManager. SelectManager can automatically select tokens on the map in many ways (name, partial names, bar values, status markers, etc.). The particulars of that syntax is discussed here. For example, if all of GroupA was named "GroupA-1", "GroupA-2", etc., then you could use: {&select GroupA*} And those tokens would be selected for purposes of the API (you would use that construction right in the command line of your other script, in this case ScriptCards, and the tokens would be "selected" by the time ScriptCards sees the message). Another script to consider is Assemble... which uses the idea of pre-built groups of tokens as a way to speed things up. It gives you an interface to quickly build your "group" and save it to an attribute for quick retrieval. Assemble will work with SelectManager (the attribute of assembled token_ids will expand into the {&select} tag) or it will directly work with a script that offers a place to put the IDs of the tokens you wish to affect. For instance, if you'd collected all of your GroupA token IDs into an attribute named "Battle01_GroupA" on a character named "BattleGroups", you would retrieve it by: @{BattleGroups|Battle01_GroupA} SelectManager would want those IDs separated by commas, so if you collected them that way (the default for Assemble), you could use that attribute in a SelectManager {&select} tag: {&select @{BattleGroups|Battle01_GroupA} } If you were to use it in a script like TokenMod, which offers you an argument of "--ids", you'd want to collect the IDs separated by spaces. Then you could use it like: !token-mod --ids @{BattleGroups|Battle01_GroupA} --set bar1_value... You can put the different attributes referring to your different groups into a query dropdown and use the same command line for each of them, if necessary: ?{Which group?|Group A,@{BattleGroups|Battle01_GroupA}|Group B,@{BattleGroups|Battle01_GroupB},Group C,@{BattleGroups|Battle01_GroupC}} I'm not sure of the ScriptCards syntax, but these at least will make the token selection process automation work easier for you. Simply applying damage to a token (or backing character) would be easy enough to do with TokenMod (for the former) or ChatSetAttr (for the latter).
Thank you @timmaugh,  I added SelectManager and it allows for me to group the tokens ahead of time.     I am still lost on how to apply damage though.  I played with token-mod but I don't know how to get it into scriptcard.  Below is what I have and where the holes are: !scriptcard  {{   --#title|Massive Battle   --#leftsub|The Fate of the Realm Hangs in the Balance     --=Damage|1d20   --+Hit!|Group A takes  [$Damage] points of  damage in their defense of the realm.   --/| Here is where I would like a persistent Damage to be applied to GroupA   --+|"Does Group A still suffer under Spirit Guardians?" --:MAIN_MENU|     --+Options|[rbutton]Yes::ExtraDamage[/rbutton] [rbutton]No::NoExtra[/rbutton]     --X|End the execution of the script until the player presses the button aligning with their choice of action(s) --:ExtraDamage|   --=XDamage|4d8 [Radiant]   --+Hit!|Group A takes  [$XDamage] points of radiant damage from Spirit Guardians.   --/| Here is where I would like the XDamage to be applied to GroupA   --^Final| --:NoExtra|   --^Final|   --:Final| }}
1772076158
timmaugh
Roll20 Production Team
API Scripter
I'm not the best resource for ScriptCards, but I can tell you that it will help the people who *are* good resources for ScriptCards to understand what it means for you to "apply damage". Specifically... ...what system are you playing? ...what sheet are you using? ...if these are "mook" tokens, where is their "health" or "hit points" tracked (ie, which bar)? ...if these are tokens that represent characters, what attribute tracks their health/hit points?
I am using the 2014 5e character sheets with jumpgate.  they all have hit points and the tokenmod command:   !token-mod --set bar1_value|-10 {&select GroupA*} works in isolation, but I don't know how to get it to use a 4d8 roll instead of a fixed number (-10) or how to insert it into Scriptcards.  Or perhaps I could use the Scriptcard apply damage commands
1772112398
timmaugh
Roll20 Production Team
API Scripter
Again, I'll have to leave it to a ScriptCard-ioso to chime in on the ScriptCard commands around applying damage directly, but to your point about TokenMod... The way to use a roll with a script (like TokenMod) is generally to use inline roll notation: !token-mod --set bar1_value|-[[4d8]] {&select GroupA*} Now, since you installed the Metascript Toolbox (you did install the whole Toolbox from the 1-click, correct? Not just SelectManager?), you can actually give each token their OWN result of that roll, if you wanted to. That is, if 10 tokens in GroupA were supposed to take 4d8, but each should have their own individual result of how much damage was to apply to them, you can do that like this: !forselected(^) token-mod --set bar1_value|-[^[^4d8^]^] {&select GroupA*} That will iterate over the tokens and give them their own roll. If you did that, you might deplete 1 token's bar1 value before another (since they are all being reduced by different amounts). In that case, you might want to alter your {&select} tag to only select those GroupA tokens that had a bar1 value over 0.... so you don't continue to try to deplete them: {&select GroupA*, +bar1>0} As for how to send either of these from ScriptCards (I guess if you wanted a panel of output reporting the work was done?)... I believe that syntax would look like: --@scriptTriggeringHandle|_argument _argument2 Basically, put your handle between the "@" and "|", and put the rest of the line after the pipe, changing all double-hyphens to a single underscore. So the TokenMod command line would look like: --@token-mod|_set bar1_value|-[[4d8]] {&select GroupA*} (For future reference, it looks like ScriptCards will see that roll and reduce it out to the roll's value before dispatching the message for the intended target script... so instead of TokenMod getting a message with a roll in it, it will receive a message where the command line property includes the raw value derived from the roll. For a roll like 4d8, that won't matter. For something that would require several returns from a rollable table, that might matter, more.)
!!!!YES!!! This right here is perfect:  --@token-mod|_set bar1_value|-[[4d8]] {&select GroupA*}  I actually don't need an output of how much damage each unit took. Its all background combat to build tension, provide  a "clock", and give a consequence for action/inaction, so just seeing the HP bars dropping is sufficient.  I will tinker with the  -[^[^4d8^]^] individual damage but that is just icing on the cake. 
Sooo close.  everything works great except the second set value command the one after the prompt doesnt work.  Likely its a ScriptCard thing I am not aware of.  !scriptcard  {{   --#title|Massive Battle   --#leftsub|The Fate of the Realm Hangs in the Balance    --@token-mod|_set bar1_value|-[[1d4]] {&select Orc*}   --+|"Do the Orcs still suffer under Spirit Guardians?" --:MAIN_MENU|     --+Options|[rbutton]Yes::ExtraDamage[/rbutton] [rbutton]No::NoExtra[/rbutton]     --X|End the execution of the script until the player presses the button aligning with their choice of action(s) --:ExtraDamage|  --+Hit!|Group A takes  additional damage from Spirit Guardians.  --@token-mod|_set bar1_value|-[[3d8]] {&select Orc*}   --^Final| --:NoExtra|   --^Final|   --:Final| }}
1772125351
timmaugh
Roll20 Production Team
API Scripter
Hmm... so, this could be a timing issue. When  you issue the ScriptCards command (which is going to issue a TokenMod command), things happen like: Roll20 parsing , then Metascript Parsing, then Normal Script Parsing (ScriptCards) Then ScriptCards understands you want to send the TokenMod command, so it sends a new message... which goes: Roll20 parsing, then Metascript Parsing Normal Script Parsing (TokenMod) The timing issue could be because when the metascripts originally work on the message, they're working on the first message (the one going to ScriptCards). In THAT message they select the tokens for you, so when ScriptCards sees the message, it sees that there were tokens selected (Orcs found by "Orc*"). At that point, the text: {&select Orc*} ...is consumed out of the message. Then ScriptCards sends the TokenMod command line, which no longer includes the metascript tag {&select}. So it doesn't know what tokens to work on, and it doesn't do anything. (I'm surprised that the first TokenMod command would work in the ScriptCards code since it would fall victim to this problem, as well.) The way to get around this is to *hide* the {&select} tag from being seen during the metascript parsing that happens as the first message is on its way to ScriptCards, but then have it *unhidden* when it gets sent to TokenMod (to be discovered during the metascript parsing that happens when the secondary messages are on their way to TokenMod). Since this timing has to be managed AFTER ScriptCards receives the message, a metascript deferral won't work (if you don't know what that means... don't worry; it just means that a normal trick we can use to hide/unhide something won't work because it will be unhidden by the time ScriptCards sees the message, so it won't help our timing). You have to instead use a ScriptCards deferral character. I *believe*... and you should read that verrry elongated, because this is pulling from the wayback brain machine... I *belieeeeeeeeeeeeeeeeeeeeeve* ScriptCards defaults the caret character to be the deferral character (though you can configure it to be something else). To use the deferral character, you'd insert it into the metascript tag in a place that would break up the text recognition... typically between the "{" and the "@": {^&select Orc*} So, try that and see if I'm correct about ScriptCard's default deferral character. If not, you'll have to look that up in the help (or how to set it). NOTE that deferring the {&select} tag will mean that it will not process during the first message (on the way to ScriptCards)... so when the message reaches ScriptCards the tokens that ScriptCards will see as selected will be the ones still selected on the map. If you need ScriptCards to ALSO see the tokens discovered by the {&select Orcs*} tag, you will need to includ ANOTHER tag in the body of the message, somewhere... and this one leave not-deferred (so it processes in the first message).
1772125639
timmaugh
Roll20 Production Team
API Scripter
BTW, if ScriptCard's default deferral character is the caret, AND if you also want to try the individualized damage provided by the "forselected" message, then you're either going to have to config ScriptCards to not use the caret (at least for that line) OR you're going to have to change the forselected deferral character... for instance, to a tilde: !forselected(~)... ...which would become, in ScriptCards: --@forselected(~)|... ...and then use that tilde in the rolls: [~[~4d8~]~] This is because forselected introduces yet ANOTHER round of messages after the first message (to ScriptCards) and second message (to forselected)... it will then send out a message to TokenMod for each token selected. I know, it's a lot to keep straight, but post if you have any questions.
Putting the caret on the second select worked:  --:ExtraDamage|  --+Hit!|Group A takes  additional damage from Spirit Guardians.  --@token-mod|_set bar1_value|-[[1d8]] {^&select Orc*}   --^Final| I even got the  foreselected function to work:  --@forselected(^) token-mod|_set bar1_value|-[^[^1d4^]^] {&select Orc*}    for the first line and   --@forselected(^) token-mod|_set bar1_value|-[^[^1d8^]^] {^&select Orc*} for the second one, no need for the tilde.
1772137581
timmaugh
Pro
API Scripter
Kofi said: I even got the  foreselected function to work: ... ...no need for the tilde. Yep... the tilde would only be needed if: 1) you wanted to put your forselected lines in the ScriptCard, and 2) the ScriptCard deferral was already the caret... ...in which case the easiest thing would be to change what forselected was using for its deferral character (ie, changing to a tilde). Glad you got it working!
Thank you for your help!