Skip to content

Instantly share code, notes, and snippets.

@Cazra
Last active December 18, 2015 06:08
Show Gist options
  • Save Cazra/5737453 to your computer and use it in GitHub Desktop.
Save Cazra/5737453 to your computer and use it in GitHub Desktop.
This is a script for a "heal" chat command for the roll20 virtual tabletop API.
// 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 the Dwarf":
// !heal Dave the Dwarf
//
// Healing all characters
// !heal all
on("chat:message", function(msg) {
var cmdName = "!heal ";
var msgTxt = msg.content;
// heals one token specified by name.
var healCharacter = function(targetName) {
sendChat(msg.who, "/em heals " + targetName);
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") !== "") {
target.set("bar3_value", target.get("bar3_max"));
}
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.slice(cmdName.length);
// heal only one character
if(targetName !== "all") {
healCharacter(targetName);
}
// heal all characters
else {
var allCharacters = findObjs({_type: "character"});
for(var x in allCharacters) {
var character = allCharacters[x];
healCharacter(character.get("name"));
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment