
Hi all,
I have what I hope is a simple question. I'm using token mod and the following "health tracker" script to help with hp management. I would like to add a line to move the token to the map layer when it dies. I'm not sure what the syntax is for this. Can someone assist? I feel like it should go right after " changes.status_dead = true;" but I don't know what to put there.
on('ready', () => {
const HPBarNum = 3;
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);
}
if('undefined' !== typeof ApplyDamage && ApplyDamage.registerObserver){
ApplyDamage.registerObserver('change',constrainHPBarToMax);
}
});
Thanks much in advance!