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

power card scripting

1623296138

Edited 1623354099
Non DM users can select their character, activate a macro, but then cannot select an NPC to target the macro using the PowerCard API script. DMs can select a character, activate a macro, and target an NPC and the API script will execute. How can I allow non DM users to activate a macro and target an NPC (or other character) with a macro?
1623296907
timmaugh
Pro
API Scripter
Select and Target are available for everyone... Obviously, select only works with tokens you can control, but you can target anybody. If you really need the token selected (when you use targeting, there aren't selected tokens, as far as the API is concerned), SelectManager can help, but I don't think that's what you are asking. If your user can put @{target|token_name} into chat and get something back after they pick a token, they can use that in a macro, so what specific functionality are they missing?
1623336225

Edited 1623336602
you are right i can target a npc using @{target|token_name} here is the code, so with this i can select a target, choose what spell level and if i have advantage disadvantage or standard roll however after selecting all of that the macro stops functioning, nothing comes up in the chat window i also get a error message as gm saying not a valid target id. also the choose target box does not disappear after target is selected !power {{  --emote|@{selected|token_name} shoots a bolt of light at @{target|token_name}  --name|Guiding Bolt  --leftsub|120 ft ranged spell  --rightsub|Level ?{Spell Level|1|2|3|4|5|6|7|8|9}  --attack| [[ [$atk] ?{attack|standard,1d20|advantage,2d20kh1|disadvantage,2d20hl1}+6 ]] vs AC @{target|npc_ac}  --?? $atk >= @{target|npc_ac} and $atk.base <> 20 ?? damage:| [[ [$dmg] (?{Spell Level|1|2|3|4|5|6|7|8|9})d6 ]]  --?? $atk.base == 20 ?? Critical Hit|[[ [$critdmg] (2*(?{Spell Level|1|2|3|4|5|6|7|8|9}))d6 ]]  --?? $atk < @{target|npc_ac} ??You Miss| [[ 1t[taunts] ]]  --soundfx|_audio,play,nomenu|laser  --vfx_opt|@{selected|token_name} @{target|token_name} beam-Holy  --?? $atk >= @{target|npc_ac} ?? advantage|next attack has advantage  --?? $atk >= @{target|npc_ac} ?? api_token-mod|@{target|token_name} _ignore-selected _set statusmarkers|archery-target  --?? $atk >= @{target|npc_ac} ?? api_act|-1 1 _advantage  --?? $atk >= @{target|npc_ac} and $atk.base <> 20 ?? alterbar1|_target|@{target|token_name} _bar|1 _amount|-[^dmg] _show|all  --?? $atk.base == 20 ?? alterbar2|_target|@{target|token_name} _bar|1 _amount|-[^critdmg] _show|all }}
1623338817
timmaugh
Pro
API Scripter
In those alterbar and TokenMod calls, it looks like you are sending the token name rather than the token id. I'm not sure what alterbars requires in the syntax, but I wouldn't be surprised if that was the problem... Token-Mod, if you're not going to use the selected token, requires the --ids argument... AND it has to be enabled to be used by your players. That is a setting in TokenMod found at the bottom of the help... "playerscanids". If that's what you're doing with the token-mod call, then I think it has to be something more like: api_token-mod|_ids|@{target|token_id} _ignore-selected _set statusmarkers|archery-target Guessing something similar with the alterbars syntax... where this bit: _target|@{target|token_name} ...should be... _target|@{target|token_id}
1623353980

Edited 1623354165
i got them to work finally and am begining to have some fun with them thank you,  i have another question . is there any way to multi target?   for say like a fireball spell that has an aoe as apposed to a single target?
1623356290
timmaugh
Pro
API Scripter
Yep... the targeting syntax has up to 4 potential parts: @{keyword|reference|attribute|max} The keyword is always "target". The reference is how you would differentiate one target from another, the prompt the user would get to pick their target, and how you would refer back to the same target in the future. For instance, you could have "Target 1", "Target 2", and "Target 3", or you could have "Primary Bonus", "Secondary Bonus", and "Dude we hardly care about". The attribute is obviously what you're looking for. If you need the "max" of an attribute, it has to be the fourth item in the list... Otherwise you are asking to find an attribute named "max". TEMPLATE  | EXAMPLE                           | NOTES ==========|===================================|===================================================================================== 2 items   | @{target|hp} | gets the hp attribute from the target's associated character; prompt will be "Target" 3 items | @{target|Pick someone|hp} | same as above, but with custom prompt of "Pick someone" | @{target|Pick someone|ac} | if the "Pick someone" target has already been used in the command, | | the user won't be asked to select this target again 3 items | @{target|hp|max} | this looks for an attribute named "max", using the prompt of "hp"; 99.99% of the time, | | this is not what you're looking to do 4 items | @{target|Pick someone|hp|max} | this looks for the max value of the "hp" attribute on the character associated with the target; | | prompt will be "Pick someone"  
1623358124
David M.
Pro
API Scripter
Rick, I'd highly recommend looking into migrating from Powercards to Scriptcards . It has tons more functionality. Here's an example that "does it all" for fireball, for example, automatically finding tokens within range of a target token. This post shows an animated gif of a version of this scriptcard in action (gif at half speed for some reason).
is it all that more versitile
It is much more versatile, and was born from PowerCards.   Rick F. said: is it all that more versitile
1623418631

Edited 1623418754
David M.
Pro
API Scripter
EDIT - Sniped by Will (who's made some really cool stuff, btw), but here's some additional details: It is more like a scripting language than Powercards, with support for creating procedures (that you can optionally pass arguments to), loops, arrays, case statements, creating buttons programmatically, programmatically building commands (based on conditions) for another script that you can trigger, etc. You can have string- or roll-typed variables, and there are a ton of built-in functions to do things like calculate distances between tokens, string manipulation (split, trim, replace, substring, etc.), and writing to the State object to temporarily store variables for use in a subsequent macro. You can pause the macro in the middle of operation to ask for more input, access repeating fields, access the turn order, do things for all tokens on a page, just all kinds of stuff. If you have a bunch of powercard macros that work, no need to touch them! But, if you run into a roadblock functionality-wise, there is a decent chance that scriptcards can do it. Another big plus is that it is actively being developed and Kurt is very responsive, adding capabilities all the time. Anyway, if you have time and if any of the above interests you or gets you thinking, check it out!  Here is a fledgling thread where folks are starting to share some of the completed scriptcards they've come up with, which could jump-start your development process. There are also some simple examples at the bottom of the wiki. And of course if you have questions, the main thread is very active with a bunch of folks ready to jump in and help :) 
1623423585
timmaugh
Pro
API Scripter
Will M. said: It is much more versatile, and was born from PowerCards.   Video of that day: Such a precocious script.
can script cards make a good fireball spell using a 20 ft radius gif of a fireball and apply damage and roll for half damage across all targets with in the fireball gif?   if so then you have sold me
Check out this Fireball script developed in Scriptcards.
1624123890
Kurt J.
Pro
API Scripter
Will M. said: Check out this Fireball script developed in Scriptcards. A couple posts down from that post is the revised Fireball that does saves and resistances/immunities/vulnerabilities. This was also the basis for the Lightning Bolt and Burning Hands  scripts as well.
its interesting and covers the bases but the gif i have is alreadt 20 ft in diameter the script would need to be altered
1624162688
David M.
Pro
API Scripter
Are you currently manually dropping the animated token onto the map? API-generated tokens with animations don't really place nicely together. You could add a call to the SpawnDefaultToken script to the Fireball scriptcard (passing the targetid as the "selected" token via SelectManager) to plop a static Fireball token on the map, even having that "static" token expand to full size before deleting itself (see the second gif from this post  for an extreme example). Or you could have scriptcards trigger an fx at the target origin.
that is an amazing use of spawn token command
i have script card installed now and used this macro for magic missle however when trying to use the macro it always says that the charicter no longer has any spell slots left   why is that? !scriptcard {{    --#title|Magic Missile   --#sourceToken|@{selected|token_id}   --#targetToken|@{target|token_id}    --:GetAndCheckSlotInformation|   --=SlotLevel|?{Spell Slot Level?|1|2|3|4|5|6|7|8|9}   --=SlotsTotal|[*S:lvl[$SlotLevel]_slots_total]   --=SlotsAvailable|[*S:lvl[$SlotLevel]_slots_expended]   --?[$SlotsAvailable.Total] -le 0|NoSlotsLeft   --<|   --:NoSlotsLeft|   --+|[*S:character_name] has no level [$SlotLevel.Total] spell slots available.   --X|   --:DeductSpellSlot|   --=SlotsAvailable|[$SlotsAvailable] - 1   --@setattr|_charid [*S:character_id] _lvl[$SlotLevel]_slots_expended|[$SlotsAvailable] _silent   --<|   --:MissileLoop|   -->FireMissile|   --=DisplayCount|[$DisplayCount] + 1   --?[$DisplayCount] -le [$MissileCount]|MissileLoop   --+Total|Total damage is [$MissileDamage]   -->DeductSpellSlot|   --#rightsub|Level [$SlotLevel] Left: [$SlotsRemaining]    -->PlayEffects|none;burst-smoke;beam-magic;spell_01   -->ApplyDamageTokenmod|@{target|token_id};3;-[$MissileDamage]   -->ApplyDamageAlterbars|@{target|token_id};3;-[$MissileDamage]   --X|   --:FireMissile|   --=ThisMissile|1d4 + 1   --=MissileDamage|[$MissileDamage] + [$ThisMissile]   --+Missile|[$DisplayCount.Total] Hits for [$ThisMissile] [b]force[/b] damage   --<|   --:GetAndCheckSlotInformation|   --=SlotLevel|?{Spell Slot Level?|1|2|3|4|5|6|7|8|9}   --=SlotsTotal|[*S:lvl[$SlotLevel]_slots_total]   --=SlotsExpended|[*S:lvl[$SlotLevel]_slots_expended]   --?[$SlotsExpended.Total] -ge [$SlotsTotal.Total]|NoSlotsLeft   --<|   --:NoSlotsLeft|   --+|[*S:character_name] has no level [$SlotLevel.Total] spell slots available.   --X|   --:DeductSpellSlot|   --=SlotsExpended|[$SlotsExpended] + 1   --@setattr|_charid [*S:character_id] _lvl[$SlotLevel]_slots_expended|[$SlotsExpended] _silent   --=SlotsRemaining|[$SlotsTotal] - [$SlotsExpended]   --<|   --:PlayEffects|Parameters are : source effect; target effect; line effect; sound effect   --vtoken|@{selected|token_id} [%1%]   --vtoken|@{target|token_id} [%2%]   --vbetweentokens|@{selected|token_id} @{target|token_id} [%3%]   --@roll20AM|_audio,play,nomenu|[%4%]   --<|   --:ApplyDamageTokenmod|Parameters are tokenid;bar#;amount   --@token-mod|_ignore-selected _ids [%1%] _set bar[%2%]_value|[%3%]   --<|   --:ApplyDamageAlterbars|   --@alter|_target|[%1%] _bar|[%2%] _amount|[%3%]   --<| }}
1624546440
David M.
Pro
API Scripter
Scriptcards processes commands line by line until there are no commands or until it hits an --X| command to exit early. You have several "procedures" in your script. These should be placed after the main body of your scriptcard. When called, the parser will jump from the calling point in the main body down to the procedure, run that procedure, then jump back to the line after it was called in the main body (the --<| line at the end of the procedure tells the parser to return to where it was before the procedure was called). It is possible to terminate the macro early from within a procedure if the parser runs into another --X| line somewhere (for example the conditional checking for "NoSlotsLeft" above). In your example, you have placed the entire GetAndCheckSlotInformation procedure up in the main body of your macro, rather than just calling the procedure with a single line. So, the parser runs the GetAndCheckSlotInformation code block and just continues along its merry way to the NoSlotsLeft block. Also, it looks like you have a bunch of stuff duplicated, which could cause a mess of other problems. See this example of a similar Magic Missile scriptcard from the wiki to see how to appropriately call procedures (and how to place them in relation to the main body). You will see that the main body is the first ~25 lines of code in this example, including blank lines, and ends at the first --X| line. Everything below that line only runs if it is told to somewhere in the main body.