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

conditional macro

Is there a way to conditionally call a macro? I want to only add sneak attack damage for certain attacks.   I understand I will need a prompt that tells me to call the sneak attack macro, assuming this can work.  
1598194369
David M.
Pro
API Scripter
The macro language does not support conditional statements. You best bet would probably be to add a chat button somewhere in the template of your attack macro(s). KeithCurtis does a good job explaining these  here . Optionally, if your character sheet supports it (like 5e by Roll20 does), you could always add it as a secondary damage instance/type, and just ignore it when it does not apply.
1598202651
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Another option is to put a button into the description field of the attacks you want to have the sneak attack option. Create an ability on your abilities tab that rolls Sneak Attack damage. Name it ex., "Sneak-Attack". Then in the description field of the chosen attacks add the line: [Sneak Attack](~Sneak-Attack) You'll get something like this, a button you can push whenever you want to add sneak attack damage (the separate box below).
Can I do this if I use macros, but I don't use character sheets? I'm asking because I can't get it to work. Is there is a Youtube video? It's about a 5/10 on the importance scale so if not then I'll just add the sneak attack damage, and just have the GM ignore it. 
1598808669
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I'd have to see the macro to give advice on the best placement, but almost certainly. Putting that button code in will cause the button to appear in chat regardless. You can even put it in all by itself. But remember, for that particular button to do anything, you must use an ability (macro written on the abilities tab of a character journal) named "Sneak-Attack".
I'm just seeing your reply. This is the code for one of my weapons.  Sap <---I have this in the macro code area so the GM know which weaoon I'm using.  Attack [[1d20+11]] Damage [[1d4+1]] [Sneak Attack](~Sneak-Attack) The ability is named "Sneak-Attack"<--copied and pasted The code I use to roll the sneak attack damage for the ability is  [[2d6]] ----- When I press the button inside of the "Sap" macro I get " TypeError: Cannot read property 'substring' of undefined"
1600330434
Ziechael
Forum Champion
Sheet Author
API Scripter
It fails because the ~ is looking to run an ability from a character sheet. If you aren't using one, you might be best off with a simple query driven conditional: Sap Attack [[1d20+11]] Damage [[1d4+1]] ?{Sneak Attack|No, &nbsp ;|Yes,+ [[2d6]] Sneak} or Sap Attack [[1d20+11]] Damage [[1d4+1 + ?{Sneak Attack|No,0 |Yes,2d6[Sneak]} ]] or Sap Attack [[1d20+11]] Damage [[ [[1d4+1]] + ?{Sneak Attack|No,[[0]]|Yes,[[2d6]][Sneak]} ]] total ($[[0]] Base and $[[1]] Sneak)
1600435896

Edited 1600462931
Just an example I got help with in an AD&D2 game, posted in hopes that it might prove helpful to other neophytes like me. It's not a conditional macro code, not quite, but it does enough of that work for me at the moment. It's one macro that calls another. A lot of the special combat tricks from the Complete Fighter's Handbook are based on called shots with the standard -4 penalty, which can just be inserted manually into an attack roll. Some have an additional -4, like Sap (p. 72), the chance to knock out a foe with a precise blow. Because you're not using the weapon's business end in the way the gods intended, magical bonuses do not apply.  My elven swashbuckler is specialized in the rapier and main-gauche as well as the two-weapon style, so having recently picked up a long sword +1, flame tongue , he's now using that along with his rapier. He's not specialized in it, but does get the +1 species bonus with it. My usual attack macro has me picking out which pluses to use against particular opponents, which go up to +4 versus undead, but that's irrelevant here. This macro I call Sap offers me a choice of three weapons to use in an attack, rolls a d20, then tells me what AC I managed to hit and the damage done. Sap can only be used against man-sized critter and smaller, so L damage doesn't need to be accounted for.  /me attempts to knock out his opponent! Using his ?{which--|Rapier, rapier Tragedie's hilt as a club he swings hitting AC [[ @{thac0}-1d20-1 [STR] -1 [spec] +8 [Ludicrous Called Shot] ]] and inflicting [[ 1d6+1 [weap] +1 [STR] +2 [spec] ]] damage…..|Flame, Flame Tongue Wildfire he strikes with its hilt hitting AC [[@{thac0}-1d20-1 [STR] -1 [elf] +8 [Ludicrous Called Shot] ]] and inflicting [[1d8+1 [STR] ]] damage..... |Main-gauche, trusty main-gauche Kindness he surprises his opponent with the pommel  hitting AC [[@{thac0}-1d20-1 [STR] -1 [spec] +8 [Ludicrous Called Shot] ]] and inflicting [[1d4+1 [STR] +2 [spec] ]] damage...} /w Lameth [Knock out](~Lameth O'Clurichaun|Knock-Out) That last line above whispers to me a button I can click (if my attack was successful) that calls the Knock-Out macro below: &{template:2Edefault} {{name=Knock Out}}{{subtitle=attempt}}{{Knock Out Chance=[[?{Damage done|0}*10 ]] }}{{ My Roll=[[1d100cs<[[?{Damage done|0}*10]] ]] }} {{Temp Dmg=[[ceil(?{Damage done|0}*.75) ]]}} I have to enter the damage dealt in the successful Sap attack, which multiplied by ten yields my percentage chance to knock out my opponent. That's rolled, and the macro reminds me that 75% of that damage is temporary. In practice, the -8 Ludicrous Called Shot is too hefty to use against great armor classes, but when I succeed the output looks like this:
Ziechael you solved the issue I was having. Thanks for the help.