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

Script to remove token from initiative tracker?

Quick query/request: Does anyone have a chunk of script code that will remove  the selected token(s) from the initiative tracker? Thanks in advance. :-)
I was given this a while back by an arcane scriptomancer.  It removes a token from the turn order if bar1 goes to -1 or lower.  You can change that threshold if need be.  I use it to remove NPCs that fall in battle, and I set PC health to 0 when they fall, so they stay in the turn order for Death Saves. Hope this helps! on('ready',function() {     'use strict';          // Threshold to be equal to or less than to get removed     var threshold = -1;          // 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));         }     }); });
1502712509
The Aaron
Pro
API Scripter
If you just need a command to remove the selected token(s), I can whip you one up.
1502713192

Edited 1502713258
The Aaron
Pro
API Scripter
Actually, I had one laying around: on('ready',function(){     "use strict";     var removeTokenTurn = function(tid) {         Campaign().set({             turnorder: JSON.stringify(                 _.reject(                     ( '' === Campaign().get('turnorder') ? [] : JSON.parse(Campaign().get('turnorder')) ),                     function(to) {                         return to.id === tid;                     }                 )             )         });     };     on('chat:message',function(msg){         var args;         if (msg.type !== "api") {             return;         }         args = msg.content.split(/\s+/);         switch(args.shift()) {             case '!noturn':                 _.each(msg.selected,function(s){                     removeTokenTurn(s._id);                 });                 break;         }     }); }); Select 1 or more tokens and run !noturn to remove them
Awesome! Thanks, Gozer and Aaron!