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 .
×

Feng Shui 2 Shot Tracker in the tracker API help

I'm running a Feng Shui 2 game. For those who don't know, you generate initiative again at the start of each "frame" which is sort of a round. Then the actions you take have a cost associated - usually 3 "shots." So, if you got a 9 on your initiative, and attack on 9 with a shot cost of 3, you'll go again on 6. I have macros set up that automatically deduct the shot cost from the token's initiative in the tracker, but am looking for an API script that will automatically re-sort the tracker so the character who is next is always at the top that I can tack onto the end of actions. Any help would be appreciated.
1596690381
The Aaron
Roll20 Production Team
API Scripter
GroupInitiative can sort for you: !group-init --sort That's limited to the GM, but I can throw together a simple script tomorrow that handles the above for you pretty easily.
Thanks - that would be much appreciated!
1596718231
The Aaron
Roll20 Production Team
API Scripter
Ok, here ya go! !fs-init [Amount to subtract] So, you might do: !fs-init 3 or !fs-init [[1d8]] or !fs-init @{selected|shot_cost} or whatever.  Works for players if they can control the token at the top of the turn order.  Always works for the GM.  Sorts after change. Script: on('ready',()=>{ const playerCanControl = (obj, playerid='any') => { const playerInControlledByList = (list, playerid) => list.includes('all') || list.includes(playerid) || ('any'===playerid && list.length); let players = obj.get('controlledby') .split(/,/) .filter(s=>s.length); if(playerInControlledByList(players,playerid)){ return true; } if('' !== obj.get('represents') ) { players = (getObj('character',obj.get('represents')) || {get: function(){return '';} } ) .get('controlledby').split(/,/) .filter(s=>s.length); return playerInControlledByList(players,playerid); } return false; }; const processInlinerolls = (msg) => { if(_.has(msg,'inlinerolls')){ return _.chain(msg.inlinerolls) .reduce(function(m,v,k){ let 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(); } else { return msg.content; } }; /* eslint-disable no-unused-vars */ const getTurnArray = () => ( '' === Campaign().get('turnorder') ? [] : JSON.parse(Campaign().get('turnorder'))); const setTurnArray = (ta) => Campaign().set({turnorder: JSON.stringify(ta)}); const addTokenTurn = (id, pr) => Campaign().set({ turnorder: JSON.stringify( [...getTurnArray(), {id,pr}]) }); const addCustomTurn = (custom, pr) => Campaign().set({ turnorder: JSON.stringify( [...getTurnArray(), {id:-1,custom,pr}]) }); const removeTokenTurn = (tid) => Campaign().set({ turnorder: JSON.stringify( getTurnArray().filter( (to) => to.id !== tid)) }); const clearTurnOrder = () => Campaign().set({turnorder:'[]'}); const sorter_asc = (a, b) => a.pr - b.pr; const sorter_desc = (a, b) => b.pr - a.pr; const sortTurnOrder = (sortBy = sorter_desc) => Campaign().set({turnorder: JSON.stringify(getTurnArray().sort(sortBy))}); /* eslint-enable no-unused-vars */ on('chat:message',msg=>{ if('api'===msg.type && /^!fs-init(\b\s|$)/i.test(msg.content)){ //let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); let args = processInlinerolls(msg).split(/\s+/); let to = getTurnArray(); let token = getObj('graphic',(to[0]||{}).id); if( playerIsGM(msg.playerid) || (token && playerCanControl(token,msg.playerid)) ){ let adjust = parseFloat(args[1])||0; to[0].pr = parseFloat(to[0].pr)-(adjust); setTurnArray(to.sort(sorter_desc)); } } }); });
That's awesome. Thank you so much!