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

Who is the current player performing an action?

1711157445

Edited 1711157795
GM
Pro
So I’m going to refactor some really big and complex scripts for a SWN campaign that controls ship combat. I’ll need to know which player is selecting a token, so I can pull character attributes like wisdom bonus, etc.   Basic overview:   There is a TV on the table that acts as a HUD during ship combat. I use a dummy player account called “The Ship” here.   There are 5 departments on the ship (engineering, gunnery, etc), and all those dept actions are on a single “Console” screen.  A macro I use sends The Ship to the HUD page (on the tv), and each player to “Console” on their own tablets/laptops. This is needed as the players all have a macro allowing them to go to other screens like “system nav” or “landing page” during gameplay. So, I have this “battle stations macro” to herd cats when ship combat starts.  A player selects an action on their device, and clicks a “confirm” macro.  the macro queries for bonuses, and sends that (and the action as an indexOf) to the api to resolve the action.  Dials and indicators are changed on both The HUD and Console.  It all works, but I want the api to know which player has selected an action so I can automatically query for relevant attributes/bonuses/etc. I want only one modifier query to appear, as I might give one for circumstances like debuffs.  Of course, if I can figure out “current player” here, it opens a lot of doors elsewhere too.  As I’m still fairly new to JS and scripting, I won’t be upset with some code snippets, but beggars can’t be choosers.  Thanks! This forum has been amazing. Special thanks to TheAaron, Timmaugh, and others. My campaign has been a resounding success in part because of you. 
So I know that ScriptCards sets some ScriptCards variables about the sending player so I figured that there must be a way that ScriptCards is doing this. Looks like this would be the relevant bit of code  here . if (msg.playerid) {     var sendingPlayer = getObj("player", msg.playerid);     if (sendingPlayer) {     // YOUR CODE HERE     } } I'm not super versed in JS but I knew that Kurt J must've done something to set those string variables in ScriptCards. Hopefully that code snippet helps you.
Holy smokes. That’s it! Thanks, Joshua N!
1711371916
timmaugh
Pro
API Scripter
Hey, GM... Joshua gave you the correct property. Two things... When a script calls another script (for instance, ScriptCards sending a command that another script should catch), the playerid will not be an actual player's id... it will instead be "api," so make sure you account for situations where you won't have a playerid at all. SelectManager can restore that for people to bridge the gap, but not everyone will have that. More the pity. Second, for help with developing/writing/altering a script, I would suggest a couple of my scripts: ScriptInfo - can help disambiguate line numbers in errors Inspector - can help you quickly understand the available data attached to an object (and flow from one object to another, related object)
Thanks, Timmaugh. I was worried about the api “who’s this” issue, and you’ve caught it. I hope to get this worked up over the ext few days, since we play on the 10th.