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

Token-Mod and ChatSetAttr - dynamic number of targets?

Is it possible to have the number of targets in the script change based on something like the level of the spell?  I created a macro today for the Bless Spell.  It works great for the 3 targets when cast at 1st level.  But now I'm wondering if there is a way to have a Target|4, Target|5, etc. if the spell is cast at a higher level. If this is possible somehow, it would be great for this and other spell macros that change the number of targets based on the level at which the spell is cast.  If not, we can certainly work around it; I just thought I'd ask :-) Here is what I have now: !token-mod --set statusmarkers|blessed --ids @{target|1|token_id} @{target|2|token_id} @{target|3|token_id} !setattr {{ --silent  --charid @{target|1|character_id}, @{target|2|character_id}, @{target|3|character_id} --repeating_savemod_$0_global_save_active_flag|1 --repeating_tohitmod_$0_global_attack_active_flag|1 }} /w gm Elran casts Bless on @{target|1|token_name}, @{target|2|token_name} and @{target|3|token_name} granting 1d4 on Attack Rolls and Saving Throws. %{Elran|repeating_spell-1_-MZ2GVwMXKID5c2UF1Wm_spell}
1624324122
The Aaron
Roll20 Production Team
API Scripter
Target selection happens on the client side, before the API even becomes active. The only way for the API to have an influence would be if the script then whispered you a button with the right number of targets to click. It would be highly disruptive and a bit annoying to code.  The best way to handle this is to either have one macro/ability per level of spell, or have the total number of target calls it could need, but click a single token multiple times for lower level spells. (Duplicates are removed)
1624333039

Edited 1624333623
Look at the ScriptCards script.  I think you could ask the user the level of the spell they are casting at, then loop through your targetting/cast logic for each iteration.  Here's an example of a similar concept with the Magic Missile spell. 
1624336541
timmaugh
Pro
API Scripter
InsertArg can rebuild a command line on the fly and sub in the right number of targets, leaving you a button in the chat interface to click.
Will M. said: Look at the ScriptCards script.  I think you could ask the user the level of the spell they are casting at, then loop through your targetting/cast logic for each iteration.  Here's an example of a similar concept with the Magic Missile spell.  ScriptCards looks promising.  The Magic Missile script looks similar in getting the number of targets based on spell level and then looping.  Thanks, I'll take a look.
1624375454

Edited 1624379748
The Aaron said: Target selection happens on the client side, before the API even becomes active. The only way for the API to have an influence would be if the script then whispered you a button with the right number of targets to click. It would be highly disruptive and a bit annoying to code.  The best way to handle this is to either have one macro/ability per level of spell, or have the total number of target calls it could need, but click a single token multiple times for lower level spells. (Duplicates are removed) This actually sounded like the simplest solution, to just have multiple versions of the script, which are coded for for 3, 4 or 5 targets based on casting the spell at Level 1, 2 or 3.   But the nested macros in a query of another macro is throwing me.  I created three different macros, #Bless-1, #Bless-2 and #Bless-3 for casting at 1st, 2nd and 3rd level.  Then tried a simple macro to query spell level and run the correct macro ?{Cast at what level?|Level 1,#Bless-1 |Level 2,#Bless-2 |Level 3,#Bless-3 }.  But of course, that didn't work.  I did try character replacement for } in the Bless-1 macro, but that didn't work either. So, I'm giving up on this project.  Way too hard.  I can just manually apply the Bless to additional characters if he upcasts it.