This API script will add or subtract from a token's bars. Just define Bar#Keys and Bar#Names variables and you're good to go. The script has been updated to try and prevent errors by players putting in a plus or minus sign and healing the target they wanted to damage or damaging a target they wanted to heal, though it is still very possible. You can use the macros below to help limit those problems as well, but it requires two macros for each bar you want to be able to alter instead of just one. Add to Bar of Selected Token: !alter @{selected|token_id} 1 +?{Add to Bar|0} Subtract from Bar of Selected Token: !alter @{selected|token_id} 1 -?{Subtract from Bar|0} Add to Bar of Target Token: !alter @{target||token_id} 1 +?{Add to Bar|0} Subtract from Bar of Target Token: !alter @{target||token_id} 1 -?{Subtract from Bar|0} Updates November 9th, 2014 12:01 am eastern (ver 1.1) ~ Added option to hide chat announcement and send to GM instead and option to always send to GM in addition to sending to the chat window. To hide chat announcement, simply add any kind of text at the end of the macro. You CANNOT have any spaces in the value however. So you cannot do 1d8 + 4. It has to be something like 1d8+4 unless you're using a roll query like ?{Healed for|0}. Spaces will work in queries. November 8th, 2014 11:30 pm eastern (ver 1.0) ~ Cleaned up the script and made it smaller. Script will no longer edit the msg object and will not break other scripts that rely on the msg object. Old Update ~ Added variables to define the tag used to tell the script which bar to subtract from. These are Bar1Key, Bar2Key, and Bar3Key. In the script below, they are h, f, and m for (H)ealth, (F)atigue, and (M)ana. Old Update ~ Added a variable to define the names of the three bars. You must use this format: ["Bar1Name", "Bar2Name", "Bar3Name"] or else it will not work. These are only used if you set ANNOUNCE_CHANGE to true. Old Update ~ Added ANNOUNCE_CHANGE to send a message to the chat window to announce which token gained or lost points from which bar. Old Update ~ Added PREVENT_OVERMAX to prevent a bar from gaining enough points to go over its max value. If a max value is not set for a bar, this variable has no effect. Old Update ~ Added STOP_AT_ZERO to prevent the script from dropping the current value of the bar being altered to a value below zero. Old Update ~ Added an inline roll like look to the script. Currently not optional, but I will get to that. It has a tooltip so the GM can see the roll or value entered by the player but does NOT function like the full regular tooltip with highlighted numbers and such. That would make this script very much more complicated. // VERSION INFO
var AlterBars_Version = 1.1;
// FUNCTION DECLARATION
var AlterScript = AlterScript || {};
on("chat:message", function (msg) {
// Exit if not an api command...
if (msg.type != "api") return;
// Get the api command...
var command = msg.content.split(" ", 1)[0];
if (command === "!alter") AlterScript.Process(msg);
});
AlterScript.Process = function(msg, who) {
// USER CONFIG
// BAR CONFIGURATION - These are used to identify which bar to adjust. You can
// also use any lowercase letters as well such as 'h' for hit points/health.
var Bar1Key = "1";
var Bar2Key = "2";
var Bar3Key = "3";
// BAR NAMES - These names are used if ANNOUNCE_CHANGE is set to true. The
// format of the annoucement is: Name gained/lost # BarName.
var BarNames = ["hit points", "hit points", "hit points"];
// PREVENT OVERMAX - Set this variable to true to prevent the current value of
// the bar from being greater than its max value. If there is no max value set,
// it will not stop the current bar value from increasing.
var PREVENT_OVERMAX = true;
// ANNOUNCE CHANGE IN CHAT - Set to true to send a message to the chat window
// showing which token gained or lost points and how much.
var ANNOUNCE_CHANGE = true;
// SEND TO GM - Set to true to send the results to the GM. This will also trigger
// if a hidden change is sent.
var ALERT_GM = false;
// STOP AT ZERO - Prevents the current value of the bar from dropping below zero.
var STOP_AT_ZERO = true;
// END USER CONFIG
// Get and/or create variables...
var n = msg.content.split(" ");
var who = msg.who;
var Target = getObj("graphic", n[1]);
var Bar = 0;
Bar = (n[2].toLowerCase().toString() == Bar1Key) ? 1 : 0;
Bar = (n[2].toLowerCase().toString() == Bar2Key) ? 2 : Bar;
Bar = (n[2].toLowerCase().toString() == Bar3Key) ? 3 : Bar;
if (Bar === 0) {
sendChat("ERROR", "/w " + who.replace(" (GM)", "") + " That is not a valid bar.");
return;
}
var AlterValue = n[3];
var CurrentValue = parseInt(Target.get("bar" + Bar + "_value"));
var MaxValue = parseInt(Target.get("bar" + Bar + "_max"));
var NoAnnounce = n[4];
// Check for a + or - sign...
var Operand1 = AlterValue.charAt(0);
var Operand2 = AlterValue.charAt(1);
if (Operand2 === "+" || Operand2 === "-") AlterValue = AlterValue.substring(2);
else if (Operand1 === "+" || Operand1 === "-") AlterValue = AlterValue.substring(1);
// Save the value for the tooltip...
var Expression = AlterValue;
// Define CSS...
var AddStyle = "display: inline-block; text-align: center; min-width: 1.75em; font-size: 1em; font-weight: bold; color:#040; background-color: #8C8; border: 1px solid #040; padding: -1px 2px; border-radius: 3px;";
var MinusStyle = "display: inline-block; text-align: center; min-width: 1.75em; font-size: 1em; font-weight: bold; color:#600; background-color: #FAA; border: 1px solid #600; padding: -1px 2px; border-radius: 3px;";
// Main process...
sendChat("", "/r " + AlterValue, function(outs) {
AlterValue = parseInt(JSON.parse(outs[0].content).total);
var Tooltip = "Rolling " + Expression + " = " + AlterValue + "' class='a inlinerollresult showtip tipsy-n'";
if (Operand1 != "-") {
// Add to bar...
if (PREVENT_OVERMAX) AlterValue = (AlterValue + CurrentValue > MaxValue) ? MaxValue - CurrentValue : AlterValue;
if (ANNOUNCE_CHANGE && NoAnnounce == undefined) sendChat("DiceBot", Target.get("name") + " gained <span title='" + Tooltip + "' style='" + AddStyle + "'>" + AlterValue + "</span> " + BarNames[Bar-1] + ".");
if (ALERT_GM || NoAnnounce != undefined) sendChat(who, "/w GM " + Target.get("name") + " gained <span title='" + Tooltip + "' style='" + AddStyle + "'>" + AlterValue + "</span> " + BarNames[Bar-1] + ".");
Target.set("bar" + Bar + "_value", CurrentValue += AlterValue);
} else {
// Subtract from bar...
if (STOP_AT_ZERO && (CurrentValue - AlterValue < 0)) AlterValue = CurrentValue;
if (ANNOUNCE_CHANGE && NoAnnounce == undefined) sendChat("DiceBot", Target.get("name") + " lost <span title='" + Tooltip + "' style='" + MinusStyle + "'>" + AlterValue + "</span> " + BarNames[Bar-1] + ".");
if (ALERT_GM || NoAnnounce != undefined) sendChat(who, "/w GM " + Target.get("name") + " lost <span title='" + Tooltip + "' style='" + MinusStyle + "'>" + AlterValue + "</span> " + BarNames[Bar-1] + ".");
Target.set("bar" + Bar + "_value", CurrentValue -= AlterValue);
}
});
};