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

Move Token to Map Layer on Death

1701986510

Edited 1702004207
UPDATE: Got it to work. Final install of the script is below for anyone else who is running Bar 1 as their HP bar. 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;                 changes.layer = "objects";             } else if(hp <= 0) {                 hp=0;                 changes[bar] = hp;                 changes.status_dead = true;                 changes.order = "tofront"                 changes.layer = "map";             } else {                 changes.status_dead = false;                 changes.layer = "objects";             }             obj.set(changes);         }     };     on("change:token", constrainHPBarToMax);     if('undefined' !== typeof TokenMod && TokenMod.ObserveTokenChange){         TokenMod.ObserveTokenChange(constrainHPBarToMax);     }     if('undefined' !== typeof ApplyDamage && ApplyDamage.registerObserver){         ApplyDamage.registerObserver('change',constrainHPBarToMax);     } });
Does your game use bar 3 for HP? It's also pretty common for tokens to have HP on bar 1. Sorry if that's overly simple of a start. Other than that, might be console output to see if anything is there or potentially add some  logging statements to the script to confirm where it is and what it is processing.
Dude … I think you’re absolutely right I need to check that.. I’ll confirm here shortly
Well that didn't work.. Any ideas what could be happening here? I am using the Aura/Tint HealthColors Script and I'm wondering if that would cause some issues?