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

Add Custom Turn / Player Name

Wondering if there's an accessible value I can use which has the player's name stored (as opposed to the token's or the character's)?  Trying to work on a turn tracker for Gaslands, where a single player may control multiple vehicles, and play cycles through all players in order (with each player choosing an eligible vehicle to activate) until all eligible vehicles have taken a turn.   Since a single player may have more than one vehicle under their control, and since initiative proceeds by player and not by vehicle, I'd love to be able to use a macro calling Add Custom Turn to add the player name to the tracker.  Is there some variable like @{selected|player_name} that I can use?  I tried experimenting with that syntax specifically and came up empty, and have been running searches to see if the question is answered elsewhere but also didn't get any hits. Thanks for your time!
1670341442
The Aaron
Roll20 Production Team
API Scripter
There isn't an attribute like that.  What's the procedure you would see yourself going through to get all the players added to the turn order as custom turns?  I'd be tempted to just make a fake character to represent each player and role a token representing that player into the turn order.  If you wanted to do it as custom turns, you could just have a macro that adds them all: !act [[1d20]] 0 --Bob !act [[1d20]] 0 --Sue !act [[1d20]] 0 --Tim
Thanks for the quick response!  Since I may have different players in each game, my ideal solution would be to streamline setup by having a single macro click that would read all player names currently in the game and add them to the turn tracker.  I was hoping the player name would be an accessible value (maybe something based on how cards from the deck functionality are allocated to players and not tokens), but if that's not supported I can just add them manually at the start of the game.  Appreciate the help!
1670343650
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I'd be willing to bet one of Timmaugh's met scripts could do this...
1670343981
The Aaron
Roll20 Production Team
API Scripter
This will do that: on('ready',()=>{ const getTurnArray = () => ( '' === Campaign().get('turnorder') ? [] : JSON.parse(Campaign().get('turnorder'))); const addCustomTurn = (custom, pr) => setTurnArray([...getTurnArray(), {id:"-1",custom,pr}]); on('chat:message',msg=>{ if('api'===msg.type && /^!apt(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); findObjs({type:'player', _online: true}) .filter(p=>!playerIsGM(p.id)) .map(p=>p.get('_displayname')) .map(n=>addCustomTurn(n,0)) ; } }); });
1670347675

Edited 1670349710
timmaugh
Forum Champion
API Scripter
I just updated Fetch to provide a token-to-player and character-to-player connection. The issue with going from the token/character to the player is that the controlledby property that links them can be a list of players with controlling rights... so while Fetch could always have retrieved that property: @(selected.token_cby_names) ...if that property returned a list instead of a single name, it wouldn't help you in this case. With the new properties (the same properties for token and character), Fetch will take the first entry in the list that doesn't equal "all". Fetch has a property to return the ID of this player entry, and a separate property to return the name of this player entry: @(selected.player)    => id of the player @(selected.player_name) => name of the player ...these properties also work from the token/character name: @(Bob the Hirsute.player) @(Bob the Hirsute.player_name) So you can use this anywhere you need the player name from a token. Of course, Fetch is a script (a metascript, but still a script), meaning you have to use it in a bangsy message (one that starts with a bang: '!'). If your script doesn't output something to chat, you may not actually see Fetch work to retrieve this property, so if you want to test that, you can install Fetch and ZeroFrame and try: !The first player with controlling rights is @(selected.player_name){&simple} To use it in an Add Custom Turn macro, just use the @(selected.player_name) where it is needed. SCRIPT LOCATION: Fetch 2.0.2 is in my personal repo , and will be added to the 1-click merge asap.
Thanks, all! @TheAaron -- macros I can handle reasonably well, but scripting is opaque to me.  How do I actually run the code you posted?  I pasted it into a script ("PopulateTracker.js"), but I'm not sure how to trigger it. @timmaugh -- thanks for the pointer to Fetch 2.02!  I've set that up as well, as I can see how I can utilize that to add my turn phase tracker to the initiative as well.  Was trying to test it with the command you suggested, though, and although the text message output correctly (" The first player with controlling rights is "), it didn't actually output a value for the player_name...  I'm guessing it's user error on my part, but would appreciate if you have any suggestions! Really appreciate the help!
Jeff H. said: @TheAaron -- macros I can handle reasonably well, but scripting is opaque to me.  How do I actually run the code you posted?  I pasted it into a script ("PopulateTracker.js"), but I'm not sure how to trigger it. To add a custom script, on the game Mod (API) Scripts page, click on the 'New Script' button.  You will see a blank console window, where you can cut-and-paste Aaron's code, and give the script a name (E.g. "Add Player Turn"). Then to run the script you simply type '!apt' into the chat window once you're in the game. This line  is the one with the command:     if('api'===msg.type && /^!apt(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ Basically it's checking for three things when a command goes through chat 1. That it is an API command ('api'===msg.type) 2. That it starts with !apt (/^!apt(\b\s|$)/i.test(msg.content)) 3. That the player who sent the message is the GM (playerIsGM(msg.playerid)) Then the rest of the code looks for all active non-GM players and gets their names, then adds them to the Turn Tracker.
1670388122

Edited 1670388725
@Jarren -- I had pasted TheAaron's code into a script, but the !apt was the bit I was missing -- thanks for flagging it!  However, when I entered '!apt' into the chat window, it bounced me the following error on the mod output console: ReferenceError: setTurnArray is not defined ReferenceError: setTurnArray is not defined at addCustomTurn (apiscript.js:10991:41) at apiscript.js:10999:17 at Array.map (<anonymous>) at apiscript.js:10999:10 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:168:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:168:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1750: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) Any suggestions?  Is "setTurnArray" supposed to be "getTurnArray"? Hmm... making that change does allow the script to run without producing errors in the output console, but it doesn't actually seem to be adding anything to the tracker.  (In my game right now, I have my GM account and a test dummy account...  I actually commented out the .filter for the GM because sometimes I play as well)
Looks like it was missing a line: 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) => setTurnArray([...getTurnArray(), {id:"-1",custom,pr}]);      on('chat:message',msg=>{     if('api'===msg.type && /^!apt(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){       let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname');       findObjs({type:'player', _online: true})         .filter(p=>!playerIsGM(p.id))         .map(p=>p.get('_displayname'))         .map(n=>addCustomTurn(n,0))           ;     }   }); }); (Which I figured out from peeking through Aaron's 'Add Custom Turn' script ). I just tested it out quickly with my Dummy Account and it seems to work.
Worked for me as well -- thanks for the help!
1670420040
timmaugh
Forum Champion
API Scripter
Jeff H. said: @timmaugh -- thanks for the pointer to Fetch 2.02!  I've set that up as well, as I can see how I can utilize that to add my turn phase tracker to the initiative as well.  Was trying to test it with the command you suggested, though, and although the text message output correctly (" The first player with controlling rights is "), it didn't actually output a value for the player_name...  I'm guessing it's user error on my part, but would appreciate if you have any suggestions! Ack! I'd made an assumption about the way the data was stored, and my testing didn't reveal my error! I believe I've dug out the problem and fixed it, now. Try version 2.0.3 from my repo (also pending in the 1-click).
That worked;  thanks!
1670427689
timmaugh
Forum Champion
API Scripter
Excellent!