Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Mostly cause I was bored... auto-damage script for single target attacks [5e OGL]

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);         }     } });
Ohhh me likey, ill have to play with this when i get home from work. Just curious... Does this take into account a targets resistances? (I'm guessing no) To use this do I just install this script (I already use alter bars) and add vs [[ @{target||npc_ac} [ID @{target||token_id}] ]] AC to the weapon desc? If so.. if I have a desc already in place  (ex: a reach weapon) will I have to remove it? Thanks Sky
Dustin C. said: Ohhh me likey, ill have to play with this when i get home from work. Just curious... Does this take into account a targets resistances? (I'm guessing no) To use this do I just install this script (I already use alter bars) and add vs [[ @{target||npc_ac} [ID @{target||token_id}] ]] AC to the weapon desc? If so.. if I have a desc already in place  (ex: a reach weapon) will I have to remove it? Thanks Sky 1.  No, that would require a more extensive script unfortunately. 2. Yes, although I would probably remove the @{target|npc_ac} after I prove that it works as intended. I don't know about you but I don't like telling my players the AC of the things they are fighting. The script looks up the target's AC anyway in the script so it is just there to show the value and has no impact on calculation. 3. No. The script is specifically looking for the value between "[ID" and "]"  but does not care where it is in the description. So long as you have "[ID @{target|token_id}]" in the description, the script should run as intended.
Awesome Kyle thanks. I'm with you I like to keep the AC a secret. 
1490558767

Edited 1490558793
It actually wouldn't be too difficult to add resistance checks to the script. This script was mostly me being bored and trying something out. Maybe someone else would like to expand it. It would actually be better to re-write this script to add a button in chat that players and GM's could click on to apply the damage to a target token. That way it could be used even with saving throws and multi-target spells like fireball.
1490560398

Edited 1490560485
SkyCaptainXIII said: It actually wouldn't be too difficult to add resistance checks to the script. This script was mostly me being bored and trying something out. Maybe someone else would like to expand it. It would actually be better to re-write this script to add a button in chat that players and GM's could click on to apply the damage to a target token. That way it could be used even with saving throws and multi-target spells like fireball. The only problem that I am running in to is how to differentiate between adamantine/nonmagical/silver weapons with regards to the resistance and immunity. Primarily because the weapon damage types are almost always concatenated in the resistance as "bludgeoning, piercing, and slashing from nonmagical weapons" and the like. Also, I've been toying with the idea of recreating how fantasy grounds does targeting; setting up attributes on my PCs that have a list of token IDs that are being targeted. Then when the attack/damage is rolled, it already has the token id to get the AC, apply the damage, and/or perform any necessary saving throws. But it still requires some way of knowing when saves have advantage/disadvantage.
The benefit of listening for a template and pulling the info from that is players don't have to do anything to set up their character sheet. Just fill it out as normal. As for adamantine and magic weapons, that would require making sure that information gets entered correctly on their weapons and that all the variations of resistances and immunities gets searched for on npc sheets.