@GiGs created a Script API that works off this sheet. It is pasted below. It takes a character sheet's selections for peril and damage tracks and changes the bars on the token attached to the character sheet. You do manually need to set the max of said bar to 5 on the token. See below: on('ready', () => {
const bars = {
// 1 is green top bar, 2 is blue middle bar and 3 is bottom red bar. Set them below as you see fit.
peril: 1,
damage: 2
};
const damages = ['Damage_Track_2', 'Damage_Track_3', 'Damage_Track_4', 'Damage_Track_5', 'Damage_Track_6'];
const perils = [ 'peril_imperiled','peril_ignore_one','peril_ignore_two','peril_ignore_three','peril_incapcitated'];
const calcScore = (charid, peril = false) => {
const stats = peril ? perils : damages;
return stats.reduce((total, name) => total += (parseInt(getAttrByName(charid, name))||0) === 0 ? 0 : 1, 0);
};
on('change:attribute:current', function(obj) {
const att = obj.get('name');
if(perils.includes(att) || damages.includes(att)) {
const char = getObj('character', obj.get('characterid'));
// do a search of all matching tokens
const tokens = findObjs({
_type: 'graphic',
represents: char.id
});
const score = calcScore (char.id, perils.includes(att));
tokens.forEach(token => {
token.set({[`bar${perils.includes(att) ? bars.peril : bars.damage}_value`]: score});
});
}
});
on('add:graphic', function(obj) {
if(obj.get('represents') != '') {
const token_id = obj.id;
_.delay(()=>{
const token=getObj('graphic',token_id);
if(token){
const char = getObj('character', obj.get('represents'));
obj.set({
[`bar${bars.peril}_value`]: calcScore(char.id, true),
[`bar${bars.damage}_value`]: calcScore(char.id, false)
});
}
}, 300);
}
});
});