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

Spell Effect Token - Using a macro to reduce it's own attribute bar?

I have a token for a spell effect that allows for six rounds of a healing effect within it's AOE. I am using bar2 to count this.  Without API scripts, is there a way to have the macro reduce the bar by one automatically? If not, how would I go about this with API scripts. I have a pro account, but have not taken the dive into API yet.  Follow up on that, is there a way to have the token automatically remove itself once it reaches zero or a negative value so that it? 
1692365433
timmaugh
Forum Champion
API Scripter
Hey, Masha'to... in answer to your first question, macros cannot affect tokens/characters. This is solely the realm of player interaction and/or mod scripts. As for what script(s) you need to make this happen... you are doing a few different things: ...decrementing the bar1 value (script: Token-Mod) ...on a per-round cadence (user triggering or script: OnMyTurn) ...if the value of bar1 reaches 0 (script: APILogic or ScriptCards) ...remove the token (script: depends) What script you would use for the removing the token would depend on what you mean by "remove". TokenMod can relocate the token and/or move it to another layer (effectively hiding it from players), others might be able to remove the token completely. Since you're going to need TokenMod already, I'll use that one. You can replace that portion of the solution later if you find another script/effect you'd rather use. Using OnMyTurn is the more "hands-off" solution, since that would automate the effect every round. OMT requires 1) that the token be in the Turn Order, 2) that it represents a character, and 3) on that character there is an ability macro named "OnMyTurn". Then, when that token's turn comes around, OMT automatically fires that ability to have the effect happen. That's how I'd suggest to go, so that's the solution I'll write. One other note... we're writing an ability macro on a character sheet, but we need to reference the token. To save you from having to retrieve the token id manually and then manually update this command line, you have a couple of other options. You could reference the token based on character name in a Fetch construction: @(SpellTimer.token_id) Or you could reference the current token in the tracker: @(tracker.token_id) I will use the tracker formation, since that (in combination with OnMyTurn) will work for a token of any name, and will be duplicatable if you wanted to replicate this on another character sheet. Solution With all of that said, this should work: !token-mod --set {&if @(selected.bar2) > 1}bar2|-{&else}layer|gmlayer top|70 left|70{&end}{&select @(tracker.token_id)} Put that in an ability named "OnMyTurn" on the character sheet the token represents. Then, when that token's turn comes around, this command will run. It will test the bar2 value and decrement that bar if it is greater than 1. Otherwise, it will move the token to the gmlayer and relocate it to the upper left corner of the map. You could obviously alter this portion to suit a different preference. REQUIRED SCRIPTS: TokenMod, OnMyTurn, APILogic, Fetch, SelectManager (as well as any supporting scripts that get installed automatically when you use the 1-click dropdown to get these scripts) Alternately, once this week's script-merge happens (it was skipped this week, so hopefully next week Tuesday/Wednesday it will happen), you could get the MetaScriptToolbox script instead of getting the last 3 listed scripts. APILogic, Fetch, and SelectManager are all metascripts, and the MetaScriptToolbox will get all of the metascripts to install from the 1-click repository in one go.
Hi TImmaugh My only question would be -- I'd rather the trigger for the bar be rolling dice. As mentioned, it's a healing effect, and I'd like the count to change when the dice are rolled. Could you possibly point me to what would change from the "OnMyTurn" function? 
1692673810
timmaugh
Forum Champion
API Scripter
It seems the reason to have the rolling of dice trigger the effect is just to make sure that the spell isn't forgotten, and that the healing effect occurs as well as the decrementing of the bar value... and in that case, I might go as far as outputting a button to chat for the GM to click. That would be the equivalent of saying, "I'm ready for this spell to take effect...so make it happen." As for what would be changed, that would hard without knowledge of what the healing looked like (how many dice, what attribute would be affected), and how the receiving tokens were identified (it sounds like within some range of the token). I have a metascript very close to being ready that would do the tokens-within-range identification, but it isn't yet ready for wide release. As for the actual value of the healing, it would be something like ChatSetAttr doing the value change. Then I would use ZeroFrame in the OnMyTurn ability macro to batch up the two calls (ChatSetAttr and TokenMod). !{{   !setattr ...   !token-mod ... }}