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

ChatSetAttr: How to change token's bar3?

Trying !setattr --sel --mod --bar3|-2 just makes a new atrbute on the sheet, when I want the token bar to be modified. Note I have multiple mook tokens all linked to the same sheet, I only want to deduct hp for the currently selected token. How do go about that?
1633359000
timmaugh
Pro
API Scripter
ChatSetAttr works on the character sheet. For modifying a token, you want TokenMod. !token-mod --set bar3... and then there are a ton of options for setting to a flat value, decrementing/increasing by X, making sure it stays between 0 and the max... check the documentation handout that comes with it to fit your specific use-case.
You also can bind the modding of the hps between 0 and the max field of the bar.  In chatsetattr this is done with the command !mod b attr --sel --hp|-2.  You can do this in tokenmod too but I'm drawing a blank on the exact syntax and when I quickly browsed the help doc I did not see the entry.  I could have sworn it was an exclamation point that binds the adjustment between 0 and max but alas, I can't find it to confirm it.  
Thanks. Does token-mod has any built in if-then functionality?
1633399499
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Only the barest sort: "If this number is out of range of zero and max, make it zero or max", for example.
1633408237
timmaugh
Pro
API Scripter
You can use the APILogic metascript to add if/then functionality in the TokenMod command line. What kind of if/then do you want to do?
1633431532
David M.
Pro
API Scripter
Scriptcards  is another option.
timmaugh said: You can use the APILogic metascript to add if/then functionality in the TokenMod command line. What kind of if/then do you want to do? Things like: If token's bar3 < MaxHp/2 then apply a condition icon. If token has a  specific condition icon, add a penalty to this roll.
1633461076
timmaugh
Pro
API Scripter
!token-mod --set {&if @{selected|bar3} < [[@{selected|MaxHP}/2]].value } statusmarkers|white-tower {&end} It would come down to what you needed to always include vs what you want included only in a condition. In this case, having the --set outside of the IF would make sense if you always wanted to set SOMETHING, and only include the white-tower status marker assignment if the conditional evaluated to true. In fact, you can obfuscate the entire API handle, or render a simple message by including the API handle in the conditionally included text: !{&if @{selected|bar3} < [[floor(@{selected|MaxHP}/2)]].value }token-mod --set statusmarkers|white-tower {&else}@{selected|token_name} is [\][\]$[[0]].value - @{selected|bar3}\]\] points above half of their max hp.{&simple}{&end} If the conditional fails in this case, it will send a normal message instead of the token-mod command (which would otherwise do nothing anyway). You can see the deferred roll of the message, using the syntax: [\][\] ... \]\] That is one way to include a conditional penalty to a roll (retrieving the value to test first, building the equation, then letting the roll go). Otherwise you could conditionally set an attribute on the character (ChatSetAttr using an APILogic structure), and then use normal inline roll math to flatten the penalty to nothing based on the value... ie, if the penalty were a -5 to the roll, you'd store a 0 in the attribute for "no penalty," or a 1 for "apply the penalty"... then your inline roll would multiply -5 by the value of the attribute: [[1d10 + (-5 * @{selected|wounded_penalty})]] Required Scripts: To do the above inline tricks of APILogic, you'd need APILogic , ZeroFrame , and SelectManager installed.
1633662446

Edited 1633662708
timmaugh said: - Thank you. I made a macro to apply damage to tokens and mark them if they are heavily injured: **@{selected|token_name} loses ?{mod|1} hp!** !token-mod --set bar3_value|-?{mod} !token-mod --set {&if @{selected|bar3} <= [[(@{selected|HP|max}/3)+1]].value } statusmarkers|red {&end} But how do I insert !setattr --sel --silent --Penalty|1 in the conditonal so that it both adds the red dot and sets Penalty attribute to 1.
I also tried to make an ammo tracker (yes I know there is Ammo script, but I dont like the output formating there). Simplified example here: !**@{selected|token_name}** Attacks **@{target|token_name} with [[@{selected|R0Ammo}-1]] shots left. !modattr --sel --silent --R1Ammo|-1 Problem is, the @{target|token_name} couses a deselection of the token, so !modattr complains about no selected token. Any idea on how to fix that. The target token is necessary for other stuff, and cant be taken out.
1633672787
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
If this is to be used by one specific token, use the charid instead of selected: !modattr --charid -1234567890abcde --silent --R1Ammo|-1 You can get the charid for hardcoding by selecting the token and running: @{selected|characetr_id}  Remember that the dash at the beginning is part of the id.
1633713816
timmaugh
Pro
API Scripter
If you need this for more than 1 character, you can cheat for at least 1 selected token by using Plugger and turning one or the other of your lines into an embedded "plug-in" to the other. That way, you can process the selected token_id at the same time, and the value will be in the line before Plugger issues the line: !**@{selected|token_name}** Attacks **@{target|token_name} with [[@{selected|R0Ammo}-1]] shots left.{&eval(^)}!modattr --sel --silent --R1Ammo|-1{^&select @{selected|token_id}}{&/eval} That grabs the token_id of the selected token in the top level roll20 parsing pass of the command line, then drops it in a SelectManager {&select} structure. That structure is deferred (or hidden) because of the ^, so it won't be immediately detected. When Plugger issues the command between the EVAL tags... {&eval} ... {&/eval} ...it will remove a character that you declare as your deferral character. In this case, I used the ^ character: {&eval(^)} So when the Plugger-issued ChatSetAttr call goes through, SelectManager will see the {&select} structure with the right token id and will restore the selected token before ChatSetAttr picks up the message.