// This is a "heal" chat command for the roll20 virtual tabletop API.
// It can be used to heal all 3 bars for a token by name,
// or you can have it heal the tokens for all the characters in your campaign's journal.
// E.g:
// Healing one character named "Dave" (Only Tokens with only a first name can be used. You can still have the full name in the journal.)
// !heal Dave X (Where x is the amount healed. Putting no value for X resets health to max value)
//
// Healing all characters no longer works as perscribed. Working on finding bug.
// !heal all
on("chat:message", function(msg) {
var cmdName = "!heal ";
var msgTxt = msg.content;
// heals one token specified by name.
var healCharacter = function(targetName, healNumber) {
sendChat(msg.who, "/em heals " + targetName);
//The above line (which sends the emote to chat) can be disabled with a simple in line comment notation ( // ), like this line.
var targetsMatched = findObjs({_type: "graphic", name: targetName});
if(targetsMatched.length === 0) {
sendChat(msg.who, "target " + targetName + " not found.");
}
// heal the character token on all pages.
for(var x in targetsMatched) {
var target = targetsMatched[x];
/* if(target.get("bar1_value") !== "") {
target.set("bar1_value", target.get("bar1_max"));
}
//if(target.get("bar2_value") !== "") {
target.set("bar2_value", target.get("bar2_max"));
} */
if(target.get("bar3_value") !== "") {
if(healNumber == undefined) {
target.set("bar3_value", target.get("bar3_max"));
} else {
target.set("bar3_value", Number(target.get("bar3_value")) + Number(healNumber));
}
}
target.set({
status_greenmarker: false,
status_bluemarker: false,
status_redmarker: false,
status_dead: false
});
}
};
// Check for our heal command in the chat message.
if(msg.type == "api" && msgTxt.indexOf(cmdName) !== -1) {
var targetName = msgTxt.split(" ")[1];
var healNumber = msgTxt.split(" ")[2];
// heal only one character
if(targetName !== "all") {
healCharacter(targetName, healNumber);
}
// heal all characters
else {
var allCharacters = findObjs({_type: "character"});
for(var x in allCharacters) {
var character = allCharacters[x];
healCharacter(character.get("name"), healNumber);
}
}
}
});
// It can be used to heal all 3 bars for a token by name,
// or you can have it heal the tokens for all the characters in your campaign's journal.
// E.g:
// Healing one character named "Dave" (Only Tokens with only a first name can be used. You can still have the full name in the journal.)
// !heal Dave X (Where x is the amount healed. Putting no value for X resets health to max value)
//
// Healing all characters no longer works as perscribed. Working on finding bug.
// !heal all
on("chat:message", function(msg) {
var cmdName = "!heal ";
var msgTxt = msg.content;
// heals one token specified by name.
var healCharacter = function(targetName, healNumber) {
sendChat(msg.who, "/em heals " + targetName);
//The above line (which sends the emote to chat) can be disabled with a simple in line comment notation ( // ), like this line.
var targetsMatched = findObjs({_type: "graphic", name: targetName});
if(targetsMatched.length === 0) {
sendChat(msg.who, "target " + targetName + " not found.");
}
// heal the character token on all pages.
for(var x in targetsMatched) {
var target = targetsMatched[x];
/* if(target.get("bar1_value") !== "") {
target.set("bar1_value", target.get("bar1_max"));
}
//if(target.get("bar2_value") !== "") {
target.set("bar2_value", target.get("bar2_max"));
} */
if(target.get("bar3_value") !== "") {
if(healNumber == undefined) {
target.set("bar3_value", target.get("bar3_max"));
} else {
target.set("bar3_value", Number(target.get("bar3_value")) + Number(healNumber));
}
}
target.set({
status_greenmarker: false,
status_bluemarker: false,
status_redmarker: false,
status_dead: false
});
}
};
// Check for our heal command in the chat message.
if(msg.type == "api" && msgTxt.indexOf(cmdName) !== -1) {
var targetName = msgTxt.split(" ")[1];
var healNumber = msgTxt.split(" ")[2];
// heal only one character
if(targetName !== "all") {
healCharacter(targetName, healNumber);
}
// heal all characters
else {
var allCharacters = findObjs({_type: "character"});
for(var x in allCharacters) {
var character = allCharacters[x];
healCharacter(character.get("name"), healNumber);
}
}
}
});
No comments:
Post a Comment