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] ScriptCards - My "Spiritual Successor" to PowerCards

Sorry I am looking for a way to select more than 1 target but not seeing the snake if its ready to bite me.  Can someone help me? with the syntax?
Bradley P. said: Sorry I am looking for a way to select more than 1 target but not seeing the snake if its ready to bite me.  Can someone help me? with the syntax? Depending on how many targets you need to select you can use the following: @{target|Target 1|token_id}, @{target|Target 2|token_id}, @{target|Target 3|token_id} Use commas to separate each target and make sure to change the number in the middle. If you have more targets in your list than what the Character is selecting, they will have to continue selecting until it cycles through all targets. Example: The Wizard casts Magic Missile at 1st level (3 darts) and you have 5 targets in your list. The Wizard will select his 3 targets (they can all be the same) but Roll20 will still register that 2 more need to be selected, they will have to select the other 2, but the spell will only select the first 3. You do have to do a little finagling with the script thought to make this happen. See Kurt J's  Magic Missile Example  to see how this works.
David M. said: Michael, I finally got a chance to look at this. I came up with something using the BubbleSort algorithm, but it's not very pretty. I basically took the array containing all the tokens on the page and filtered for range and npc_condition_immunites, but instead of populating an inRange array, I populated three indexed variables for hp, name, and tokenid (so hp0, hp1, name0, name1, etc). Then edited the BubbleUp procedure to do the index swapping for all three variable sets. You could add or subtract any variables you don't need (like probably name), but I figured you would need tokenid to do your condition marker. If you remove name, be sure to remove the corresponding block from the BubbleUp procedure. Currently I am just outputting the varaible sets before and after sorting, but you should be able to easily add the stuff you want to do with the sorted values. !script {{ --#title|Sorting values from arrays Example --:(1) GET ALL TOKENS INTO THE "allTokens" ARRAY| will have blank 1st element to be removed later --~|array;pagetokens;allTokens;@{selected|token_id} --:(2) CREATE THE "inRange" ARRAY TO HOLD TOKENS IN RANGE| --~|array;define;inRange; --:(3) PREP ARRAY FOR LOOP| if no array elements then end macro --~tokenid|array;getfirst;allTokens --?[&tokenid] -eq ArrayError|endOutput --:(4) FIND ALL TOKENS IN RANGE| add indexed roll variables for tokID, name, & hp --=numToks|0 --=i|0 --+~~~Tok Order BEFORE sorting~~~| --:RangeLoop| --:TOKEN MUST BE ON OBJECTS OR GMLAYER AND TYPE MUST INCLUDE UNDEAD| --?[*[&tokenid]:t-layer] -ne objects -and [*[&tokenid]:t-layer] -ne gmlayer|NextToken --?"[*[&tokenid]:npc_condition_immunities]" -inc "sleep" -or [*[&tokenid]:t-bar1_value] -lt 1|NextToken --:CHECK DISTANCE IN UNITS. 20ft is 4UNITS| --~dist|euclideandistance;@{selected|token_id};[&tokenid] --?[$dist] -gt 4|NextToken --:ADD TO THE "ARRAYS" OF VARIABLES| --&tokID[$i.Total]|[&tokenid] --&name[$i.Total]|[*[&tokenid]:t-name] --=hp[$i.Total]|[*[&tokenid]:t-bar1_value] --=numToks|[$numToks] + 1 --:OUTPUT PRE_SORTED VALS| --+Tok[$i.Total]|[&name[$i.Total]], [$hp[$i.Total]], [&tokID[$i.Total]] --=i|[$i] + 1 --/~|array;add;inRange;[&tokenid] --:NextToken| --~tokenid|array;getnext;allTokens --?[&tokenid] -ne ArrayError|RangeLoop --:(5) SORT ALL "ARRAY" VARIABLES BY HP VALUE WITH A BUBBLE SORT| --=max_i|[$i] --=i|0 --:OuterLoop| --=i|[$i]+1 --=j|[$i] --:InnerLoop| --=j|[$j]+1 --?[$hp[$i.Total]] -gt [$hp[$j.Total]] |>BubbleUp;[$i.Total];[$j.Total] --?[$j.Total] -lt [$NumDice.Total]|InnerLoop --?[$i.Total] -lt [$max_i.Total]|OuterLoop --:(6) OUTPUT THE SORTED VARIABLES| --=i|0 --+~~~Tok Order AFTER sorting~~~| --:SortLoop| --+Tok[$i.Total]|[&name[$i.Total]], [$hp[$i.Total]], [&tokID[$i.Total]] --=i|[$i]+1 --?[$i.Total] -lt [$numToks.Total]|SortLoop --:End| --X| --:PROCEDURES| --:BubbleUp| accepts i, j as parameters. Swaps var[i] & var[j] for three variables --=Temp|[$hp[%2%]] --=hp[%2%]|[$hp[%1%]] --=hp[%1%]|[$Temp] --&Temp|[&tokID[%2%]] --&tokID[%2%]|[&tokID[%1%]] --&tokID[%1%]|[&Temp] --&Temp|[&name[%2%]] --&name[%2%]|[&name[%1%]] --&name[%1%]|[&Temp] --<| }} Sample output: I just saw this here. Has anyone built a script for the Sleep spell using this (or similar) coding that they'd like to share? I will admit that I'm still a bit of a noob when it comes to scripting and some of this is waaaaaaaayyy above my head.
Anyone have a scriptcard for initiative that add it to the turn tracker? 
1628136265

Edited 1628136421
David M.
Pro
API Scripter
Arthur, I think this works for a 5e Sleep spell. Queries for spell level and rolls dice. Sorts tokens in ascending hp order and ignores undead, creatures immune to charm, and tokens with either no bar1 hp value (to ignore non-creatures) or less than 1hp (already unconscious). Then, "sleepy" condition markers are added to tokens under the remaining hp from the spell until it runs out of juice. It's really late so I didn't bother to deduct spell slots with a ChatSetAttr script call, but you could add this easily. Since it calculates distance from a token, I would use a "targeting" token (perhaps with an aura) to place the spell, and have your macro set up as a token action on that token. I would also probably use Spawn (not shown in this example - again it's late) to further speed up the process so you don't have to drag the targeting "character" token from the journal.  !script {{ --#title|5e Sleep Spell --:(0) QUERY SPELL LEVEL AND ROLL DICE| --=SpellSlot|?{What Level Spell Slot?|1,1|2,2|3,3|4,4|5,5|6,6|7,7|8,8|9,9} --#leftsub|Spell Level:[$SpellSlot] --=NumDice|[$SpellSlot.Raw]-1*2 + 5 --&RollText|[$NumDice.Raw]d8 --#rightsub|HP Roll:[&RollText] --=hpRemaining|[&RollText] --+roll|[$hpRemaining] --:(1) GET ALL TOKENS INTO THE "allTokens" ARRAY| will have blank 1st element to be removed later --~|array;pagetokens;allTokens;@{selected|token_id} --:(2) CREATE THE "inRange" ARRAY TO HOLD TOKENS IN RANGE| --~|array;define;inRange; --:(3) PREP ARRAY FOR LOOP| if no array elements then end macro --~tokenid|array;getfirst;allTokens --?[&tokenid] -eq ArrayError|endOutput --:(4) FIND ALL TOKENS IN RANGE| add indexed roll variables for tokID, name, & hp --=numToks|0 --=i|0 --:RangeLoop| --:TOKEN MUST BE ON OBJECTS OR GMLAYER AND NOT UNDEAD OR IMMUNE TO CHARM| --?[*[&tokenid]:t-layer] -ne objects -and [*[&tokenid]:t-layer] -ne gmlayer|NextToken --?"X[*[&tokenid]:npc_condition_immunities]" -inc "charm" -or "X[*[&tokenid]:npc_type]" -inc "undead"|NextToken --?"X[*[&tokenid]:t-bar1_value]" -eq "X"|NextToken --?[*[&tokenid]:t-bar1_value] -lt 1|NextToken --:CHECK DISTANCE IN UNITS. 20ft is 4UNITS| --~dist|distance;@{selected|token_id};[&tokenid] --?[$dist] -gt 4|NextToken --:ADD TO THE "ARRAYS" OF VARIABLES| --&tokID[$i.Raw]|[&tokenid] --=hp[$i.Raw]|[*[&tokenid]:t-bar1_value] --=numToks|[$numToks] + 1 --=i|[$i] + 1 --:NextToken| --~tokenid|array;getnext;allTokens --?[&tokenid] -ne ArrayError|RangeLoop --:(5) SORT ALL "ARRAY" VARIABLES BY HP VALUE WITH A BUBBLE SORT| --=max_i|[$i]-1 --=i|-1 --:OuterLoop| --=i|[$i]+1 --=j|[$i] --:InnerLoop| --=j|[$j]+1 --?[$hp[$i.Raw]] -gt [$hp[$j.Raw]] |>BubbleUp;[$i.Raw];[$j.Raw] --?[$j.Raw] -lt [$max_i.Raw]|InnerLoop --?[$i.Raw] -lt [$max_i.Raw]|OuterLoop --:(6) APPLY SLEEP DAMAGE TO SORTED TOKENS| --=i|0 --:SortLoop| --=ThisHP|[$hp[$i.Raw]] --?[$ThisHP.Raw] -le [$hpRemaining.Raw]|>GoToSleep;[&tokID[$i.Raw]];sleepy;[$ThisHP.Raw] --=i|[$i]+1 --?[$i.Raw] -lt [$numToks.Raw]|SortLoop --:End| --X| --:PROCEDURES| --:BubbleUp| accepts i, j as parameters. Swaps var[i] & var[j] for three variables --=Temp|[$hp[%2%]] --=hp[%2%]|[$hp[%1%]] --=hp[%1%]|[$Temp] --&Temp|[&tokID[%2%]] --&tokID[%2%]|[&tokID[%1%]] --&tokID[%1%]|[&Temp] --<| --:GoToSleep| accepts tokenID, condition marker, and hp to subtract as parameters --@token-mod|_ignore-selected _ids [%1%] _set statusmarkers|[%2%] --=hpRemaining|[$hpRemaining]-[%3%] --<| }} Click for example. Note the Skeleton and Flesh Golem are ignored due to immunities. The "sleepy" condition marker is applied to affected creatures.
1628175528

Edited 1628177315
Is there a way to access a compendium using scriptcards?  EDIT: I am writing a macro for Starfinders to help with character creation and would like to link to areas of the compendium rather than having the player have to keep looking to the toolbar. Also, is there a way to put a gif, jpg or other image file in a scriptcards macro that doesn't require an https link?  I would like to use the gifs in my own directory.
Michael C. said: Is there a way to access a compendium using scriptcards?  EDIT: I am writing a macro for Starfinders to help with character creation and would like to link to areas of the compendium rather than having the player have to keep looking to the toolbar. Also, is there a way to put a gif, jpg or other image file in a scriptcards macro that doesn't require an https link?  I would like to use the gifs in my own directory. Can't help you with that but I have some scriptcards I made for Starfinder, if you're interested in them.  I think I have a decent attack macro that auto damages NPCs, I think I finally got a find trap one that worked pretty good.
Here is a subroutine I wrote for pulling up DND 5e compendium items. Sample Call to my compendium routine:&nbsp; --&gt;ROLL20_ITEM_LINK|[*R:itemname] [button][*R:itemname]::[&amp;zROLL20_MagicItem_Link][/button] Subroutine --:ROLL20_ITEM_LINK|ITEM NAME --&amp;zROLL20_MagicItem_Link|<a href="https://app.roll20.net/compendium/dnd5e/[%1%]" rel="nofollow">https://app.roll20.net/compendium/dnd5e/[%1%]</a> --&lt;|
1628207946

Edited 1628207994
@Brien V. - I would love to see those macros if you don't mind private messaging them. Edit: just didn't want to add too much to the thread, not being greedy. @Will M. - that would certainly work.&nbsp; Thank you.&nbsp; I think I could work that into an rbutton too.
1628218489

Edited 1628218669
I am attempting to modify the MM example to target multiple targets.&nbsp; I can get X number of targets to get prompted by the script but cannot figure out how to loop through the targets to do damage etc.&nbsp; Is this possible?&nbsp;&nbsp; @{target|Target 1|token_id}, @{target|Target 2|token_id}, @{target|Target 3|token_id} in this case all targets are the same yes?&nbsp; Is there an example for multi targets?
Bradley P. said: I am attempting to modify the MM example to target multiple targets.&nbsp; I can get X number of targets to get prompted by the script but cannot figure out how to loop through the targets to do damage etc.&nbsp; Is this possible?&nbsp;&nbsp; @{target|Target 1|token_id}, @{target|Target 2|token_id}, @{target|Target 3|token_id} in this case all targets are the same yes?&nbsp; Is there an example for multi targets? I am a little confused as MM does allow the selection of multiple targets.&nbsp; I will PM you my Scorching Ray (attack based as opposed to automatic hit) and Chain Lightning (Save based) scripts.&nbsp; Hopefully that will solve your issues.
Can you post the Scorching Ray script on the Scriptcards Sharing forum?&nbsp; Would like to take a gander at it.
Will M. said: Can you post the Scorching Ray script on the Scriptcards Sharing forum?&nbsp; Would like to take a gander at it. Done.&nbsp; :-)
Looking at it now.&nbsp; Like how clean your style is, making this easy to read.&nbsp;&nbsp;
Hi everyone. I have this line of code&nbsp;--=Val| 1d20 + [@{selected|dexterity_mod}] and if I use --+ Rolled:| &nbsp;[$Val] it will print the total which is great. But I also want to print a line so we don't have to hover over the results example say the d20 rolled a 8 hovering would show 1d20 (8) + [2] if there mod was 2. Any ideas how to di this?&nbsp;
1628267934
David M.
Pro
API Scripter
Something like this? !Script {{ --&amp;RollText|1d20 + @{selected|dexterity_mod}[DEX] --=Val|[&amp;RollText] --+Rolling:|[b][&amp;RollText]...[/b] --+Result|[$Val] }}
David M. said: Something like this? !Script {{ --&amp;RollText|1d20 + @{selected|dexterity_mod}[DEX] --=Val|[&amp;RollText] --+Rolling:|[b][&amp;RollText]...[/b] --+Result|[$Val] }} Close, it doesn't show the results of the 1d20 roll.
1628269313

Edited 1628269372
David M.
Pro
API Scripter
Oops, sorry. How about this? !Script {{ --=Val|1d20 + @{selected|dexterity_mod}[DEX] --+Val|[$Val] [i][b]1d20 ([$Val.Base]) + @{selected|dexterity_mod}[DEX][/b][/i] }}
David M. said: Oops, sorry. How about this? !Script {{ --=Val|1d20 + @{selected|dexterity_mod}[DEX] --+Val|[$Val] [i][b]1d20 ([$Val.Base]) + @{selected|dexterity_mod}[DEX][/b][/i] }} Awesome David ty you so much.&nbsp;
@Michael - This is handy, I've been noodling on the best way to target multiple creatures with spells like Scorching Ray.&nbsp;&nbsp; Been working with your code and it looks pretty good.&nbsp; Of course I'm making my own tweaks: Allow player to select a different token if the token died from a previous ray. (more difficult than it sounds due to async issues with token changes) Give an option to take account for the Feat: Elemental Adept - FIRE which changes 1's to 2's for fire damage and overrides fire resistant creatures. I use token-mod (instead of alter) for applying damage to tokens Adding some graphical icons to more visually show Hits, Misses, Fumbles and Crits Put a big X token marker if the creature is killed by a ray.&nbsp;&nbsp; Removed targets' AC from the dialog.&nbsp; They probably know the AC, but I'd rather not just come out and tell them.&nbsp;&nbsp; One thing I did notice is that when checking for spell slots and deducting, the current script doesn't take into account that the 5e OGL sheet incorrectly named lvl_x_slots_expended.&nbsp; It actually stores Slots Remaining.&nbsp; I changed your code to account for this "bug" in the 5e OGL sheet itself.&nbsp;&nbsp; --:GetAndCheckSlotInformation| --=SlotLevel|?{Spell Slot Level?|2|3|4|5|6|7|8|9} --=SlotsTotal|[*S:lvl[$SlotLevel]_slots_total] --=SlotsRemaining|[*S:lvl[$SlotLevel]_slots_expended] --?[$SlotsRemaining.Total] -le 0|NoSlotsLeft I'll post my update back on the Sharing site when I get it working well, but overall this was very helpful.&nbsp; Thanks again! Michael C. said: Will M. said: Can you post the Scorching Ray script on the Scriptcards Sharing forum?&nbsp; Would like to take a gander at it. Done.&nbsp; :-)
Anyone have a Long rest and short rest script I could use?
Will M. said: @Michael - This is handy, I've been noodling on the best way to target multiple creatures with spells like Scorching Ray.&nbsp;&nbsp; Been working with your code and it looks pretty good.&nbsp; Of course I'm making my own tweaks: Allow player to select a different token if the token died from a previous ray. (more difficult than it sounds due to async issues with token changes) Give an option to take account for the Feat: Elemental Adept - FIRE which changes 1's to 2's for fire damage and overrides fire resistant creatures. I use token-mod (instead of alter) for applying damage to tokens Adding some graphical icons to more visually show Hits, Misses, Fumbles and Crits Put a big X token marker if the creature is killed by a ray.&nbsp;&nbsp; Removed targets' AC from the dialog.&nbsp; They probably know the AC, but I'd rather not just come out and tell them.&nbsp;&nbsp; One thing I did notice is that when checking for spell slots and deducting, the current script doesn't take into account that the 5e OGL sheet incorrectly named lvl_x_slots_expended.&nbsp; It actually stores Slots Remaining.&nbsp; I changed your code to account for this "bug" in the 5e OGL sheet itself.&nbsp;&nbsp; --:GetAndCheckSlotInformation| --=SlotLevel|?{Spell Slot Level?|2|3|4|5|6|7|8|9} --=SlotsTotal|[*S:lvl[$SlotLevel]_slots_total] --=SlotsRemaining|[*S:lvl[$SlotLevel]_slots_expended] --?[$SlotsRemaining.Total] -le 0|NoSlotsLeft I'll post my update back on the Sharing site when I get it working well, but overall this was very helpful.&nbsp; Thanks again! Michael C. said: Will M. said: Can you post the Scorching Ray script on the Scriptcards Sharing forum?&nbsp; Would like to take a gander at it. Done.&nbsp; :-) @Will M - Thanks for the format appreciation.&nbsp; Comes from programming classes on structure (Pascal) from 45+ years ago. Your additions look awesome also. Actually, the macro I sent is a template I use.&nbsp; I will often alter it for a particular character or circumstance and add it to the character's attributes.&nbsp; I create a non-Mule macro to call the character's abilities, spells. etc.&nbsp; This allows me to change the spell lists that access Spell-Mules (ability mules, etc.) for each participant.&nbsp; As to your changes: 1.&nbsp; That is awesome as async problems are way outside my wheelhouse. 2.&nbsp; This would be an individual tweak as I have long since learned that trying to tweak every contingency in a single program (macro) is time consuming and potentially inefficient.&nbsp; I also have a SpellMule (~MacrosFeats::Abilityname) that I use for templates with feat changes. 3.&nbsp; I recognize that this is a preference issue.&nbsp; I prefer alterbars for addressing damage to NPCs as I avoid the player permission issues with tokenmod and because the damage actually applied is stated in a separate bar that is very visible to the player.&nbsp; This is particularly useful when an AOE spell hits a group with different immunities, resistances, and vulnerabilities as players get confused by the modified damage calculations unless they have a hover or other means of reassuring themselves that the calculation was done correctly.&nbsp; 4.&nbsp; That's always cool.&nbsp; Being able to insert gifs, color themes, etc. is what makes the macros awesome.&nbsp;&nbsp; 5.&nbsp; I normally don't do this because Roll20 usually does it for me.&nbsp; Sometimes, in less complicated macros, I will just move the token to the gmlayer after some visual effect. 6.&nbsp; Another preference issue and player concession on my part.&nbsp; Players are in disbelief that the roll of a 2 didn't actually hit (being facetious here) and want to be reassured.&nbsp; For me, giving away the AC doesn't give away much. As to the spell slot issue, another preference issue but one that irks me no end.&nbsp; The macro is actually deliberately designed to treat slots that way for just the same reason as you mention.&nbsp; Because The Powers That Be saw fit to mislabel the character sheet one has a choice: treat the "expended" attribute as expended per the attribute itself or treat it as "remaining" as it is mislabeled in the character sheet.&nbsp; I chose to simplify the matter by advising the players to ignore the character sheet (all their spells are on macros anyway) and I have a specific macro that will list the remaining spell slots that a character has available to the player on their Token Action bar:&nbsp; (I used to list the remaining slots in each macro and you will still see that in my older versions.)&nbsp;&nbsp; !scriptcards {{&nbsp; &nbsp; --#title|Spell Slot Report &nbsp; --#sourceToken|@{selected|token_id} &nbsp; --#leftsub|@{selected|character_name} &nbsp; --#emotestate|hidden &nbsp; --#titleFontColor|#D7DBDD &nbsp; --#titleCardBackground|#34495E &nbsp; --#oddRowBackground|#884EA0 &nbsp; --#oddRowFontColor|#ffffff &nbsp; --#evenRowBackground|#2C3E50 &nbsp; --#evenRowFontColor|#ffffff &nbsp; --+|[img]<a href="https://media.giphy.com/media/v7yls1pusVAyo2JfPu/giphy.gif[/img]" rel="nofollow">https://media.giphy.com/media/v7yls1pusVAyo2JfPu/giphy.gif[/img]</a> &nbsp; --:Level1| &nbsp; --?[*S:lvl1_slots_total] -eq 0|Level2 &nbsp; --=SlotsLeft|[*S:lvl1_slots_total] - [*S:lvl1_slots_expended] &nbsp; --+Level 1|[b][$SlotsLeft.Total] of [*S:lvl1_slots_total] slots remaining[/b] &nbsp; --:Level2| &nbsp; --?[*S:lvl2_slots_total] -eq 0|Level3 &nbsp; --=SlotsLeft|[*S:lvl2_slots_total] - [*S:lvl2_slots_expended] &nbsp; --+Level 2|[b][$SlotsLeft.Total] of [*S:lvl2_slots_total] slots remaining[/b] &nbsp; --:Level3| &nbsp; --?[*S:lvl3_slots_total] -eq 0|Level4 &nbsp; --=SlotsLeft|[*S:lvl3_slots_total] - [*S:lvl3_slots_expended] &nbsp; --+Level 3|[b][$SlotsLeft.Total] of [*S:lvl3_slots_total] slots remaining[/b] &nbsp; --:Level4| &nbsp; --?[*S:lvl4_slots_total] -eq 0|Level5 &nbsp; --=SlotsLeft|[*S:lvl4_slots_total] - [*S:lvl4_slots_expended] &nbsp; --+Level 4|[b][$SlotsLeft.Total] of [*S:lvl4_slots_total] slots remaining[/b] &nbsp; --:Level5| &nbsp; --?[*S:lvl5_slots_total] -eq 0|Level6 &nbsp; --=SlotsLeft|[*S:lvl5_slots_total] - [*S:lvl5_slots_expended] &nbsp; --+Level 5|[b][$SlotsLeft.Total] of [*S:lvl5_slots_total] slots remaining[/b] &nbsp; --:Level6| &nbsp; --?[*S:lvl6_slots_total] -eq 0|Level7 &nbsp; --=SlotsLeft|[*S:lvl6_slots_total] - [*S:lvl6_slots_expended] &nbsp; --+Level 6|[b][$SlotsLeft.Total] of [*S:lvl6_slots_total] slots remaining[/b] &nbsp; --:Level7| &nbsp; --?[*S:lvl7_slots_total] -eq 0|Level8 &nbsp; --=SlotsLeft|[*S:lvl7_slots_total] - [*S:lvl7_slots_expended] &nbsp; --+Level 7|[b][$SlotsLeft.Total] of [*S:lvl7_slots_total] slots remaining[/b] &nbsp; --:Level8| &nbsp; --?[*S:lvl8_slots_total] -eq 0|Level9 &nbsp; --=SlotsLeft|[*S:lvl8_slots_total] - [*S:lvl8_slots_expended] &nbsp; --+Level 8|[b][$SlotsLeft.Total] of [*S:lvl8_slots_total] slots remaining[/b] &nbsp; --:Level9| &nbsp; --?[*S:lvl9_slots_total] -eq 0|Final &nbsp; --=SlotsLeft|[*S:lvl9_slots_total] - [*S:lvl9_slots_expended] &nbsp; --+Level 9|[b][$SlotsLeft.Total] of [*S:lvl9_slots_total] slots remaining[/b] &nbsp; --:Final| }}
1628367947

Edited 1628368248
Kurt J.
Pro
API Scripter
ScriptCards 1.4.0 Now Available New optional parameters to the pagetokens function. If you include another parameter following the tokenid, you can specify "all" (all tokens, and the default if you don't include anything), "char" tokens that represent characters, "graphic" tokens that don't &nbsp;represent characters, "pc" for tokens representing characters with a controlledby, and "npc" for tokens that represent characters without a controlledby. Utilizing these is quite a bit faster than filtering these tokens via ScriptCards, especially since in purchased adventures generally at least half of the tokens are "graphic" tokens that you normally wouldn't want anyway. New array function subcommand - sort. Sorts the specified array in ascending order. Added "lightColor" to the list of supported token reference properties to support multicolor dynamic lighting. Array Sort Example : !script {{ --~|array;define;fruits;mango;banana;apricot;apple;orange;pineapple --~presort|array;stringify;fruits --+presort|[&amp;presort] --~|array;sort;fruits --~postsort|array;stringify;fruits --+postsort|[&amp;postsort] }}
1628369043
Kurt J.
Pro
API Scripter
Craven said: David M. said: Oops, sorry. How about this? !Script {{ --=Val|1d20 + @{selected|dexterity_mod}[DEX] --+Val|[$Val] [i][b]1d20 ([$Val.Base]) + @{selected|dexterity_mod}[DEX][/b][/i] }} Awesome David ty you so much.&nbsp; .RollText outputs the expression that was used to generate the roll, while .Text outputs the results with the roll results in it, so [$Val.Text] will output something&nbsp;like&nbsp; 1d20 (15) + 5 [DEX]
1628376131
David M.
Pro
API Scripter
Kurt J. said: .RollText outputs the expression that was used to generate the roll, while .Text outputs the results with the roll results in it, so [$Val.Text] will output something&nbsp;like&nbsp; 1d20 (15) + 5 [DEX] Ah, much cleaner!
@Will M. - I forgot that I wrote that macro before Kurt's For...Next Loop version.&nbsp; A more up-to-date macro is: !scriptcards {{&nbsp; &nbsp; --#title|Spell Slot Report &nbsp; --#sourceToken|@{selected|token_id} &nbsp; --#leftsub|@{selected|character_name} &nbsp; --#emotestate|hidden &nbsp; --#titleFontColor|#D7DBDD &nbsp; --#titleCardBackground|#34495E &nbsp; --#oddRowBackground|#884EA0 &nbsp; --#oddRowFontColor|#ffffff &nbsp; --#evenRowBackground|#2C3E50 &nbsp; --#evenRowFontColor|#ffffff &nbsp; --#debug|1 &nbsp; --+|[img]<a href="https://media.giphy.com/media/v7yls1pusVAyo2JfPu/giphy.gif[/img]" rel="nofollow">https://media.giphy.com/media/v7yls1pusVAyo2JfPu/giphy.gif[/img]</a> &nbsp; --%LoopCounter|1;9;1 &nbsp; &nbsp; &nbsp;--?[*S:lvl[&amp;LoopCounter]_slots_total] -eq 0|% &nbsp; &nbsp; &nbsp;--=SlotsLeft|[*S:lvl[&amp;LoopCounter]_slots_total] - [*S:lvl[&amp;LoopCounter]_slots_expended] &nbsp; &nbsp; &nbsp;--+Level [&amp;LoopCounter]|[b][$SlotsLeft.Total] of [*S:lvl[&amp;LoopCounter]_slots_total] slots remaining[/b] &nbsp; --%| &nbsp; --X| }}
@Kurt - 1.4.0 is awesome!&nbsp; The array function is huge and is getting integrated into more of my macros with each update.&nbsp; I know that you are super busy but it would be really helpful if you could expand the array section of the wiki when you get a chance. (Maybe with some examples?) Thanks in advance!
1628452783
Kurt J.
Pro
API Scripter
Michael C. said: @Kurt - 1.4.0 is awesome!&nbsp; The array function is huge and is getting integrated into more of my macros with each update.&nbsp; I know that you are super busy but it would be really helpful if you could expand the array section of the wiki when you get a chance. (Maybe with some examples?) Thanks in advance! I made a new Wiki section on arrays and put some basic info there with a few examples. I'll expand on it as I get the chance.
@Kurt - Score!... and thanks!
1628474007
Kurt J.
Pro
API Scripter
ScriptCards 1.4.0a Bug Fix Update If you pulled 1.4.0 from the GitHub Repo , there is no need to update. I made a mistake with updating the GIST to 1.4.0 that introduced a bug in the makeButton function. I have updated both locations to 1.4.0a, which just corrects this bug on the GIST version but bumps the version on both to keep them in sync.
@Kurt - Thanks for the fix. I was about to post the problem I was having today's session with one of my players cards. Now I don't have to :)
I have two questions. Is there any way for the function or roll text to carry over?&nbsp; I am trying to program the Lucky Feat in.&nbsp; When I do that, if the new roll is greater than the old roll, I have it save over the old roll.&nbsp; Looks like this: &nbsp; --=AttackRoll|[$NewRoll] But when I do that, I can't evaluate AttackRoll anymore with thing like [$AttackRoll.Base] anymore because it doesn't think there is a roll there anymore.&nbsp; Any help with this would be great. The next thing is I was wondering if there was a way to edit a String value to get rid of the spaces.&nbsp; To turn something like Protection From Evil and Good to ProtectionFromEvilandGood.
1628951671
David M.
Pro
API Scripter
Justin, check out the string replace function to replace " " with "" <a href="https://wiki.roll20.net/Script:ScriptCards#Assign_Variable_to_Built-In_Function_.28--.7E.29" rel="nofollow">https://wiki.roll20.net/Script:ScriptCards#Assign_Variable_to_Built-In_Function_.28--.7E.29</a> Function Name Sub Function Parameters Return Type Description string replace string;replace;searchText;replaceText;stringValue stringVariable Replaces&nbsp; searchText &nbsp;in&nbsp; stringValue &nbsp;with&nbsp; replaceText &nbsp;and returns the resulting string
Thanks, I will do that. David M. said: Justin, check out the string replace function to replace " " with "" <a href="https://wiki.roll20.net/Script:ScriptCards#Assign_Variable_to_Built-In_Function_.28--.7E.29" rel="nofollow">https://wiki.roll20.net/Script:ScriptCards#Assign_Variable_to_Built-In_Function_.28--.7E.29</a> Function Name Sub Function Parameters Return Type Description string replace string;replace;searchText;replaceText;stringValue stringVariable Replaces&nbsp; searchText &nbsp;in&nbsp; stringValue &nbsp;with&nbsp; replaceText &nbsp;and returns the resulting string
1628970564
Kurt J.
Pro
API Scripter
Justin G. said: I have two questions. Is there any way for the function or roll text to carry over?&nbsp; I am trying to program the Lucky Feat in.&nbsp; When I do that, if the new roll is greater than the old roll, I have it save over the old roll.&nbsp; Looks like this: &nbsp; --=AttackRoll|[$NewRoll] But when I do that, I can't evaluate AttackRoll anymore with thing like [$AttackRoll.Base] anymore because it doesn't think there is a roll there anymore.&nbsp; Any help with this would be great. The next thing is I was wondering if there was a way to edit a String value to get rid of the spaces.&nbsp; To turn something like Protection From Evil and Good to ProtectionFromEvilandGood. There isn't a direct way to replace a roll with another roll without re-rolling the dice involved, but Lucky can be done with something like the code below. Subsequent references to the attack roll would use&nbsp; [$AttackRoll[&amp;UseLucky]] &nbsp;to reference the correct roll. This is an over-simplified example, of course, as you would want to display the dice roll to the user and prompt them via a pair of reentrant buttons if they want to use a Luck point, but this is how you could differentiate the higher of the two rolls. !script {{ &nbsp; --&amp;UseLucky|0 &nbsp; --=AttackRoll0|1d20 + 5 [STR] + 2 [PB] &nbsp; --=AttackRoll1|1d20 + 5 [STR] + 2 [PB] [LUCKY] &nbsp; --+Info:|First Roll was [$AttackRoll0] &nbsp; --+Info:|Second Roll was [$AttackRoll1] &nbsp; --?[$AttackRoll1] -gt [$AttackRoll0]|&amp;UseLucky;1 &nbsp; --+Attack|You rolled [$AttackRoll[&amp;UseLucky]] }}
1628970707

Edited 1628970760
Kurt J.
Pro
API Scripter
David M. said: Justin, check out the string replace function to replace " " with "" <a href="https://wiki.roll20.net/Script:ScriptCards#Assign_Variable_to_Built-In_Function_.28--.7E.29" rel="nofollow">https://wiki.roll20.net/Script:ScriptCards#Assign_Variable_to_Built-In_Function_.28--.7E.29</a> Function Name Sub Function Parameters Return Type Description string replace string;replace;searchText;replaceText;stringValue stringVariable Replaces&nbsp; searchText &nbsp;in&nbsp; stringValue &nbsp;with&nbsp; replaceText &nbsp;and returns the resulting string The string functions don't treat quotes as anything special, so the actual call would leave them out. Something like: --~Result|string;replaceall; ;;Protection From Evil and Good With a space for the search text and nothing for the replacement text. "replace" only does the first occurrence, so you would probably want replaceall
Will M. said: Can you post the Scorching Ray script on the Scriptcards Sharing forum?&nbsp; Would like to take a gander at it. Where do I find this? Scriptcards Sharing forum
Arthur B. said: Will M. said: Can you post the Scorching Ray script on the Scriptcards Sharing forum?&nbsp; Would like to take a gander at it. Where do I find this? Scriptcards Sharing forum Here is the link:&nbsp; Scriptcards Working and Sharing
Thank you, I didn't even know this was available. Will M. said: Arthur B. said: Will M. said: Can you post the Scorching Ray script on the Scriptcards Sharing forum?&nbsp; Would like to take a gander at it. Where do I find this? Scriptcards Sharing forum Here is the link:&nbsp; Scriptcards Working and Sharing
Hello everyone! I have a question about dynamically returning the character_id of a random monster. For instance I would like to use !script {{ --&amp;name|"#rando-monster-macro" --@{[&amp;name]|character_id} --"more code here using the char_id"... }} However if I'm using this, it returns: "No character was found for '[&amp;name]'" The usage of this code is in a dynamic SpawnDefaultToken script to automatically resize the token to its native token_size. Token size is stored in the character_id, so the main code looks something like this (WIP): !script {{ &nbsp; --#title|Chat Spawned a Monster! &nbsp; --&amp;type|***#Random-monster*** &nbsp; --&amp;id|[&amp;type],@{[&amp;type]|character_id} &nbsp; --&amp;name|[&amp;id]:name] &nbsp; --=tokenSize|[[&amp;id]:token_size] &nbsp; --=qty|[[1d6]] &nbsp; --@forselected|Spawn _name|[&amp;name] _offset|1,0 _qty|[$qty] _size|[$tokenSize] _placement|grid 3 &nbsp; --+Result|[$qty] [&amp;name](s) Spawned }} I have tried adding and removing the * in the command lines, but to no avail. Anyone have any ideas?
1629042980
Kurt J.
Pro
API Scripter
daniel e. said: Hello everyone! I have a question about dynamically returning the character_id of a random monster. For instance I would like to use !script {{ --&amp;name|"#rando-monster-macro" --@{[&amp;name]|character_id} --"more code here using the char_id"... }} However if I'm using this, it returns: "No character was found for '[&amp;name]'" The usage of this code is in a dynamic SpawnDefaultToken script to automatically resize the token to its native token_size. Token size is stored in the character_id, so the main code looks something like this (WIP): !script {{ &nbsp; --#title|Chat Spawned a Monster! &nbsp; --&amp;type|***#Random-monster*** &nbsp; --&amp;id|[&amp;type],@{[&amp;type]|character_id} &nbsp; --&amp;name|[&amp;id]:name] &nbsp; --=tokenSize|[[&amp;id]:token_size] &nbsp; --=qty|[[1d6]] &nbsp; --@forselected|Spawn _name|[&amp;name] _offset|1,0 _qty|[$qty] _size|[$tokenSize] _placement|grid 3 &nbsp; --+Result|[$qty] [&amp;name](s) Spawned }} I have tried adding and removing the * in the command lines, but to no avail. Anyone have any ideas? API scripts can't execute macros, so: --&amp;name|"#rando-monster-macro" Will assign the text "#rando-monster-macro" to the [&amp;name] string variable. The other issue that is going to be a problem is the order of operations when a line of text is sent to the API. This: --&amp;id|[&amp;type],@{[&amp;type]|character_id} Will be processed by the chat server before &nbsp;it gets sent to ScriptCards, which will try to find a character named [&amp;type] and retrieve its character id, which will, of course, fail. The workaround for this would be to use a rollable table that contains the character IDs of the characters that can be spawned and modify the second bit of code above like this: !script {{ &nbsp; --#title|Chat Spawned a Monster! &nbsp; --&amp;charid|[[1t[random-monster-charid]]] &nbsp; --&amp;name|[*[&amp;charid]:name] &nbsp; --=tokenSize|[*[&amp;charid]:token_size] &nbsp; --=qty|1d6 &nbsp; --@forselected|Spawn _name|[&amp;name] _offset|1,0 _qty|[$qty] _size|[$tokenSize] _placement|grid 3 &nbsp; --+Result|[$qty] [&amp;name](s) Spawned }} The main changes here are in the lines bolded. An in-line table roll is used to get a character ID from the rollable table (note that there is currently a bug in the ScriptCards roll parser that prevents you from using it to roll on tables with "-" in the name - that will be corrected in the next version, but the inline table roll will work fine. When assigning the name, your original code had "[&amp;id]:name]", which doesn't match the attribute referencing syntax for ScriptCards. Finally in the qty roll I removed the [[ and ]] (a chat-server inline roll) so the ScriptCards roll parser is used. This will allow you to hover over the result and see the details of the roll (in inline roll will only have the final result transferred to ScriptCard). Of course, for the above to work, you would need to create a table called "random-monster-charid" and populate it with the entries you want to have available to the script.
1629043759
Kurt J.
Pro
API Scripter
ScriptCards 1.4.0b and 5e Action Menu 1.6.4 I've updated the GITHUB (recommended) and GIST with version 1.4.0b of ScriptCards, including the following updates. Most of these changes came as a result of pull requests by JSherwood. Cleaned up spacing in the script (JSherwood) The roll parser now treats numbers in parenthesis as just plain numbers (JSherwood) Fixed a bug in the Roll Parser that would prevent it from rolling on rollable tables with "-" in the name. In addition, JSherwood has contributed some updates to the 5E Action Menu script, and I've bumped the version to 1.6.4: Removed spell bonus addition to damage, since that isn't the way spell damage works :) An extraneous condition was causing a "HIT" if the base die roll was equal to the target's AC, which was not intended. Added [Spell Attack Bonus] to the roll statement to indicate where the modifier is coming from. Use attack specific bonuses instead of general character bonuses for attack and damage rolls.
1629123269
timmaugh
Pro
API Scripter
Kurt J. said: API scripts can't execute macros, so: --&amp;name|"#rando-monster-macro" Will assign the text "#rando-monster-macro" to the [&amp;name] string variable. The other issue that is going to be a problem is the order of operations when a line of text is sent to the API. This: --&amp;id|[&amp;type],@{[&amp;type]|character_id} Will be processed by the chat server before &nbsp;it gets sent to ScriptCards, which will try to find a character named [&amp;type] and retrieve its character id, which will, of course, fail. Kurt explains pretty well why what you're trying to do won't work... I would only add that Fetch and ZeroFrame (metascripts) can help, here. I posted a more detailed breakdown in response to Daniel's post over on the Spawn thread, but the idea goes that the full order of operations for script commands would go: Roll20 parsers (with the Roll20 order of operations) &nbsp; &nbsp; &nbsp;=&gt; Meta Scripts (in install order, except for mine which can be ordered by ZeroFrame) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; Standard Scripts (install order) So you could flip Kurt's process around, and have your table contain the monster types (much more human-readable), and use that to return the character id of the associated character: !script {{ &nbsp; --#title|Chat Spawned a Monster! &nbsp; --&amp;name|[[1t[random-monster]]].value &nbsp; --&amp;charid|@($[[0]].value.character_name) &nbsp; --=tokenSize|[*[&amp;charid]:token_size] &nbsp; --=qty|1d6 &nbsp; --@forselected|Spawn _name|[&amp;name] _offset|1,0 _qty|[$qty] _size|[$tokenSize] _placement|grid 3 &nbsp; --+Result|[$qty] [&amp;name](s) Spawned }} The meta-script options I discussed in the other thread work as well in a ScriptCards call as they do in a Spawn call, so it's really just a matter of what data you need to get, and when you need it.
Thank you Timmaugh! I read your other posts as well, and I got the commands using !spawn [...] to work with the correct token size. Awesome! However, using the !script function, it returns the correct --+Result in chat, however the tokens spawn as literal 1x1 pixels. There is also no Error message popping up. I'm not as familiar with scriptcards as I am with spawndefaulttoken, so I'm unable to effectively troubleshoot. Here's the code, only change I made was to the table-name. I'm using Fetch and the Zero'forgot-name' API. Once again, thank you for the detailed descriptions and help. You and David have been very instrumental in making this work! I am playing 5e by the way. (Ignore the poor placement of the image I cant quite figure out how to move it. !script {{ &nbsp; --#title|Chat Spawned a Monster! &nbsp; --&amp;name|[[1t[Low-CR-Table]]].value &nbsp; --&amp;charid|@($[[0]].value.character_name) &nbsp; --=tokenSize|[*[&amp;charid]:token_size] &nbsp; --=qty|1d6 &nbsp; --@forselected|Spawn _name|[&amp;name] _offset|1,0 _qty|[$qty] _size|[$tokenSize] _placement|grid 3 &nbsp; --+Result|[$qty] [&amp;name](s) Spawned }} *PS: For context I am using a program to click the macros on the screen whenever Twitch chat does specific commands. The end goal is to have one person from chat try to run through the dungeon while the rest of chat spawns things for them to fight, spawns traps, damages/heals them etc.
1629136907
David M.
Pro
API Scripter
Daniel, looks like this line might be a problem: &nbsp; --&amp;charid|@($[[0]].value.character_name) I'm assuming you meant to assign .character_id rather than .character_name? This is likely causing the&nbsp; [*[&amp;charid]:token_size] &nbsp;line to return a 0 which then gets assigned to your Spawn --size command.&nbsp;
@Daniel - FYI, Not all NPC character sheets have a defined token_size attribute.&nbsp; I've found that when there is no token_size attribute, the following code returns a 1.&nbsp; Manually adding a token_size attribute to the sheet fixes that for me. !script {{ --#title|Token Size --#Sourcetoken|@{selected|token_id} --+Name|[*S:character_name] / [*S:t-name] --+TokenSize|[*S:token_size] --+Size|[*S:size] }}
1629144217
timmaugh
Pro
API Scripter
David M. said: Daniel, looks like this line might be a problem: &nbsp; --&amp;charid|@($[[0]].value.character_name) I'm assuming you meant to assign .character_id rather than .character_name? This is likely causing the&nbsp; [*[&amp;charid]:token_size] &nbsp;line to return a 0 which then gets assigned to your Spawn --size command.&nbsp; Yep, that was my mistake, taking what Kurt had posted and changing it. I didn't clean up all those loose ends. Sorry!
Hello friends! Its your favorite clueless coder-wannabe here with another question! You have been very helpful, and believe me before I come to the forum I make sure I scour everywhere to try to find the answer myself, I don't want to bother you all! However, I've reached another conundrum. I'm trying to add a line to code I have been using in order to add a dynamic initiative roller. Here's what I have: !script {{ --#title|Chat Spawned a Monster! --#titleFontSize| 42px --#bodyFontSize| 24px --#oddRowBackground|#9900ff --&amp;name|[[1t[High-CR-Table]]].value --&amp;charid|@($[[0]].value.character_id) --=tokenSize|[*[&amp;charid]:token_size] --=qty|1d3 --{&amp; select SB}@forselected|!Spawn _name|[&amp;name] _size| [$tokenSize] _qty|[$qty] _placement|grid 3 _offset|[[(2*(1d2-1)-1)*1d24]],[[(2*(1d2-1)-1)*1d10]] --+Spawned|[$qty] [&amp;name](s). //* this is random flavor text dont mind this*\\--+|[[1t[highflav]]] //* Line in question *\\--~turnorder|addtoken;[&amp;charid];[1d20] }} I've tried multiple different variations, and I can't seem to get it to add initiative. I have also tried using the !init-assist API instead, and can't get it.&nbsp; Thank you, Daniel
1629641271
David M.
Pro
API Scripter
Daniel, I haven't used turnorder before, but I see a couple things from looking at your macro and the wiki: the turnorder;addtoken function is looking for a token_id, not a character_id to use any function, the format is --~VariableName|function;param1;param2;param3;...&nbsp; &nbsp;Looks like the turnorder function doesn't actually put a value into the VariableName, so you would just use a dummy variable The value you are passing ( [1d20] ) is not a valid format. Instead, pass a roll variable or a full inline roll, e.g. [[1d20]]&nbsp; This example can give you an idea of how to incorporate into your scriptcard. It adds two entries to the turn order: one using a roll variable and one with an inline roll !script {{ --#hidecard|1 --&amp;tokenid|@{selected|token_id} --=roll|1d20+5 --~dummy|turnorder;addtoken;[&amp;tokenid];[$roll] --~dummy|turnorder;addtoken;[&amp;tokenid];[[1d20]] }}
Thanks David, I am trying to use this to automatically add the random monster into the initiative order: !script {{ --#title|Chat Spawned a Monster! --#titleFontSize| 42px --#bodyFontSize| 24px --#oddRowBackground|#9900ff --&amp;name|[[1t[High-CR-Table]]].value --&amp;charid|@($[[0]].value.character_id) --=tokenSize|[*[&amp;charid]:token_size] --=qty|1d3 --{&amp; select SB}@forselected|!Spawn _name|[&amp;name] _size| [$tokenSize] _qty|[$qty] _placement|grid 3 _offset|[[(2*(1d2-1)-1)*1d24]],[[(2*(1d2-1)-1)*1d10]] --+Spawned|[$qty] [&amp;name](s). //* this is random flavor text dont mind this*\\--+|[[1t[highflav]]]&nbsp;&nbsp;&nbsp; --&amp;tokenid|{&amp; select [&amp;name]}@{selected|token_id} --~dummy|turnorder;addtoken;[&amp;tokenid];[[1d20]] }} I am also not set on using the built-in --~Variable text from scriptcards, however even using another initiative tracker API I will still need to dynamically find the token_id for a random monster AFTER the token is spawned. Do you think the problem may be because of the order that scriptcards executes lines? For instance, maybe the token isnt spawning in time for the API to select it? However, I've also tried this on a new macro without the spawn and cannot select the token. Any ideas?