
So I'm trying to make a quick little script that will use a combination of other scripts to apply a set of damage attributes to a token. This requires that the selected token is the one that is affected. I spent some time trying to figure out how to grab the specific character ID from a selection, then I tried to simply use the chat output from the API to call other scripts like Custom Status Markers. on("chat:message", function(msg) {
if(msg.type == "api" && msg.content.indexOf("!damage ") !== -1) {
var severity = msg.content.replace("!damage ", "");
var sendingPlayer = getObj('player', msg.playerid);
var d20Result = randomInteger(20);
var message = _.clone(msg),
args,attr,amount,chr,token,who;
log(message);
severity = severity.toLowerCase();
var bodyPart = "";
var bodyTag = "";
switch (d20Result) {
case 1:
case 2:
bodyPart = "h-lleg";
bodyTag = "leg";
break;
case 3:
case 4:
bodyPart = "h-rleg";
bodyTag = "leg";
break;
case 5:
case 6:
bodyPart = "h-rarm";
bodyTag = "arm";
break;
case 7:
case 8:
bodyPart = "h-larm";
bodyTag = "arm";
break;
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
bodyPart = "h-torso";
bodyTag = "torso";
break;
case 19:
case 20:
bodyPart = "h-head";
bodyTag = "head";
break;
default:
bodyPart = "h-other";
bodyTag = "other";
}
var hcolor = "";
var hvalue = 0;
switch (severity) {
case "minor":
hcolor = "none"
hvalue = "1"
break;
case "major":
hcolor = "yellow"
hvalue = "2"
break;
case "mortal":
hcolor = "red"
hvalue = "4"
break;
default:
hcolor = "none"
hvalue = "0"
}
log("bodyPart: "+bodyPart+" hvalue:"+hvalue);
log("bodyTag: "+bodyTag+" hcolor:"+hcolor);
sendChat(msg.who, "!CustomStatusMarkersSetMarker " + bodyTag);
sendChat(msg.who, "!CustomStatusMarkersSetTintForMarker " + bodyTag + " " + hcolor);
sendChat(msg.who, "!setatt @{selected|token_id} " + bodyPart + " " + hvalue);
sendChat(msg.who, severity + " [[" + d20Result + "]] ");
sendChat(msg.who, bodyPart + " [[" + hvalue + "]] " + bodyTag + " " + hcolor);
}
});
The chat messages at the end are the commands I'm attempting to put through chat, however I get "ERROR: Unable to find character selected in chat command." in the API output console when I do. I'm wondering if there is a more direct solution.