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

[Request] Simple status check

I tried to do this with token mod but I don't see a way to do the if/then part. I would like a script that checks a number of token id's that are supplied in a list (like the ids command in tokenmod) and then checks Bar2 on each of them to see whether its positive or less then 1. If its less then 1 put the backpain status up.  This is basically a global stamina check per round, although it could be used for HP too.
1463775323

Edited 1464009187
The Aaron
Pro
API Scripter
I've not tested this yet, but this should do what you want. !bar-status <bar number> <status name> <value to compare to> <comparison type> <reset status on failed comparison> --ids <token id> [<token id> ...] Possible comparisons (case insensitive): LessThan GreaterThan LessThanOrEqual GreaterThanOrEqual Equal Example: !bar-status 2 back-pain 1 LessThan yes --ids @{target|token_id} Reasonable defaults are chosen for omitted options: !bar-status --ids @{target|token_id} @{selected|token_id} -JAdfasJas12ss5 Will check bar 1 is greater than 0 and set back-pain if that's the case but not reset. Let me know how it goes, I'll try and test this a bit later tonight... Code: on('ready',function(){     "use strict";     var compFuncs={         greaterthan: (o,v) => parseInt(o,10)>v,         lessthan: (o,v) => parseInt(o,10)<v,         greaterthanorequal: (o,v) => parseInt(o,10)>=v,         lessthanorequal: (o,v) => parseInt(o,10)<=v,         equal: (o,v) => parseInt(o,10)===v     },     yesValues = [1,'1','on','yes','true','sure','yup','-'],     statusValues = ['red', 'blue', 'green', 'brown', 'purple', 'pink',         'yellow', 'dead', 'skull', 'sleepy', 'half-heart', 'half-haze',         'interdiction', 'snail', 'lightning-helix', 'spanner', 'chained-heart',         'chemical-bolt', 'death-zone', 'drink-me', 'edge-crack', 'ninja-mask',         'stopwatch', 'fishing-net', 'overdrive', 'strong', 'fist', 'padlock',         'three-leaves', 'fluffy-wing', 'pummeled', 'tread', 'arrowed', 'aura',         'back-pain', 'black-flag', 'bleeding-eye', 'bolt-shield', 'broken-heart',         'cobweb', 'broken-shield', 'flying-flag', 'radioactive', 'trophy',         'broken-skull', 'frozen-orb', 'rolling-bomb', 'white-tower', 'grab',         'screaming', 'grenade', 'sentry-gun', 'all-for-one', 'angel-outfit',         'archery-target'],     toBar = (o) => {         let v=parseInt(o,10);         return `bar${ _.contains([1,2,3],v) ? v : 1}_value`;     },     toStatus = (o) => {         return _.contains(statusValues,o) ? o : 'back-pain';     },     toValue = (o) => {         return parseInt(o,10) || 0;     },     toCompFunc = (o) => {         let v=o.toLowerCase();         return (_.has(compFuncs,v) ? compFuncs[v] : compFuncs.greaterthan );     },     toReset = (o) => {         return _.contains(yesValues,o);     };     on('chat:message',function(msg_orig){         var cmd,bar,status,comparison,value,ids,msg,tokens,reset;         if('api' !== msg_orig.type || !playerIsGM(msg_orig.playerid) ){             return;         }         msg=_.clone(msg_orig);         if(_.has(msg,'inlinerolls')){             msg.content = _.chain(msg.inlinerolls)             .reduce(function(m,v,k){                 var ti=_.reduce(v.results.rolls,function(m2,v2){                     if(_.has(v2,'table')){                         m2.push(_.reduce(v2.results,function(m3,v3){                             m3.push(v3.tableItem.name);                             return m3;                         },[]).join(', '));                     }                     return m2;                 },[]).join(', ');                 m['$[['+k+']]']= (ti.length && ti) || v.results.total || 0;                 return m;             },{})             .reduce(function(m,v,k){                 return m.replace(k,v);             },msg.content)             .value();         }         ids = msg.content.split(/\s+--ids\s+/);         cmd = ids.shift().split(/\s+/);         ids=( ( ids[0] && ids[0].split(/\s+/) ) || []);         ids = _.union(ids, ((msg.selected && _.pluck(msg.selected,'_id')) || []) );         switch(cmd.shift()){             case '!bar-status':                 bar = toBar(cmd.shift());                 status = toStatus(cmd.shift());                 value = toValue(cmd.shift());                 comparison = toCompFunc(cmd.shift());                 reset = toReset(cmd.shift());                 tokens = _.chain(ids)                     .uniq()                     .map( (id) => getObj('graphic',id) )                     .reject(_.isUndefined)                     .each( o => {                         if( comparison(o.get(bar),value)){                             o.set(`status_${status}`,true);                         } else if(reset){                             o.set(`status_${status}`,false);                         }                     });         }     }); });
thanks a bunch I will play around with this tomorrow and see how it goes but I think it will work great.
I copied that code into a new script called bar-status and ran it with both of those commands above and I got this error message both times. TypeError: cmd.shift is not a function TypeError: cmd.shift is not a function at apiscript.js:2352:20 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:105:34), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:105:34), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1197:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:111:400
1463936233
The Aaron
Pro
API Scripter
Ok, I corrected the script above.  I also added operating on the selected tokens.  So, you can select tokens and run the commands, or use --ids to specify tokens, or both. =D Let me know if you have any more problems!
1464002622

Edited 1464002692
Ok so when I select a bunch of tokens with a drag-box it works perfectly. I have another macro that collects token ids and whispers them to the GM. On my map the results was -KI9DcOFqjIJtK8g6z3X -KI9DczB5LcBfws6PSw2 -KI9DeD5o2A1ECOllt_u -KI9DdcSz0M8QuYzKw_M -KI9Deoxrlqd9xVc9JDn -KI9HQDXX_6In4yVOe6w I copy this text directly into the command below right after the --ids in a new macro.  However when I run the macro this way with nothing selected but passing the ids nothing happens to any of the tokens.  This below is the macro I use. !bar-status 2 back-pain 1 LessThan yes --ids -KI9DcOFqjIJtK8g6z3X -KI9DczB5LcBfws6PSw2 -KI9DeD5o2A1ECOllt_u -KI9DdcSz0M8QuYzKw_M -KI9Deoxrlqd9xVc9JDn Do all token ids start with the - or is that some kind of separater I shouldn't be including. Thanks for all the help Aaron.
1464003208
The Aaron
Pro
API Scripter
Hmm. I'll give that another try and see if I can duplicate it. Just to verify, can you try passing that string of token ids to token mod and verify it works there?
1464009200
The Aaron
Pro
API Scripter
Ok, found and squashed the bug, updated the code above!  =D
Thanks that works.