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

Can I create if/then statements with the Macros?

i.e., for my PC's main attack, a hand crossbow, I currently have the code set up like this: Firing! /roll 1d20+4 - @{target|Target1|bar2} AC /roll 1d4 damage against @{target|Target1|bar1} HP However, I would like to set up an if/then statement between line 2 and line 3 to detect if the result of line 2's equation is greater than negative one, indicating a hit on the enemy. If the attack roll is successful, then I want to go through with the damage roll. If not, then I want it to end the Macro. It would also be great if I could somehow detect if I got a natural twenty so that I could alter the script to roll another d20 to confirm the critical before rolling the damage dice, but I'll stick with the simpler things for now.
There are no if/then/else statements in the Macro system or any way to carry a variable from one line to another. You'll need Mentor level access to use the API for that. The best method(albeit still not great) I've found to date has been to write out all your attacks and damage along with critical / sneak attack / etc and visually determine what hit and what didn't. Using in-line rolls will make that cleaner to read. Example: [[ 1d20 + 4 - @{target|Target1|bar2} AC ]] would display something like: 2 AC instead of displaying the dice graphics and math Here's a sample macro I use for low-level one-shot campaigns I use when I don't want to spend the time working with attributes and token actions: /me grips his Longspear firmly in both hands and THRUSTS! Attack:[[1d20 + 7]](+2 if charge) Damage:[[1d8+6]] + SA:[[1d6]] Crit Threat: 20/x3 Confirm:[[1d20 + 7]] for addt'l [[ {1d8+6} + {1d8+6} ]] Output: Dorrin grips his Longspear firmly in both hands and THRUSTS! Attack: 15 (+2 if charge) Damage: 10 + SA: 4 Crit Threat: 20/x3 Confirm: 16 for addt'l 22
Ok, thanks!
What does SA stand for?
Sneak Attack. That macro is from a Pathfinder Rogue Scout who gets to apply Sneak Attack damage on charges.
1389717731

Edited 1389718061
Hi Michael. I did do something similar to what you wanted. Here is the script: /emas @{selected|token_name} attacks @{target|Target1|token_name} with it's @{Wpn1Nam} and deals [[{{1d20+@{STR} +@{Wpn1Atk} +@{Prof}}>@{target|Target1|AC}} * {@{Wpn1Dam} +@{STR}} ]] Damage! As a note, every character has the following stats filled out: AC, Wpn1Atk (the attack bonus from the weapon, i.e magic weapons), Prof (Proficiency bonus, or base attack bonus), Wpn1Dam (the damage of the weapon, usually a die amount [1d8], and then the 6 attributes associate with DnD (STR, DEX, CON, WIS, INT, CHA). This script rolls appropriately, tests to see if it is greater than or equal to the targets AC, and then deals damage. If it misses, then it deals 0. There are a 3 real challenges, and I have solutions to 2 of them. The first, is incidental bonuses to attack. For instance, if the attacker is charging they may get +2 to their attack. This is not taken into account, however you can add: + ?(Bonus to attacker|0). This would prompt you for a bonus to the attack roll. The second is incidental bonuses to AC of the target, which is cured the same way. with both solutions, it would look like this: /emas @{selected|token_name} attacks @{target|Target1|token_name} with it's @{Wpn1Nam} and deals [[{{1d20+@{STR} +@{Wpn1Atk} +@{Prof} + ?{Bonuses to Attack|0} - ?{Bonuses to targets AC|0}}>@{target|Target1|AC}} * {@{Wpn1Dam} +@{STR}} ]] Damage! Note: You cannot add to the static value after a >, so instead I subtract the bonus to AC from the roll result. It yields the same effect. The final is critical hits. I have been trying to wrack my brain to figure out how to get the damage to increase in the event of a roll above a certain value, but have been unsuccessful so far. We play DnD next, so in the event of a critical, the solution is to add the max die value for a weapon to damage dealt. We have to do this after the attack.
Also note, this is a DM script. If you want to use it as a player, change the /emas @{selected|token_name} to /me .
OK, thanks!
1389963120
GiGs
Pro
Sheet Author
API Scripter
An alternative to the ?{Bonuses to Attack|0} - ?{Bonuses to targets AC|0}} part of the script above: +{GMmods|Bar1} - {GMmods|Bar2} (Or just use a single bar for both - better option) Then create a separate token called GMmods, and before players make rolls, add any modifier to the bar1 and bar2 parts of that token. That saves the players from being pestered by modifier popups (which i think are fine for rarely used macros, but not for macros where most of the time there will be 0 modifier). It has the downside that the GM has to remember to enter the modifiers for each attack. Alternatively, for each monster, make AC a bar/bubble, so you can adjust it on the fly.