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

'Apply Damage' script combining with 'Dead Marker' tracking

1553771612

Edited 1553771684
Disclaimer - I have no idea how the API's work. You Guru's are on a higher plane of existence than a mere mortal like me! Every week my players create area of effect attacks, which I manage using Jacobs latest 'GroupCheck' API. It also uses his addon bit 'ApplyDamage'. In addition to this, I also use 'DeathTracker.js' from Robin Kuipera AND fancy script from Aaron which I just call 'Health Tracker' (which I've since forgotten it's purpose!). - It may duplicate the effect of 'Death Tracker'. I can't remember any more. I may be duplicating things. on('ready', () => { const HPBarNum = 1; const bar = `bar${HPBarNum}_value`; const max = `bar${HPBarNum}_max`; const constrainHPBarToMax = (obj) => { const hpMax = parseInt(obj.get(max),10); if(!isNaN(hpMax) && 'token' === obj.get('subtype') && !obj.get('isdrawing') ){ let hp = parseInt(obj.get(bar),10); let changes = {}; if(hp > hpMax) { hp = hpMax; changes[bar] = hp; changes.status_dead = false; } else if(hp <= 0) { hp=0; changes[bar] = hp; changes.status_dead = true; } else { changes.status_dead = false; } obj.set(changes); } }; on("change:token", constrainHPBarToMax); if('undefined' !== typeof TokenMod && TokenMod.ObserveTokenChange){ TokenMod.ObserveTokenChange(constrainHPBarToMax); } }); Anyway. - One/both? of these script watches for any tokens that either goes into negative HP, or 0 HP, then it will make the negative HP just '0' and then it ALSO adds the big red cross 'Death' token over the top. It works super well. However, when I 'Apply Damage' using Jakobs script, the damage is applied but since I'm not manually changing a figure, I don't think that the other API's are being 'notified?' that a change has occurred. I don't know if this is anything to do with the term 'Sheetworkers' that I've heard of? Anyway. - I can adjust it by going onto each effected monster, go to his health (which may say -10) and then just press enter. - It then sort of 'refreshes' and the API check kicks in and changes the HP to 0 and applies the death marker correctly. Is there a way that this minor issue can be fixed? Either by me reselecting all effected monsters in the API and clicking a "Hey, there has been a change, please check these numbers again" button.... or better still, one where maybe the 'apply damage' script has a final bit added to the end where it also 'Notifies the other scripts there has been a change'.... I hope that this makes sense to anyone reading this. If not, I can try to re-explain, maybe with pictures! - Thanks!
1553773403
The Aaron
Roll20 Production Team
API Scripter
That makes perfect sense. The issue is that api changes don’t cause events like manual changes do. That means scripts must provide an explicit mechanism for notifying each other that they made a change (that’s what ObserveTokenChange() in the above is doing). There is probably a system in GroupCheck that does this, I’ll have to check then modify the above to make use of it.  SheetWorkers are kind of like character sheet specific api scripts they run on individual characters to do complex adjustments when those sheets are changed. A good example is calculating the encumbrance when inventory is changed. They sometimes interact with API scripts and are written in the same language, JavaScript.
Amazing! - Thanks. Any fancy new code would be appreciated! (<a href="https://i.imgflip.com/1i7mm7.jpg" rel="nofollow">https://i.imgflip.com/1i7mm7.jpg</a>)
1553775393
The Aaron
Roll20 Production Team
API Scripter
This version should work: on('ready', () =&gt; { const HPBarNum = 1; const bar = `bar${HPBarNum}_value`; const max = `bar${HPBarNum}_max`; const constrainHPBarToMax = (obj) =&gt; { const hpMax = parseInt(obj.get(max),10); if(!isNaN(hpMax) &amp;&amp; 'token' === obj.get('subtype') &amp;&amp; !obj.get('isdrawing') ){ let hp = parseInt(obj.get(bar),10); let changes = {}; if(hp &gt; hpMax) { hp = hpMax; changes[bar] = hp; changes.status_dead = false; } else if(hp &lt;= 0) { hp=0; changes[bar] = hp; changes.status_dead = true; } else { changes.status_dead = false; } obj.set(changes); } }; on("change:token", constrainHPBarToMax); if('undefined' !== typeof TokenMod &amp;&amp; TokenMod.ObserveTokenChange){ TokenMod.ObserveTokenChange(constrainHPBarToMax); } if('undefined' !== typeof ApplyDamage &amp;&amp; ApplyDamage.registerObserver){ ApplyDamage.registerObserver('change',constrainHPBarToMax); } });
Perfect! - Thanks!
1553783286
The Aaron
Roll20 Production Team
API Scripter
Possible that’s not completely right, I’ll test it tonight. &nbsp;
1553783729
The Aaron
Roll20 Production Team
API Scripter
And let me know if you try it and it works. =D
1553784190

Edited 1553784356
Thanks amazing again. One 'minor' thing, which is by no means the end of the world (I feel bad for even mentioning it!) - is that I also use ' LazyExperience '. It's not that much of an issue in my current game, since in my current game, I use a 'milestone' approach to levelling up, but I did notice that the LazyExperience API seemingly isn't being notified that a monster has died....- I don't know how this would work since the 'Apply Damage' macro potentially results in multiple monsters all dying at exactly the same time. I wouldn't want the game to trip over itself as it tries to report the 'death' of multiple monsters all at the same time. - Any ideas....? That said, if you've had enough of helping (Super quickly btw!) - I'll understand.
1553789599
The Aaron
Roll20 Production Team
API Scripter
No worries. It’s the same exact problem. LazyExperience relies on the change event which isn’t triggered by the api change. Basically, we need to add the same explicit notification to LazyExperience.&nbsp; This is one of those areas where I feel like there could be a one-size-fits-all solution, but I’ve not had much time for api work lately. It’s on my perpetual list if things to look into.&nbsp;
Just tried it out with apply damage and couldn't get it working for me but I could be doing something wrong :p
Anthony V. said: Just tried it out with apply damage and couldn't get it working for me but I could be doing something wrong :p It may have nothing to do with it, but I also had 'DeathTracker.js' from Robin Kuipera running too?
1553812916

Edited 1553812941
godthedj said: Anthony V. said: Just tried it out with apply damage and couldn't get it working for me but I could be doing something wrong :p It may have nothing to do with it, but I also had 'DeathTracker.js' from Robin Kuipera running too? Yes that is what I am using as well, Did that work for your game?
Anthony. - Yes... you're welcome to join my game as a Co GM and check it out... see what the difference are etc PM me if interested...