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

Remove from initiative and incriment to next token

1525273779

Edited 1525274124
I have a few scripts running simultaneously - GroupInitiative and Turnmarker as well as a little extra guy that is removing a token from initiative when their hp bar drops to zero.  The problem i am facing is that when I drop the token to zero, they move out of the Turn Order but the Turnmarker is not automatically moving to/highlighting the next token. Here is the extra piece of code to remove the token, what can i do to also move the turnmarker? on('ready',function() { 'use strict'; // Threshold to be equal to or less than to get removed var threshold = 0; // Activate on a change to the value of bar1 on('change:graphic:bar1_value',function(obj){ var turnorder; // if the value is below or equal if( obj.get('bar1_value') <= threshold ){ // grab the current turnorder turnorder = Campaign().get('turnorder'); // if it's the empty string, then just treat it as an array, // otherwise decode it as a JSON string into the array of turns turnorder = ('' === turnorder) ? [] : JSON.parse(turnorder); // Get a version of it without the token we were activated for turnorder = _.reject(turnorder, function(i){ return obj.id === i.id; }); // encode the array as a JSON string and // stuff it back in the turnorder property of the Campaign Campaign().set('turnorder',JSON.stringify(turnorder)); } }); });
As I think about this, it would only be and issue if the token recieves damage on their turn that reduces them to zero.  May not come up a lot.
1525274910
The Aaron
Pro
API Scripter
This should do what you want: on('ready',function() {     'use strict';     // Threshold to be equal to or less than to get removed     var threshold = 0;  let onTurnOrderChange = ('undefined' !== typeof TurnMarker && TurnMarker.TurnOrderChange ? () =>  TurnMarker.TurnOrderChange() : () => {} );              // Activate on a change to the value of bar1     on('change:graphic:bar1_value',function(obj){         var turnorder;         // if the value is below or equal         if( obj.get('bar1_value') <= threshold ){             // grab the current turnorder             turnorder = Campaign().get('turnorder');             // if it's the empty string, then just treat it as an array,              // otherwise decode it as a JSON string into the array of turns             turnorder = ('' === turnorder) ? [] : JSON.parse(turnorder);             // Get a version of it without the token we were activated for             turnorder = _.reject(turnorder, function(i){                 return obj.id === i.id;             });             // encode the array as a JSON string and              // stuff it back in the turnorder property of the Campaign             Campaign().set('turnorder',JSON.stringify(turnorder)); onTurnOrderChange();         }     }); }); TurnMarker1 exposes a function that causes it to do the work when a turn order change occurs.  This is what GroupInitiative calls (via the Observer Pattern) when it updates the turn order.  API changes don't cause events, so other mechanisms have to be used. Let me know if that works, I didn't get the chance to test it yet. =D
1525275297
The Aaron
Pro
API Scripter
Matt M said: As I think about this, it would only be and issue if the token recieves damage on their turn that reduces them to zero.  May not come up a lot. That happens to me all the time... =D  Opportunity Attacks, Spike Growth, Wall of Fire, Evard's Black Tentacles... 
That worked like a charm!  And yeah, those PCs are tricky aren't they?
Hey is there anything that could be added to move the token to the GM layer while we are at it? 
1525275507
The Aaron
Pro
API Scripter
Great!
Or I guess delete it entirely.  Not sure what the call would be for one vs the other.
1525275592
The Aaron
Pro
API Scripter
Matt M said: Hey is there anything that could be added to move the token to the GM layer while we are at it?  Sure: on('ready',function() {     'use strict';     // Threshold to be equal to or less than to get removed     var threshold = 0;  let onTurnOrderChange = ('undefined' !== typeof TurnMarker && TurnMarker.TurnOrderChange ? () =>  TurnMarker.TurnOrderChange() : () => {} );              // Activate on a change to the value of bar1     on('change:graphic:bar1_value',function(obj){         var turnorder;         // if the value is below or equal         if( obj.get('bar1_value') <= threshold ){             // grab the current turnorder             turnorder = Campaign().get('turnorder');             // if it's the empty string, then just treat it as an array,              // otherwise decode it as a JSON string into the array of turns             turnorder = ('' === turnorder) ? [] : JSON.parse(turnorder);             // Get a version of it without the token we were activated for             turnorder = _.reject(turnorder, function(i){                 return obj.id === i.id;             });             // encode the array as a JSON string and              // stuff it back in the turnorder property of the Campaign             Campaign().set('turnorder',JSON.stringify(turnorder)); onTurnOrderChange(); obj.set('layer', 'gmlayer');         }     }); });
1525275734
The Aaron
Pro
API Scripter
Matt M said: Or I guess delete it entirely. Not sure what the call would be for one vs the other. Sure: on('ready',function() { 'use strict'; // Threshold to be equal to or less than to get removed var threshold = 0; let onTurnOrderChange = ('undefined' !== typeof TurnMarker && TurnMarker.TurnOrderChange ? () => TurnMarker.TurnOrderChange() : () => {} ); // Activate on a change to the value of bar1 on('change:graphic:bar1_value',function(obj){ var turnorder; // if the value is below or equal if( obj.get('bar1_value') <= threshold ){ // grab the current turnorder turnorder = Campaign().get('turnorder'); // if it's the empty string, then just treat it as an array, // otherwise decode it as a JSON string into the array of turns turnorder = ('' === turnorder) ? [] : JSON.parse(turnorder); // Get a version of it without the token we were activated for turnorder = _.reject(turnorder, function(i){ return obj.id === i.id; }); // encode the array as a JSON string and // stuff it back in the turnorder property of the Campaign Campaign().set('turnorder',JSON.stringify(turnorder)); onTurnOrderChange(); obj.remove(); } }); });
Woo hoo!  Thanks.
1525276202
The Aaron
Pro
API Scripter
No problem! =D