I'm implementing a script to handle bloodied and death marker tokens, and I've got it working nicely. I then started making it automatically display some blood fx when bloodied, which also works great... except it would be nice to be able to have a different fx display when HEALING, as opposed to taking damage. Here's my full code: /* global TokenMod */
on('ready',()=>{
// CONFIGURE
const bar = 3;
const bloodied = "bloodied::3239204";
const dying = "dying::3239210"
const dead = "dead::3239207";
const fx_sparks_id = findObjs({_type: "custfx", name: "metal_sparks"})[0].id;
const fx_blood_id = findObjs({_type: "custfx", name: "bloodsplat"})[0].id;
// no edit below here //
const unpackSM = (stats) => stats.split(/,/).reduce((m,v) => {
let p = v.split(/@/);
p[0]=p[0].toLowerCase();
let n = parseInt(p[1] || '0', 10);
if(p[0].length) {
m[p[0]] = Math.max(n, m[p[0]] || 0);
}
return m;
},{});
const packSM = (o) => Object.keys(o)
.map(k => ('dead' === k || true === o[k] || o[k]<1 || o[k]>9) ? k : `${k}@${parseInt(o[k])}` ).join(',');
const handleBarChange = (obj) => {
const bv = parseFloat(obj.get(`bar${bar}_value`));
const bm = parseFloat(obj.get(`bar${bar}_max`));
if(Number.isNaN(bm)){
return;
}
let sm = unpackSM(obj.get('statusmarkers'));
if(bv > (bm / 2) && bv < bm) {
spawnFx(obj.get('left'), obj.get('top'), fx_sparks_id);
}
if(bv <= (bm / 2) && bv > 0) {
sm[bloodied] = true;
spawnFx(obj.get('left'), obj.get('top'), fx_blood_id);
}
else{
delete sm[bloodied];
}
if(bv > (0 - (bm / 2)) && bv <= 0) {
sm[dying] = true;
spawnFx(obj.get('left'), obj.get('top'), 'glow-death');
}
else{
delete sm[dying];
}
if(bv <= (0 - (bm / 2)) ) {
sm[dead] = true;
spawnFx(obj.get('left'), obj.get('top'), 'bomb-death');
}
else {
delete sm[dead];
}
obj.set({
statusmarkers: packSM(sm)
});
};
on(`change:graphic:bar${bar}_value`, handleBarChange);
if('undefined' !== typeof TokenMod && TokenMod.ObserveTokenChange){
TokenMod.ObserveTokenChange(handleBarChange);
}
}); What would I do in order to have this detect whether the player decreased to bar's value, or decreased it? As far as I can tell, I only seem to be able to detect what the CURRECT bar value is, not what triggered the change.