
Hey Guys, Here's a script that you can use to change the 'As' pull down list at the bottom of your chat window to the represented character of the currently selected token. I intended this to be used as a macro for NPCs that would be in the token toolbar. I was getting a bit annoyed by having to find the right character in my long list of characters available in the pull down list, so I came up with this solution for a quick button to push in the token toolbar. Import code below to your campaign Set up a macro (ability) in the desired character with the following command: !SSASC Ensure the 'Show as Token Action' button is checked. Repeat steps 2 & 3 for each character. Ensure your tokens have their 'Represents' field filled in. Select one of the tokens. Click macro button on toolbar before doing other actions like attacking or saving throws. Viola! No more will the DM 'Bite' and 'Claw' in the chat room, but rather the monsters will do the biting and clawing. There are limitations, as noted in the beginning of the comments, so please read them. Enjoy! //SetSpeakAsSelectedCharacter by Christopher Craig v1.0 20200425
//
//Program contract:
//Requirement 1: Select a single token (graphics object) with the "represents" element populated with a valid character ID.
//
//Output: This script will change the (speaking) "As" to the represened character.
//
//Limitations: Even though this script was designed to be called from macros, DO NOT include this command in a macro with other commands in it utilizing the
// game chat. Have this command in it's own macro and assigned to it's own token toolbar button and wait until you see the 'As' field change
// before activating other macros that use chat. This is because all commands in macros run at the same time, asynchronously. In other words,
// even if this is the first command in a macro, the macro will start this script first, but will not wait for it to finish before executing
// the next command. This will result in the first one or two chat messages sent from following commands being spoken as the previously
// selected value in the 'As' field.
on("ready",function() {
log("SSASC checkpoint 1: Sandbox Ready");
on("chat:message",function(msg){
log("SSASC checkpoint 2: Chat message detected");
if(msg.type=="api" && (msg.content.indexOf("!SetSpeakAsSelectedCharacter")==0||msg.content.indexOf("!SSASC")==0)) {
log("SSASC checkpoint 3: SSASC API command detected");
var objPlayer = getObj("player",msg.playerid);
var strSSASCPlayerID = msg.playerid;
var arrSelected = msg.selected;
if (arrSelected===undefined) {
log("SSASC checkpoint 4: No token not selected");
sendChat("SSASC","/w "+msg.who+" Nothing selected. (SELECT exactly one character TOKEN and try the macro again.)");
return;
};
if (arrSelected.length!=1) {
log("SSASC checkpoint 5: "+arrSelected.length+" tokens selected");
sendChat("SSASC","/w "+msg.who+" "+arrSelected.length+" tokens selected. (Select EXACTLY ONE character token and try the macro again.)");
return;
};
log("SSASC checkpoint 6: Token selection detected");
var objSelectedToken = getObj("graphic",arrSelected[0]._id);
var strCharacterID = objSelectedToken.get("represents");
if (strCharacterID===undefined||strCharacterID==="") {
log("SSASC checkpoint 7: Represented character not detected");
sendChat("SSASC","/w "+msg.who+" Represented character not found. (Select a token that represents a character and try the macro again.)");
return;
};
log("SSASC checkpoint 8: Selected token character ID: "+strCharacterID);
strCharacterID="character|"+strCharacterID;
log("SSASC checkpoint 9: Amended selected token character ID: "+strCharacterID);
objPlayer.set("speakingas", strCharacterID);
log("SSASC checkpoint 99: Speaking As Updated - Success!!");
};
});
}); I apologize for the log statements being out of format, but it helps me to quickly find the right spot in my code when trouble-shooting and auditing.