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

Way to get character linked to player that sent chat

June 30 (10 years ago)

Edited June 30 (10 years ago)
DXWarlock
Sheet Author
API Scripter
My players constantly keep forgetting to select "Character name" as the chat option at the bottom when doing API commands I have. Many of them use the attributes and such from the character sheet and looks at who is sending it to find the character.

I have a failsafe that checks and when they do it sends msg.who roll as your character name! to the chat. The issue comes up when they, say, do an attack roll and roll a good roll on the dice but rolled as a 'player', so I have to stop and manually figure out the whole script result I would have had.

Basically say Bob has a character named AlTheMighty..so he would have both "Bob" and "AlTheMighty" as drop down chat options..he sends it as Bob by mistake..how do I convert that to AlTheMighty by assuming "ok he has only one character, we know that..go find it and use it instead"

I was assuming it would have to do with Player speakingas in the API, but either Im wrong on how to interchange them, or using it wrong to start with :)
June 30 (10 years ago)
Lithl
Pro
Sheet Author
API Scripter

If you can assume each player only has a single character (and that each character is only controlled by a single player), finding that character is fairly simple:

on('chat:message', function(msg) {
var character = findObjs({
type: 'character',
controlledby: msg.playerid
})[0];

if (!character)
{
// Something went wrong!
}
});
June 30 (10 years ago)

Edited June 30 (10 years ago)
DXWarlock
Sheet Author
API Scripter
Well, don't I feel retarded..
Ive been trying to manipulate "speakingas", and fiddling with finding character with msg.who not msg.playerid

With that I can just check, if it does exist make msg.who = character.get("name");
once again, Brian helps my 3am coding brain farts :)
June 30 (10 years ago)

Edited June 30 (10 years ago)
Always will be a problem, BobTheBad/FairyPrincessFifi/CharlieSheep@Rehab.bomb issue confounds me all of the time, I have two players who's Central U.S. accents also sound the same on voice chat and have 3 or 30 different Id's accross email, R-20, skype etc. We need to implant chips in our gamers...
July 01 (10 years ago)
Is there any way to do something like this if there are multiple players per character. We are running a henshin heroes campaign and the players each have two character sheets, one as their 'normal' self, and one for their transformed self. This means each player is 'Player X', 'Character X', and 'Guardian X' for chat purposes.
July 01 (10 years ago)
Lithl
Pro
Sheet Author
API Scripter
Sure, but you would need some way to determine what character is speaking beyond just the player that sent the message.