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

[halp] Not QUITE fixed whisper script.

Yes this is THAT whisper script. You don't have to play in my games, this is a legit API question, please just help with the question, it applies to a fair number of things I want to do eventually, I just found it here with this script. this is the script currently. on('chat:message', function(msg) {     var gmName = "DM"     if(msg.type == 'whisper' && msg.who != 'system') {         var target = getObj({ _id: msg.target }) // this is the line I can't get right.         sendChat('system', '/w " + gmName + "  + msg.who + ' whispers ' + target + ' - ' + msg.content );     }; }); My problem is that target is undefined. been fiddling around with it all night but have yet to actually be able to figure out how to make it send the name of the character that the whisper is being sent to. can get it to send the id via target = msg.target, but just cannot get it to pull the name of that ID. I know its something I'm doing wrong, I just don't know what.  Any help? 
You shouldn't be allowed access to players whispers at all and I will continue to post my disapproval of scripts like this until the API is changed to disallow this access.
1377581095

Edited 1377581468
Lithl
Pro
Sheet Author
API Scripter
var target = msg.target; var player = getObj('player', target); var playerName = player.get('_displayname'); HoneyBadger: I realize you disapprove of this use of the API, but consider the real problem here: given a playerid, how to get the player's displayname. Michael: I'm not certain if msg.target will always give a playerid, or if it will sometimes give a characterid. If you've got a characterid, the solution is similar: var character = getObj('character', characterid); var characterName = character.get('name'); If msg.target does give characterids and playerids both, you'll have to perform some sort of error-checking to figure out which it is. (For example, getObj('player', id) and then check if the result is undefined; if it is, the id should be a character and proceed from there.)
neither one of those seem to work.... course, I'm not really a coder, so yea, working slowly
1377589569

Edited 1377589705
Gauss
Forum Champion
Until the Devs decide to respond to the idea of the API being able to monitor whispers I am going to allow this thread to continue with the proviso that any posts made do not comment on the acceptability of the idea.  In short, if you have a problem with the API monitoring whispers take it up with the Devs and not each other. I will delete posts that insult each other or deal with the acceptability of monitoring whispers.  - Gauss
1377610568

Edited 1377610762
@brian. I've tinkered with it and I'm almost 100% sure it always gives the first controlling player's Id. I started a new thread on finding a way to retrieve this, as the .get() function does not work inside of a chat:message function. I may wind up just creating a namespace and using a variable to pull it. I'll also add a contingency to be safe that getObj(id)._display name != 0 else getObj(Id).controlledby Edit: @honeybadger: this thread is to discuss scripting in API. If you're looking for people's opinions on implementation, possibly you could open a thread in the off-topic forums? Even if its not something to be implemented, I'd still like to figure out the code for the sake of experience, and its difficult when heated opinions lock the thread.
This is the same problem I've had with my chat script - converting the playerID to something legible. Might try playing with Brian's idea when I go back to that script.
1377613241

Edited 1377613631
I'm driving to work and will dedicate time when I arrive, but I just realized if its sent to a char instead of a player its already sent to the GM. I'll see about creating a namespace function to derive it Edit: I think I figured it out. Find obj with I'd, parse string it, split parse on ,. Resplit part [1] on :. Brutish but simple and effective
1377613712

Edited 1377614047
on('chat:message', function(whisper) {     if(whisper.type == 'whisper' && whisper.who != "system") {         var target = findObjs({             _id: whisper.target,         });           log(target.type)         _.each(target, function(char) {             var targetname = char.get("_displayname");             sendChat("system", '/w DM ' + whisper.who + ' whispers ' + targetname + ' - ' + whisper.content );         });         if (whisper.who != "DM (GM)") sendChat("system", whisper.who + ' says something under his breath.' );     }; }); that works for the PLAYER name, But I would like to have to work for the character name and I just can't get it. been working on it since I opened the thread, and its works, but isn't quite what I wanted. EDIT: ignore the second if statment, its not neccessary. just me adding bits while i'm bored figuring out the solution
again, I'll add an if clause to ensure that it's a player ID, not a char ID. But as a GM, you are already forwarded all messages to any characters in your game, so it seems redundant?
I currently forward all messages in my game but that just means I get the whisper, not who the whisper is actually being sent to. 
1377657819

Edited 1377658196
Lithl
Pro
Sheet Author
API Scripter
Michael H. said: on('chat:message', function(whisper) {     if(whisper.type == 'whisper' && whisper.who != "system") {         var target = findObjs({             _id: whisper.target,         });           log(target.type)         _.each(target, function(char) {             var targetname = char.get("_displayname");             sendChat("system", '/w DM ' + whisper.who + ' whispers ' + targetname + ' - ' + whisper.content );         });         if (whisper.who != "DM (GM)") sendChat("system", whisper.who + ' says something under his breath.' );     }; }); that works for the PLAYER name, But I would like to have to work for the character name and I just can't get it. been working on it since I opened the thread, and its works, but isn't quite what I wanted. EDIT: ignore the second if statment, its not neccessary. just me adding bits while i'm bored figuring out the solution It appears that msg.target will never return a characterid. The value will be one of: The string "gm", if the whisper is sent to the gm (/w gm text, not /w gmPlayerName text) or if it is sent to a character with no controlling players. The player's ID, if the whisper is sent to a player by name or if it is sent to a character with a single controlling player. A comma-delimited list of player IDs, if the whisper is sent to a character with multiple controlling players. In that case, you're not going to be able to get this script to report on characters. If each player in the campaign has control of a single character, you could search the list of characters for which one is controlled by the playerid, but that solution falls short if anyone has multiple characters. EDIT: The message object has another undocumented property: target_name ! target_name will contain the name of the whisper target, unless the target is a character with no controlling players (in which case target_name is "GM", just like if you use /w gm text)
just realised I had not thanked you for your input there - Soon as I saw that I started putting together all my scripts that used it :P So in case its not obvious, Thank You!!!!! So much better now that I spend less than a quarter of the time logging my games!