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

sendChat /w gm Visibility

1457708430

Edited 1457708961
I use /w gm for rollbuttons in my charactersheet but also from the API. If I (the GM) do use a rollbutton which sends "/w gm" then I (the GM) but NOT the player sees the whisper. If a player does use the same rollbutton I (the GM) AND the player sees the whisper. If (the GM) click on a button which sends an API command which then calls sendChat with "/w gm" then I (the GM) but NOT the player does see the whisper. If the player does use the same rollbutton I (the GM) do see the whisper but NOT the player. The Charactersheet behaviour is cool - thats what I want.The API behaviour is super strange. How do I fix it that the player does see the same whisper he issued? I do not even know what is happening with the /w gm from the API. How do I ensure that the player who issued the API sendChat is the sender of the API /w gm and sees the message? I tried to simply use msg.who from the person who called the API with a chatcommand but the player still does not see it.
1457709209
The Aaron
Pro
API Scripter
From the API, when you whisper you need to repeat the whisper for each person you want to receive it.   Here's some sample code from MutantYearZero that should illustrate the point (though perhaps not exactly how you'd want to do it, YMMV):     reportBadPushCounts = function(playerid){         var player=getObj('player',playerid);         switch(state.MutantYearZero.config.reportMode){             case 'public':                     sendChat(player.get('displayname'),'/direct '+                         makeErrorMsg('Attempting to push with modified dice counts.')                     );                 break;             case 'gm+player':                 if(!playerIsGM(playerid)){                     sendChat('','/w "'+player.get('displayname')+'" '+                        makeErrorMsg('Do not adjust the number of dice when pushing.')                     );                 }                 /* break; // intentional drop thru */             case 'gm':                 if(playerIsGM(playerid)){                     sendChat('','/w gm '+                         makeErrorMsg('Cannot adjust the number of dice in a Push attempt.')                     );                 } else {                     sendChat('','/w gm '+                         makeErrorMsg(player.get('displayname')+' attempted to Push with an altered number of dice.')                     );                 }                 break;             default:                 break;         }     }, I have a setting that configures how errors are reported.  They can either be Public, GM-only or GM & Player.  In the case where they are reported to the GM and Player, it will it will whisper to the player if they are not a GM, and then whisper to the GM.  (to avoid double whispers to the GM).  
Thank you. Got it. I just expected roll20 simply shows everyone the whisper if they are the person who sent it (which would make sense) but yeah. I just wrote a little function to send to the GM if the sender is not the gm var whisperTo = function(sender,reciever,msg){ sendChat(sender,"/w "+reciever+" "+msg) } var whisperToGM = function(sender,reciever,msg){ if(sender.indexOf("(GM)") == -1){ whisperTo(sender,"gm",msg); } whisperTo(sender,reciever,msg); }
1457711803
The Aaron
Pro
API Scripter
It makes sense if you consider that the person sending the message is the API. (In fact, if you look at a chat message from the API, you'll see API as the player ID).  One thought on your code, it's better to pass the player id and use playerIsGM(id). If the GM is speaking as a character, they won't have "(GM)" in the name. Also, a player can put "(GM)" in their name. (I did a ton of digging into this subject when I wrote isGM(). =D )
Thank you!
1457711892
The Aaron
Pro
API Scripter
Also, you'll want to put " " around the player name to prevent problems with spaces in names. 
1457719265
Lithl
Pro
Sheet Author
API Scripter
The Aaron said: Also, you'll want to put " " around the player name to prevent problems with spaces in names.  And by "problems" he means that "/w The Aaron Hello World" would come out as "Aaron Hello World", although it would probably  still go to The Aaron correctly (the issue would be if there are other players or characters whose names begin with "The ").
1457719546
The Aaron
Pro
API Scripter
In fact, many times I've joined games with older scripts (predating the " ") where the GM is named "The GM"...
1457777179

Edited 1457789856
I get that. I am aware of injections and their problems, I just did not think of that when writing the roll20 scripts as I just began doing my  apprentice-magic . How do I do that properly in Javascript? sendChat(sender,"/w \""+reciever+"\" "+msg) Did break the functionality as I get a script error for msg.who "User not found". Edit: The escaping works, but when a message comes from name (GM) it creates the problems you mentioned. I guess I will have to switch to the IDs and look aht the isGM module :)
1457794488
The Aaron
Pro
API Scripter
The isGM module I only mentioned because I spend a bunch of time in this area while writing it. To check if a player is a GM, the built in function playerIsGM() is sufficient.  If you look at the code I posted above, the second sendChat() is quoting the player's display name. You can also use a full character name in the same fashion. 
1457812094
Lithl
Pro
Sheet Author
API Scripter
Wandler said: I get that. I am aware of injections and their problems, I just did not think of that when writing the roll20 scripts as I just began doing my  apprentice-magic . How do I do that properly in Javascript? sendChat(sender,"/w \""+reciever+"\" "+msg) Did break the functionality as I get a script error for msg.who "User not found". Edit: The escaping works, but when a message comes from name (GM) it creates the problems you mentioned. I guess I will have to switch to the IDs and look aht the isGM module :) This will work best, I think: on('chat:message', function(msg) { var receiver = getObj('player', msg.playerid); // etc... sendChat(sender, '/w "' + receiver.get('displayname') + '" ' + message); }); If receiver isn't the person sending the message that triggers the script, obviously you would use something other than msg.playerid to identify the player.