
I've started modifying this script to listen for damage rolls from the Pathfinder Second Edition by Roll20 sheet. But right now I'm stumped and hoping someone can spot what I'm overlooking! Two things I'm having trouble figuring out: Only the first inline roll in the Additional Damage field ('roll04') gets pulled, so if the field
contains '[[1d6]] fire, [[1d4]] electricity', only the result of the
first inline roll is added to the total; I haven't been able to figure out how to get the results of all inline rolls in the section and combine them If 'roll04' is empty, as it is for most attacks, the lastBaseDamage and lastCritDamage attributes get filled with 'NaN' instead of a value; I need it to ignore 'roll04' if it's empty so it can still take the value from 'roll02' Here's what I have so far (thank you, The Aaron, for the help!): extractRoll = function(msg){ return _.chain(msg.inlinerolls) .reduce(function(m,v,k){ m['$[['+k+']]']=v.results.total || 0; return m; },{}) .reduce(function(m,v,k){ return m.replace(k,v); },msg.content) .value(); } findRollResult = function(msg, rollname, isString = 0){ let pattern = new RegExp('{{' + rollname + '=(.+?)}}'); let result = 0; if (isString > 0) { msg.content.replace(pattern,(match,rollResult)=>{ result = rollResult; }); } else { msg.content.replace(pattern,(match,rollResult)=>{ result = parseInt(rollResult); }); } return result; } on("chat:message", function(orig_msg) { if (orig_msg.rolltemplate && orig_msg.inlinerolls) { if(/{{roll\d+_type=damage/.test(orig_msg.content)){ let msg = _.clone(orig_msg), damageType, saveType, damagePlus, damageBase, damageHeal, damageCrit, damageHalf, atk1, atk2, critTarget, charName;
damagePlus = damageBase = damageHeal = damageCrit = damageHalf = atk1 = atk2 = 0;
damageType = saveType = charName = ''; msg.content = extractRoll(msg); msg.content.replace(/charname=(.+?)$/,(match,charname)=>{ charName = charname; }); damageType = findRollResult(msg, 'roll02_info', 1); damagePlus = findRollResult(msg, 'roll04'); damageBase = findRollResult(msg, 'roll02') + damagePlus; damageHeal = findRollResult(msg, 'roll02'); damageCrit = damageBase * 2; if (damageType == 'Heal') { sendChat('', '!setattr --silent --name Damage Tracker --lastHeal|' + damageHeal); sendChat('', '!setattr --silent --name Damage Tracker --lastLohdmg|' + damagePlus); sendChat('', '/w gm [Apply Healing](!&#13;&#37;{Damage Tracker|ApplyHeal}) | [Damage Undead](!&#13;&#37;{Damage Tracker|DamageUndead}) | [*Lay on Hands* Damage](!&#13;&#37;{Damage Tracker|DamageLoH})'); } else { sendChat('', '!setattr --silent --name Damage Tracker --lastBaseDamage|' + damageBase); sendChat('', '!setattr --silent --name Damage Tracker --lastCritDamage|' + damageCrit); sendChat('', '/w gm [Hit](!&#13;&#37;{Damage Tracker|ApplyDamage}) | [Critical](!&#13;&#37;{Damage Tracker|ApplyDamageWithCrit})'); } } } }); Here's a sample macro with multiple inline rolls in 'roll04' (near the end, bolded ): @{Shezukoatl|whispertype} &{template:rolls} {{limit_height=@{Shezukoatl|roll_limit_height}}} {{charactername=@{Shezukoatl|character_name} }} {{header=Scythe—Rage}} {{subheader=^{melee_strike}}} {{notes_show=@{Shezukoatl|roll_show_notes} }} {{notes=**DEADLY:** [**+1d10**](`&#47;r 1d10) dmg on crit}} {{roll01_name=^{attack} }} {{roll01=[[1d20cs20cf1 + [ ] 4[@{Shezukoatl|text_modifier}] + (@{Shezukoatl|query_roll_bonus})[@{Shezukoatl|text_bonus}]]]}} {{roll01_type=attack }} {{roll01_info=Deadly d10 | Trip}} {{roll01_critical=1}} {{roll02_name=^{damage}}} {{roll02=[[1D10 + 4[@{Shezukoatl|text_ability_modifier}] + 0[WEAPON SPECIALIZATION] + 0[TEMP] + 0[OTHER] + @{Shezukoatl|query_roll_damage_bonus}[@{Shezukoatl|text_roll_damage_bonus}]]] }} {{roll02_type=damage}} {{roll02_info=slashing}} {{roll04_name=^{damage_additional}}} {{roll04=[[2]] electricity, [[1d3]] fire}} {{roll04_type=damage}} Here's one with no inline rolls in 'roll04' (near the end, bolded ): @{The Amalgam|whispertype} &{template:rolls} {{limit_height=@{The Amalgam|roll_limit_height}}} {{charactername=@{The Amalgam|character_name} }} {{header=claw}} {{subheader=^{melee_strike}}} {{notes_show=@{The Amalgam|roll_show_notes}}} {{notes=}} {{roll01_name=^{attack} }} {{roll01=[[1d20cs20cf1 + (14[@{The Amalgam|text_modifier}]) + (@{The Amalgam|query_roll_bonus})[@{The Amalgam|text_bonus}]]]}} {{roll01_type=attack }} {{roll01_info=}} {{roll01_critical=1}} {{roll02_name=^{damage}}} {{roll02=[[1d8+5 + @{The Amalgam|query_roll_damage_bonus}[@{The Amalgam|text_roll_damage_bonus}]]] }} {{roll02_type=damage}} {{roll02_info=slashing}} {{roll04_name=^{damage_additional}}} {{roll04=}} {{roll04_type=damage}} Original script: <a href="https://app.roll20.net/forum/permalink/7836309/" rel="nofollow">https://app.roll20.net/forum/permalink/7836309/</a>