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

Is there a Injuries API

Hello, I find it hard to consistently remember to apply injuries in my game so I am looking for help via API. I am looking for something like if damage is done greater than 10% of the players/minions health or is a crit, roll on a table or give me output in chat that i should roll on the table ( if i remember correctly rolling on a table via macro doesnt work). Is there something available like this or can someone give me a starting point to this Thank you In advance
To make my question more specific, is there a way to get the change of hp via API i know i can get the current hp and the max hp      var maxHP = parseInt (obj. get ( "bar1_max" ), 10 ); var currentHP = parseInt (obj. get ( "bar1_value" ), 10 ); but Is there any way to get the previous hp?
1745688724
timmaugh
Forum Champion
API Scripter
While you can typically get the previous value if you're coding your own script (that is, you grab the value, alter it, then grab it again)... or, if you were using TokenMod to make the change, your script could subscribe to TokenMod's publicized event alerting other scripts to a change to the token. In both cases, you'd write a normal event handler, taking 2 objects. The first object will be the token as it exists after change (a human change or a TokenMod change); the second object would be the previous state of the token. The first object would be  a Roll20 object, where you have to use get() methods to see the property values, while the second would be  a normal JavaScript object, where you can access properties directly: const checkLoss = (obj, prev) => {   let prevHP = parseInt(prev.bar1_value);   let curHP = parseInt(obj.get('bar1_value'));   let maxHP = parseInt(obj.get('bar1_max'));   if (prevHP - curHP > maxHP/10) {     // play injurious games; win injurious prizes   } }; You could subscribe that same function to both the Roll20 change:graphic  event, as well as TokenMod's own change:graphic  event (double-check my event nomenclature... I'm air-coding this). Alternatively... However, you don't have to write  your own script to do this. You can make use of the timing of messages to do what you want. I believe TokenMod properly handles tracing a bar adjustment back to the character sheet (ie, bar1 is linked to 'hp', and you adjust bar1 by -10, then 'hp' should show a loss of 10 pts)... so, for now and for an example, let's use TokenMod and the MetascriptToolbox. TokenMod would handle a bar reduction for a targeted token like this. Note this requires you to be a GM to run, or to have the "players can use ids" setting to be turned on for TokenMod. I'll use a damage roll of 2d8: !token-mod --ids @{target|token_id} --set bar1_value|-[[2d8]] The @{target} and @{selected} formations resolve immediately when the command line passes through the Roll20 parser. We can make use of that by retrieving the same value *later*... in a second command line that we can delay. Just as an example, to output a value showing the difference: !token-mod --ids @{target|token_id} --set bar1_value|-[[2d8]] !&{template:default}{{name=Proof of Concept}} {{Report=@{target|token_name} was reduced from @{target|bar1}hp to @(@{target|token_id}.bar1)hp.}} {&delay .3} {&simple} So, with the application of a little APILogic and MathOps to the command line (more metascripts in the toolbox), you can remind yourself to take action. Here, I'll output a report and a button that will let you run a macro named "RollInjury": !token-mod --ids @{target|token_id} --set bar1_value|-[[2d8]] !{&if {&math @{target|bar1} - @(@{target|token_id}.bar1)} > {&math @(@{target|token_id}.bar1_max)/10} }&{template:default}{{name=Proof of Concept}} {{Report=@{target|token_name} was reduced from @{target|bar1}hp to @(@{target|token_id}.bar1)hp.}} {{=[Roll Injury](!
#RollInjury)}} {&delay .3} {&simple}{&end}