I got tired of players forgetting to 'talk as' characters for my scripts that needed the character name to do anything such as adding XP, adjusting stats, reading attributes, etc. So I made this so regardless of who they are talking as in the dropdown it converts to the characters name, and finds its sheet, maybe someone else can use it.
Only limitation, it assumes everyone only has control of one character sheet, it will pull the first one that it finds they have edit rights over.
cWho = the character object itself to use wherever you need to pull info from it.
It also:
Checks to see if a GM is doing commands as a (GM), and if so ignore looking up a character.
It changes msg.who to the characters name if your using it in your script.
Example as such:
Only limitation, it assumes everyone only has control of one character sheet, it will pull the first one that it finds they have edit rights over.
cWho = the character object itself to use wherever you need to pull info from it.
It also:
Checks to see if a GM is doing commands as a (GM), and if so ignore looking up a character.
It changes msg.who to the characters name if your using it in your script.
Example as such:
on('chat:message', function (msg_orig) { var msg = _.clone(msg_orig); if (msg.type != "api") return; var command = msg.content.split(" ", 1); //--check if character or player var cWho = findObjs({_type: 'character',name: msg.who})[0]; if (cWho == undefined && msg.who.indexOf("(GM)") == -1) { cWho = RollRight(msg.playerid); msg.who = cWho.get("name"); } //-- if (command == "!something") { //do stuff here } if (command == "!somethingelse") { //do stuff here } });and this is the function that it uses
//--convert to character name function RollRight (whoPC) { var character = findObjs({type: 'character',controlledby: whoPC})[0]; return character; }Just toss that somewhere and call it in any scripts using RollRight(msg.playerid); you have that require the person to talk as their character.