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

Query: Controlling turn order

1546714257
Pat S.
Forum Champion
Sheet Author
Has there been an API script written that allows players to progress the turn order and or use some of the functions of the turn order such as open, assign ascending or descending, etc...? I'm working on setting up the board game " Yatzoid " to be GMless type of game and having the option to not requiring anyone being assigned co-GM status will help out tremendously.
1546715135

Edited 1546720828
The Aaron
Pro
API Scripter
TurnMarker has an !eot command built in that advanced the turn if the player executing it owns the current turn's token.  If you just want a pass the turn command, I can throw one together. on('ready', ()=>{ const getTurnArray = () => ( '' === Campaign().get('turnorder') ? [] : JSON.parse(Campaign().get('turnorder'))); const setTurnArray = (ta) => Campaign().set({turnorder: JSON.stringify(ta)}); const addCustomTurn = (custom, pr) => Campaign().set({ turnorder: JSON.stringify( [...getTurnArray(), {id:-1,custom,pr}]) }); const sorter_asc = (a, b) => b.pr - a.pr; const sorter_desc = (a, b) => a.pr - b.pr; const sortTurnOrder = (sortBy = sorter_desc) => Campaign().set({turnorder: JSON.stringify(getTurnArray().sort(sortBy))}); const getPageForPlayer = (playerid) => { let player = getObj('player',playerid); if(playerIsGM(playerid)){ return player.get('lastpage'); } let psp = Campaign().get('playerspecificpages'); if(psp[playerid]){ return psp[playerid]; } return Campaign().get('playerpageid'); }; on('chat:message', (msg)=>{ if('api'===msg.type) { if(/^!eot\b/i.test(msg.content)){ let to = getTurnArray(); let t = to.shift(); to.push(t); setTurnArray(to); } else if (/^!sort\b/i.test(msg.content)){ sortTurnOrder(); } else if (/^!asort\b/i.test(msg.content)){ sortTurnOrder(sorter_asc); } else if (/^!toggle-turn-order\b/i.test(msg.content)){ let p = getPageForPlayer(msg.playerid); if(false === Campaign().get('initiativepage')){ Campaign().set({ initiativepage: p }); } else { Campaign().set({ initiativepage: false }); } } else if (/^!add-turn\b/i.test(msg.content)){ if(msg.hasOwnProperty('inlinerolls')){ msg.content = _.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(); } let args = msg.content.slice('!add-turn '.length).split(/\s+--/); addCustomTurn(args[0],args[1]||0); } } }); }); Edit: Expanded to have the following commands: !eot This advances to the next turn. !sort This sorts in descending order !asort This sorts in ascending order !toggle-turn-order Shows the turn order if it is hidden, hides it if it is not. !add-turn SOME TEXT --NUMBER This adds a custom turn (no token needed) with whatever the text is.  You can optionally follow it with a number or inline roll: !add-turn Frank the Great --[[1d20]]     Will roll 1d20 and assign that to a turn named "Frank the Great" !add-turn Frank the Great --10     Will assign 10 to a turn named "Frank the Great" !add-turn Frank the Great     Will assign 0 to a turn named "Frank the Great" Technically, you can put whatever you like after the --, so you could use some other turn priority, like A, B, C.  If that's the case though, I'll need to give you a different sort option...
1546715721

Edited 1546715820
Pat S.
Forum Champion
Sheet Author
I would like that as I'm tweaking the game to where it is possible to run it as a PUG without needing anyone being a GM. It only needs to set the turn order to descending and advance the turn order (pass the turn?). No other function is needed. I think the TurnMarker would be overkill for what I need. Oh. Having the ability to open the turn order also would be needed.
1546716025
Pat S.
Forum Champion
Sheet Author
Thank you.
1546716306
The Aaron
Pro
API Scripter
Added !toggle-turn-order to show/hide the turn order.  let me know if you need aught else.
1546716384
The Aaron
Pro
API Scripter
Note that you can still add token turns with the usual: [[1d20 &{tracker}]] or related methods.
1546716460
Pat S.
Forum Champion
Sheet Author
How do you set it up to post the commands into the chat?
1546716991
The Aaron
Pro
API Scripter
I can do that after I give 4 kids a bath. =D
1546718114
Pat S.
Forum Champion
Sheet Author
I think your script is conflicting with the Yatzoid script or it is just kicking up an error. Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. More info... For reference, the error message generated was: TypeError: Campaign.get is not a function TypeError: Campaign.get is not a function at getPageForPlayer (apiscript.js:353:19) at on (apiscript.js:368:13) at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1634: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 Zd.Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) Is what is showing up in the output console.
1546720851
The Aaron
Pro
API Scripter
Whoops. Typo. Should be fixed above now. 
1546723079
Pat S.
Forum Champion
Sheet Author
Thanks. Sorry to be such a pain. The toggle command is not functioning.
1546724022
Pat S.
Forum Champion
Sheet Author
It spit out this error now For reference, the error message generated was:  TypeError: Cannot read property 'get' of undefined TypeError: Cannot read property 'get' of undefined at listPlayers (apiscript.js:185:43) at apiscript.js:301:13 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1634: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 Zd.Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) How do I read this? I'm trying to understand it.
1546733444

Edited 1546733735
Pat S.
Forum Champion
Sheet Author
The games api script has automated it to when the turn order button is clicked for the next player's turn, it posts that info to the chat and when it reaches the end of the players, it says round 2 (or whatever the next round is). For it to become GMless, the core functionality needed to work is that the turn order button needs to work for players, the ability to open and close the turn order window, and setting the order to ascending or descending. In between errors it worked but it did not function like I needed. I'm trying to figure out what I can incorporate into the existing game script so it is all tied together. I want to thank you for all the work you have done so far.
1546734059
The Aaron
Pro
API Scripter
Reading that error, some script has a function called listPlayers which is calling get on something it expects to exists, which doesn't.  My guess is that it assumes anything in the turnorder is associated with a token, and that that token still exists, then blindly tries to use it after attempting to get the token. What other scripts do you have installed?
1546734866
Pat S.
Forum Champion
Sheet Author
The only other script is the Yatzoid script .
1546757968
The Aaron
Pro
API Scripter
Yep, pretty much what I thought. 
1546810841

Edited 1546810867
I'm rather ignorant on the tech details, and assuming you get it to work, if a player is in the turn order, but abandons the game -- perhaps without leaving the game room -- would that stall the advancement once it gets to their turn?  Just something to consider.
1546811566
Pat S.
Forum Champion
Sheet Author
I was hoping with it being just a turn advancement (like the script is now), any player can advance the turn order. This would require everyone use an honor system so they don't advance other players. At this moment, I trying to understand how to take the script and incorporate it into the Yatzoid script so it allows the game's functionality to work properly. Right now the script advances the turn order but at the end, it does not advance the round which means it sits on round 1 without moving to round 2. It also does not open the turn order for it to be used but that can be ignore till later as I can setup the base game with the turn order open.  What it needs to add to the Yatzoid script is the player ability to Open/ Close turn window Advance turn order (in a manner that allows the script to advance the rounds also) Set the turn order to Ascending or Descending. Those are the additional functions that is needed for this game to function without needing anyone to have a GM or co-GM status.
1546814407
The Aaron
Pro
API Scripter
It might be easier to modify their script.  I can take a look at doing that.  Might even be able to send the updates as a pull request.
1546816000
Pat S.
Forum Champion
Sheet Author
Not sure if they want it for production or not. I need it for my specific use which is creating a PUG style game for my community.