Mostly made this script cause I was bored and curious about if it could be done, it will listen for 5e OGL templates in chat and apply damage automatically based on the target's AC. Just need to add [ID @{target||token_id}] to any roll in the attack, such as the damage roll or something. Or you could use... vs [[ @{target||npc_ac} [ID @{target||token_id}] ]] AC ... in the Description field of the attack. I did get it working for saving throws, but removed it due to the fact that the script wouldn't have any way of knowing if the target had advantage, disadvantage, and what not on the save. It also requires my AlterBars script here on the forums, but could easily be modified to silently apply the damage in the background. Another method for this would be to capture the attack information and throw an API command button into chat that the attacking player could use to apply damage to the target and this method would not require players to alter their attacks and could capture save DC info as well. on("chat:message", function(msg) {
if (msg.rolltemplate) {
var TokenID = "";
_.each(msg.inlinerolls, function(roll) {
if (roll.expression.match(/\[ID.*?\]/g) != null) TokenID = roll.expression.match(/\[ID.*?\]/g)[0].split("ID")[1].split("]")[0].trim();
});
if (TokenID == "") return;
var Token = getObj("graphic", TokenID);
var CharID = Token.get("represents");
if (CharID == "") return;
var Advantage = (msg.content.match(/({{advantage=)\d/g) != null) ? 1 : 0;
var Normal = (msg.content.match(/({{normal=)\d/g) != null) ? 1 : 0;
var Disadvantage = (msg.content.match(/({{disadvantage=)\d/g) != null) ? 1 : 0;
var Atk1 = parseInt(msg.content.match(/({{r1=\$\[\[\d+\]\]}})/g)[0].split("[[")[1].split("]]")[0]);
var Atk2 = parseInt(msg.content.match(/({{r2=\$\[\[\d+\]\]}})/g)[0].split("[[")[1].split("]]")[0]);
var Dmg1 = parseInt(msg.content.match(/({{dmg1=\$\[\[\d+\]\]}})/g)[0].split("[[")[1].split("]]")[0]);
var Dmg2 = parseInt(msg.content.match(/({{dmg2=\$\[\[\d+\]\]}})/g)[0].split("[[")[1].split("]]")[0]);
var Crit1 = parseInt(msg.content.match(/({{crit1=\$\[\[\d+\]\]}})/g)[0].split("[[")[1].split("]]")[0]);
var Crit2 = parseInt(msg.content.match(/({{crit2=\$\[\[\d+\]\]}})/g)[0].split("[[")[1].split("]]")[0]);
var Atk1Base = (msg.inlinerolls[Atk1].results.rolls[0].dice != 0) ? parseInt(msg.inlinerolls[Atk1].results.rolls[0].results[0].v) : 0;
var Atk1Total = (msg.inlinerolls[Atk1].results.rolls[0].dice != 0) ? parseInt(msg.inlinerolls[Atk1].results.total) : 0;
var Atk1Crit = (msg.inlinerolls[Atk1].results.rolls[0].mods != null) ? parseInt(msg.inlinerolls[Atk1].results.rolls[0].mods.customCrit[0].point) : 20;
var Atk2Base = (msg.inlinerolls[Atk2].results.rolls[0].dice != 0) ? parseInt(msg.inlinerolls[Atk2].results.rolls[0].results[0].v) : 0;
var Atk2Total = (msg.inlinerolls[Atk2].results.rolls[0].dice != 0) ? parseInt(msg.inlinerolls[Atk2].results.total) : 0;
var Atk2Crit = (msg.inlinerolls[Atk2].results.rolls[0].mods != null) ? parseInt(msg.inlinerolls[Atk2].results.rolls[0].mods.customCrit[0].point) : 20;
var Dmg1Total = parseInt(msg.inlinerolls[Dmg1].results.total);
var Dmg2Total = parseInt(msg.inlinerolls[Dmg2].results.total);
var Dmg1Type = (msg.content.match(/{{dmg1type=\w+/g) != null) ? msg.content.match(/{{dmg1type=\w+/g)[0].split("=")[1] : "";
var Dmg2Type = (msg.content.match(/{{dmg2type=\w+/g) != null) ? msg.content.match(/{{dmg2type=\w+/g)[0].split("=")[1] : "";
var Crit1Dmg = parseInt(msg.inlinerolls[Crit1].results.total);
var Crit2Dmg = parseInt(msg.inlinerolls[Crit2].results.total);
var Damage = 0;
if (Normal === 1 || Advantage === 1 || Disadvantage === 1) {
// NORMAL
var AtkBase = Atk1Base;
var AtkTotal = Atk1Total;
var AtkCrit = Atk1Crit;
// ADVANTAGE
if (Advantage === 1 && Atk2Total > Atk1Total) {
AtkBase = Atk2Base;
AtkTotal = Atk2Total;
AtkCrit = Atk2Crit;
}
// DISADVANTAGE
if (Disadvantage === 1 && Atk2Total < Atk1Total) {
AtkBase = Atk2Base;
AtkTotal = Atk2Total;
AtkCrit = Atk2Crit;
}
// RESOLVE ATTACK ROLLS
var TokenAC = (getAttrByName(CharID, "npc") == 1) ? parseInt(getAttrByName(CharID, "npc_ac")) : parseInt(getAttrByName(CharID, "ac"));
if (AtkBase === 1) return;
Damage = (AtkTotal >= TokenAC) ? Dmg1Total + Dmg2Total : 0;
Damage = (AtkBase >= AtkCrit) ? Damage + Crit1Dmg + Crit2Dmg : Damage;
if (Damage > 0) setTimeout(function() { sendChat("", "!alter --target|" + TokenID + " --bar|1 --amount|-" + Damage) }, 1500);
}
}
});