Hello all you lovely people of the internet. I tried editing and customizing an API that I found in a post, and for some reason it doesn't always register that it's working. Here's the code
const layerToMove = 'gmlayer'; //map,gmlayer
const statusToSet = 'status_dead';
const playerStatusToSet = 'status_skull';
const bolLayerMoveOnDeath = true; //true,false
let barToCheck = 'bar1_value'; //bar1_value,bar2_value,bar3_value
let acceptedValues = ['bar1_value', 'bar2_value', 'bar3_value'];
on('chat:message', function (msg) {
if (msg.type == 'api' && msg.content.indexOf('!SetHealthBar') !== -1) {
var message = msg.content.split(' ')[1];
if (acceptedValues.includes(message)) {
barToCheck = message;
log('Set Health bar value changed to ' + message);
}
}
});
on('change:graphic:' + barToCheck, function(obj, prev) {
//log('MoveDeadToGMLayer Checking: ' + barToCheck + ' event on object ' + obj.get('name'));
if (obj.get('_pageid') == Campaign().get('playerpageid') && obj.get('_subtype') == 'token' && obj.get(barToCheck) < 1 && prev[barToCheck] > 0 ) {
var players=obj.get('controlledby').split(/,/);
if(obj.get('represents') != '') {
var represent = getObj("character", obj.get("represents"));
var characters = represent.get('controlledby').split(/,/);
if(players[0] == '' && characters[0] == '') {
obj.set(statusToSet, true);
}
else {
obj.set(playerStatusToSet,true);
sendChat('',obj.get('name') + " is dying!");
}
}
}
if (obj.get('_pageid') == Campaign().get('playerpageid') && obj.get('_subtype') == 'token' && obj.get(barToCheck) <= obj.get(barToCheck.replace("value", "max")) / 2) {
obj.set("tint_color", '#ff0000');
}
else {
obj.set("tint_color", 'transparent');
}
if ((obj.get('_pageid') == Campaign().get('playerpageid') && obj.get('_subtype') == 'token' && obj.get(barToCheck) > 0) ) {
obj.set(statusToSet, false);
obj.set(playerStatusToSet, false);
}
});
Again, I'm not the one who made the original code, and I'm not sure who originally posted this as I lost the information, but I'd really appreciate any help in getting this to run consistently. Thank you!