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

[HELP] Remove token from turn order when Bar1 drops below 0 due to API activity

So, I've got GroupCheck working for my group saving throws, and ApplyDamage automatically applying the damage to the tokens, and the changes are being tracked by TempHPandStatus nicely (thanks Jakob for your help!) Now, I have a small script from TheAaron (referenced in  this thread ) which removes tokens from the Turn Order when their HP (Bar1 on the tokens) are manually made to drop below 0.  However, now I have a slight problem in that the script to remove from the turn order doesn't recognize what GroupCheck and ApplyDamage are doing, and when Bar1 drops below 0 due to the actions of these scripts, the tokens remain on the Turn Order.  Can the script to remove from the Turn Order be modified just as TempHPandStatus was?
1524316114

Edited 1524318566
The Aaron
Pro
API Scripter
Try using this version: const DropAtZeroHealth = (()=>{     const threshold = 0;     const bar = 3;     const onChangeGraphic = (obj,prev) => {         const healthBar = `bar${bar}_value`;         const val = parseInt(obj.get(healthBar));         if(val !== parseInt(prev[healthBar]) && val <= threshold){             let turnorder = Campaign().get('turnorder');             turnorder = ('' === turnorder) ? [] : JSON.parse(turnorder);             turnorder = _.reject(turnorder, function(i){                 return obj.id === i.id;             });             Campaign().set('turnorder',JSON.stringify(turnorder));             obj.set('statusmarkers','dead');         }     };     const registerEvents = () => {         on('change:graphic', onChangeGraphic);     };     return {         RegisterEvents: registerEvents,         OnChangeGraphic: onChangeGraphic     }; })(); on('ready',() => DropAtZeroHealth.RegisterEvents() ); and adding this after line 91 of ApplyChange: if('undefined' !== typeof DropAtZeroHealth && DropAtZeroHealth.OnChangeGraphic) {   DropAtZeroHealth.OnChangeGraphic(token, prev); }
Got this error: For reference, the error message generated was: TypeError: DropAtZeroHealth.registerEvents is not a function TypeError: DropAtZeroHealth.registerEvents is not a function at on (apiscript.js:3839:35) at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:70:8) at checkForReady (/home/node/d20-api-server/api.js:1438:12) at /home/node/d20-api-server/api.js:1518:9 at c (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:14:64) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Zd.Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:111:400
1524318583
The Aaron
Pro
API Scripter
Ah. Typo, corrected above. 
Now it's giving me the dreaded "Unexpected Identifier" Also, I want the bar to be Bar 1, not bar 3, and I'd like the threshold to be -1 (I want tokens with 0 health to not be removed - I set PCs health at 0, so they stay in to make death saves, but maybe there's a better way to handle that, since the ApplyChange script is automatically applying damage.  Maybe not remove tokens that are assigned to a player?). Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. More info... For reference, the error message generated was: SyntaxError: Unexpected identifier
1524319599
The Aaron
Pro
API Scripter
Ok. Wanna PM me a join link and I’ll pop in and sort it out?
Sent.
1524323747
The Aaron
Pro
API Scripter
Fixed.  Advanced version that doesn't remove player tokens (be sure to set your bar # for HP on line 3): const DropAtZeroHealth = (()=>{     const threshold = 0;     const bar = 1;     const isPlayerToken = (obj) => {         let players = obj.get('controlledby')             .split(/,/)             .filter(s=>s.length);         if( players.includes('all') || players.filter((p)=>!playerIsGM(p)).length ) {            return true;         }          if('' !== obj.get('represents') ) {             players = (getObj('character',obj.get('represents')) || {get: function(){return '';} } )                 .get('controlledby').split(/,/)                 .filter(s=>s.length);             return  players.includes('all') || players.filter((p)=>!playerIsGM(p)).length ;         }         return false;     };     const onChangeGraphic = (obj,prev) => {         const healthBar = `bar${bar}_value`;         const val = parseInt(obj.get(healthBar));         if(val !== parseInt(prev[healthBar]) && val <= threshold ){             if(!isPlayerToken(obj)){                 let turnorder = Campaign().get('turnorder');                 turnorder = ('' === turnorder) ? [] : JSON.parse(turnorder);                 turnorder = turnorder.filter((i)=>i.id !== obj.id);                 Campaign().set('turnorder',JSON.stringify(turnorder));             }             obj.set('statusmarkers','dead');         }     };     const registerEvents = () => {         on('change:graphic', onChangeGraphic);     };     return {         RegisterEvents: registerEvents,         OnChangeGraphic: onChangeGraphic     }; })(); on('ready',() => DropAtZeroHealth.RegisterEvents() );
Thanks, The Aaron!  Great work, as usual!
1524336322
The Aaron
Pro
API Scripter
=D