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

Removal from Turnorder

Can someone post a section of script that would enable me to remove a token from the turnorder from within the API. Basically I want to have my main script take the damage off a token/character's wounds, and if the token is now dead automatically remove it from the turnorder while still in the script. Thanks if someone has such a script/snippet that they can post. 
1609709737

Edited 1609710251
Oosh
Sheet Author
API Scripter
This should do the trick (you'll obviously want to get rid of the chat logging and the event triggers if it's going inside another script): on('ready', () => { const hpBar = 'bar1_value' // change this if it isn't where you store HP on(`change:token:${hpBar}`, (obj, prev) => { sendChat('api', 'bar2 change detected'); if (parseInt(obj.get(hpBar)) < 1) { // check that token dropped to 0 or less HP let turnOrder = (Campaign().get('turnorder')) ? JSON.parse(Campaign().get('turnorder')) : []; // "turnorder" is a string, and can be empty if (turnOrder.length < 1) return sendChat('api', 'turnorder is empty'); // exit if turn order is empty log(turnOrder); turnOrder.forEach((token, index) => { if (token.id === obj.id) { turnOrder.splice(index, 1); // remove current turnorder entry if it matches the token id that lost HP Campaign().set('turnorder', JSON.stringify(turnOrder)); // re-stringify before setting modified turnorder sendChat('api', `${obj.get('name')} removed from turn order`) } else sendChat('api', `${obj.id} not found in turn order`); }) } }); }); I'm not sure what system you're playing, but worth noting that in 5e this will remove a player when they get knocked out. They'd need to be added back to the turn order as soon as they're healed. May not be relevant to what you're playing. If the script does anything apart from removing turn order entries, you'd probably want to remove the early return if (turnorder.length < 1), as an empty array is perfectly valid for adding entries to. More info here .
That worked nicely, thank you!