Thanks for the tips. I've made a few changes to it so that it will be easier for me to quickly create a set of attack macros for each token.
I only made a few changes, so I saw no reason to overly expand the page.
Code: Select all
<!-- Rogue Composite Longbow Sneak Attack -->
<!-- Get needed data. Replace Dexterity with Strength and vice versa in the calculations when necessary.-->
[H: BAB = getProperty("BaseAttackBonus")]
[H: strengthBonus = getProperty("StrengthBonus")]
[H: dexterityBonus = getProperty("DexterityBonus")]
[H: name = getProperty("CharacterName")]
<!-- Make extraDiceDamage = 0 when applying to a rogue, except for "Sneak Attack" macro -->
[H: extraDiceDamage = getProperty("ExtraDice")]
<!-- Ask player for input -->
[h: input("MiscAttackBonus","MiscDamageBonus")]
[H: miscAttackBonus = MiscAttackBonus]
[H: miscDamageBonus = MiscDamageBonus]
<!-- Weapon information. Adjust for each character/attack macro -->
[H: dieRoll = 1d20]
[H: critRoll = 1d20]
[H: fumble = 1]
[H: critThreat = 20]
[H: weaponBaseDamage = "1d8"]
<!-- This could be due to feats, magic and special abilities -->
[H: weaponBaseAttackMod = 2]
[H: weaponDamageBonus = 1]
[H: critMultiplier = 3]
<!-- Process data -->
<!-- ATTACK -->
[H: attackMod = BAB + dexterityBonus + miscAttackBonus + weaponBaseAttackMod]
[H: attackResult = dieRoll + attackMod]
[H: critResult = critRoll + attackMod]
[H: isFumble = if(dieRoll == fumble,1,0)]
[H: isCritThreat = if(dieRoll >= critThreat,1,0)]
<!-- make a tooltip for the attack with attack details -->
[H: output.tip = strformat("<html>
<table><tr><td colspan=2><b><center>ATTACK</center></b></td></tr>
<tr><td>Attack Roll:</td><td>%{dieRoll}</td></tr>
<tr><td>Crit Threat Roll:</td><td>%{critRoll}</td></tr>
<tr><td>BAB:</td><td>%{BAB}</td></tr>
<tr><td>Dexterity Bonus:</td><td>%{dexterityBonus}</td></tr>
<tr><td>Misc Attack Bonus:</td><td>%{miscAttackBonus}</td></tr>
<tr><td>Weapon Attack Mod:</td><td>%{weaponBaseAttackMod}</td></tr>
<tr><td><b>Attack Result:</b></td><td><b>%{attackResult}</b></td></tr>
</table></html>")]
<!-- change output depending on character and weapon, to better describe action -->
[H: output.attack = strformat("%{name} fires his longbow, getting sneak attack, and hitting an AC of %{attackResult}%s",
if(isFumble," (Fumble)",if(isCritThreat,strformat(" (Crit: %{critResult})"),"")))]
[H: output = strformat('<span title="%{output.tip}">%{output.attack}</span>')]
<!-- DAMAGE. Remove strength bonus for most ranged weapons in damage calculation and tooptip -->
[H, if(! isFumble), code: {
[H: weaponBaseDamageResult = eval(weaponBaseDamage)]
[H: damage = weaponBaseDamageResult + strengthBonus + miscDamageBonus + weaponDamageBonus + extraDiceDamage]
[H: critDamage = damage]
[H: critDamageRolls = weaponBaseDamageResult]
<!-- I put loop here because the crit damage is rolled separately rather than just multiplied -->
[H, C(critMultiplier-1), code: {
[H: critBaseDamage = eval(weaponBaseDamage)]
[H: critDamageRolls = listAppend(critDamageRolls,critBaseDamage)]
[H: critDamage = critDamage + critBaseDamage + strengthBonus + miscDamageBonus + weaponDamageBonus]
}]
<!-- make a tooltip for the damage with damage details -->
[H, if(isCritThreat): critRollString = strformat("<tr><td>Crit Damage Roll(s):</td><td>%{critDamageRolls}</td></tr>"); critRollString = ""]
[H, if(isCritThreat): critTotalString = strformat('
<tr style="color:red"><td><b>Crit Damage Total:</b></td><td><b>%{critDamage}</b></td></tr>
<tr><td style="font-size:8px" colspan=2><i><b>note:</b> critical damage total is the damage total with successful critical.</i></td></tr>');
critTotalString = ""]
[H: output.tip = strformat("<html>
<table><tr><td colspan=2><b><center>DAMAGE</center></b></td></tr>
<tr><td>Weapon Base Damage:</td><td>%{weaponBaseDamage} = %{weaponBaseDamageResult}</td></tr>
%{critRollString}
<tr><td>Strength Damage:</td><td>%{strengthBonus}</td></tr>
<tr><td>Misc Damage Bonus:</td><td>%{miscDamageBonus}</td></tr>
<tr><td>Extra Dice Damage:</td><td>%{extraDiceDamage}</td></tr>
<tr><td>Weapon Damage Bonus:</td><td>%{weaponDamageBonus}</td></tr>
<tr><td><b>Damage Total:</b></td><td><b>%{damage}</b></td></tr>
%{critTotalString}
</table></html>")]
[H: output.damage = strformat('DAMAGE: %{damage}%s',if(isCritThreat,strformat(" (%{critDamage})"),""))]
[H: output = output + "<br>" + strformat('<span title="%{output.tip}" style="color:red">%{output.damage}</span>')]
};{}]
<!-- OUTPUT -->
[R: output]
Key changes:
- added the suggested input(...) function.
- Added weaponDamageBonus to go along with the weaponBaseAtttackMod
- Had the macro also grab the Dexterity Bonus in case it was necessary for ranged attacks or melee attacks using weapon finesse
I've tested the program with using attacks that have a 1.5 strength bonus to damage. They work fine, except for the hiccup that the tooltip has trouble showing this bonus. It's still calculated properly though, so I'm okay with that.
I may just add a [H: strengthDamageBonus = strengthBonus] or a [H: strengthDamageBonus = 1.5*strengthBonus] when necessary and move the strengthDamage where it needs to be if I get annoyed/less lazy enough.
Thank you very much for the help.