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

Determine Critical Rolls in a Macro

1603121795

Edited 1603130345
I have been looking for a way in a macro to only show critical damage if the attack roll was a critical. Oosh's post in the Stupid Tricks thread here got me thinking that maybe this is possible.  But I'm a little stumped as to how exactly I'd apply the trick to this situation.     I have all my wizard spells set up as macros using the spell template in the 5e OGL sheet.  As an example, here is my macro for Firebolt (which is relatively straightforward compared to something like Scorching Ray).  If the attack is a crit, the cs>20 gets it to show up in a green box, but is there a way to only display the the "+XX on crit" text if it is a critical attack roll? @{Thaladar|wtype}&{template:spell} {{level=evocation cantrip}}  {{name=Fire Bolt}} {{castingtime=1 action}} {{range=120 feet}} {{target=One creature or object within range}} {{v=1}} {{s=1}} {{duration=Instantaneous}} {{description=You hurl a mote of fire at a creature or object within range.  Make a ranged spell attack against the target.  On a hit, the target takes [[round((@{Thaladar|level} + 1) / 6 + 0.5)]]d10 fire damage. Spell Attack: ?{Advantage?|Normal Roll,[[1d20cs>20 + @{Thaladar|spell_attack_bonus}[SPELL]]]|Advantage,[[2d20kh1cs>20 + @{Thaladar|spell_attack_bonus}[SPELL]]]|Disadvantage,[[2d20kl1cs>20 + @{Thaladar|spell_attack_bonus}[SPELL]]] } Damage: [[[[round((@{Thaladar|level} + 1) / 6 + 0.5)]]d10]] (+[[[[round((@{Thaladar|level} + 1) / 6 + 0.5)]]*10]] for crit) }}  @{Thaladar|charname_output}
Only the Attack & Damage template has the internal programming to detect when a crit has or has not been rolled to affect the output. Alternatively you can use the Attack template with 2 different Damage templates for regular and crit outputs. In the Attack template make buttons out of the Rname and RnameC fields to reference the different templates for normal and crit damage, but of course, that takes a lot more work as you'd need 3 macros for each attack.
1603155827

Edited 1603162410
Oosh
Sheet Author
API Scripter
You can do this in a roundabout way, by doing the math outside the template fields: @{thaladar|wtype}&{template:spell} {{level=evocation cantrip}} {{name=Fire Bolt}} {{castingtime=1 action}} {{range=120 feet}} {{target=One creature or object within range}} {{v=1}} {{s=1}} {{duration=Instantaneous}} [[ [[round((@{thaladar|level} + 1) / 6 + 0.5)]]d10[BASE] + [[floor((?{Advantage?|Normal Roll,[[1d20| Advantage,[[2d20kh1| Disadvantage,[[2d20kl1}cs> 15 + @{thaladar|spell_attack_bonus}[SPELL]]]-@{thaladar|spell_attack_bonus})/ 15 )*round((@{thaladar|level} + 1) / 6 + 0.5)*10]][CRIT] ]] {{description=You hurl a mote of fire at a creature or object within range. Make a ranged spell attack against the target. On a hit, the target takes [[round((@{thaladar|level} + 1) / 6 + 0.5)]]d10 fire damage. Spell Attack: $[[1]] Damage: $[[3]]}} @{thaladar|charname_output} The crit range is currently set to 15, just because it makes it easier to test. There are two places to change this (bold & underline) if you want to change it back to 20. This does mean you won't get 3d dice for your attack roll - the only way to avoid that is to remove the [[ ]] inline rolls allowing us to grab & print the roll with the $[[1]] call. So if the 3d dice are more important to you, you can do this: @{thaladar|wtype}&{template:spell} {{level=evocation cantrip}} {{name=Fire Bolt}} {{castingtime=1 action}} {{range=120 feet}} {{target=One creature or object within range}} {{v=1}} {{s=1}} {{duration=Instantaneous}} [[ [[round((@{thaladar|level} + 1) / 6 + 0.5)]]d10[BASE] + floor((?{Advantage?|Normal Roll,1d20| Advantage,2d20kh1| Disadvantage,2d20kl1}cs>15 + @{thaladar|spell_attack_bonus}[SPELL]-@{thaladar|spell_attack_bonus})/15)*round((@{thaladar|level} + 1) / 6 + 0.5)*10[CRIT] ]] {{description=You hurl a mote of fire at a creature or object within range. Make a ranged spell attack against the target. On a hit, the target takes [[round((@{thaladar|level} + 1) / 6 + 0.5)]]d10 fire damage. Damage: $[[1]]}} @{thaladar|charname_output} This also makes the tooltip a mess, but you get your 3d dice back. Since we can't grab the attack rolls, the green crit coloring is pretty meaningless - you could change the roll to cs>1 so the attack rolls are at least green highlighted in the tooltip, but leave the second "/15" number as the correct crit range, as that one does the math. You'd have to manually find the roll in the tooltip mess to see if you hit, which isn't ideal. Unless you want to trust the 3d dice (I wouldn't). One thing I was unaware of - the blue coloring for a roll being both a crit and a fumble doesn't work in the tooltip.
Oosh, wow.  Always amazing.  I can't wait to test this out and try to understand your magic :-)  Thanks!!
1603162644
Oosh
Sheet Author
API Scripter
No problem - the explanation is reasonably straightforward. We just do the attack roll (ignoring advantage query): [[1d20 + SAB]] Then we need to remove the SAB to check if the base roll was 20 (could alternatively do it by adding SAB to the roll check.... same result): [[1d20 + SAB]] - SAB Then divide that by 20 and use the floor operator. This means 20=1 and everything else=0. floor( ([[1d20 + SAB]] - SAB) /20) Then multiply that by your crit damage calculation. A 20 gives you 1*(crit damage), while a 1-19 gives you 0*(crit damage). Simple! :)
Dakota H.  Thanks for the comment.
1603209797

Edited 1603216865
Oosh said: No problem - the explanation is reasonably straightforward. We just do the attack roll (ignoring advantage query): [[1d20 + SAB]] Then we need to remove the SAB to check if the base roll was 20 (could alternatively do it by adding SAB to the roll check.... same result): [[1d20 + SAB]] - SAB Then divide that by 20 and use the floor operator. This means 20=1 and everything else=0. floor( ([[1d20 + SAB]] - SAB) /20) Then multiply that by your crit damage calculation. A 20 gives you 1*(crit damage), while a 1-19 gives you 0*(crit damage). Simple! :) Thanks!  The explanation definitely helps.  Now I'm working to translate this into spells like Scorching Ray which have multiple attacks.  And through process of elimination, I found the second attack roll is $[[5]] and second damage roll as $[[9]].  The third attack is $[[8]] and the third damage is $[[9]]. I don't really understand the numbering of the rolls, but this seems to work consistently.  This is a breakthrough.  Thanks so much for helping solve this.  Here is my preliminary, unfinished Scorching Ray with multiple attack rolls.  Maybe there is a more elegant way to perform multiple attack and damage rolls, but this at least works. @{Thaladar|wtype}&{template:spell} {{level=evocation 2}} {{name=Scorching Ray}} {{castingtime=1 action}} {{range=120 feet}} {{target=One or more creatures within range}} {{v=1}} {{s=1}} {{duration=Instantaneous}} [[ [[2]]d6[BASE] + [[floor((?{Advantage on Ray 1?|Normal Roll,[[1d20| Advantage,[[2d20kh1| Disadvantage,[[2d20kl1}cs>15 + @{thaladar|spell_attack_bonus}[SPELL]]]-@{thaladar|spell_attack_bonus})/15)*12]][CRIT] ]] [[ [[2]]d6[BASE] + [[floor((?{Advantage on Ray 2?|Normal Roll,[[1d20| Advantage,[[2d20kh1| Disadvantage,[[2d20kl1}cs>15 + @{thaladar|spell_attack_bonus}[SPELL]]]-@{thaladar|spell_attack_bonus})/15)*12]][CRIT] ]] [[ [[2]]d6[BASE] + [[floor((?{Advantage on Ray 3?|Normal Roll,[[1d20| Advantage,[[2d20kh1| Disadvantage,[[2d20kl1}cs>15 + @{thaladar|spell_attack_bonus}[SPELL]]]-@{thaladar|spell_attack_bonus})/15)*12]][CRIT] ]] {{description=You create multiple rays of fire and hurl them at targets within range. You can hurl them at one target or several. Make a ranged spell attack for each ray. On a hit, the target takes 2d6 fire damage. Ray #1: Spell Attack: $[[1]] Damage: $[[3]] Ray #2: Spell Attack: $[[5]] Damage: $[[9]] Ray #3: Spell Attack: $[[8]] Damage: $[[11]] }}
1603258473
Oosh
Sheet Author
API Scripter
Yep, the numbering gets more and more unpredictable the more nested rolls you throw in there. AFAIK no one has figured out any pattern, it's just trial and error. There's plenty of ways to represent the spell rolls depending on preference, but as the rolls get more complicated those $[[0]] calls get increasingly difficult to wrangle. Separating out the damage into a second macro can make life easier - here's a Scorching Ray example that goes up to level 9 - it avoids using $[[0]] calls entirely due to the ungodly number of references you'd have to try to sort for rolling with 10 rays with advantage, and calculating damage. Has a target click to grab AC and colour the rolls blue for hit, green crit and red miss: &{template:npcaction}{{rname=Scorching Ray}} {{name=Target: **@{target|t1|token_name}**}} {{description=Ray 1: ** ?{Advantage?|Normal,[[1d20cs>[[{0@{target|t1|npc_ac} - @{spell_attack_bonus},2}k1]]cf<19 + @{spell_attack_bonus}]]| Advantage,[[2d20cs>[[{0@{target|t1|npc_ac} - @{spell_attack_bonus},2}k1]]cf<19kh1 + @{spell_attack_bonus}]]| Disadvantage,[[2d20cs>[[{0@{target|t1|npc_ac} - @{spell_attack_bonus},2}k1]]cf<19kl1 + @{spell_attack_bonus}]]} ?{Cast at what level?|2,Ray 2: ?{Advantage?} Ray 3: ?{Advantage?}   Cast at level **2** - | 3,Ray 2: ?{Advantage?}
Ray 3: ?{Advantage?}
Ray 4: ?{Advantage?}   Cast at level **3** - | 4,Ray 2: ?{Advantage?}
Ray 3: ?{Advantage?}
Ray 4: ?{Advantage?}
Ray 5: ?{Advantage?}   Cast at level **4** - | 5,Ray 2: ?{Advantage?}
Ray 3: ?{Advantage?}
Ray 4: ?{Advantage?}
Ray 5: ?{Advantage?}
Ray 6: ?{Advantage?}   Cast at level **5** - | 6,Ray 2: ?{Advantage?}
Ray 3: ?{Advantage?}
Ray 4: ?{Advantage?}
Ray 5: ?{Advantage?}
Ray 6: ?{Advantage?}
Ray 7: ?{Advantage?}   Cast at level **6** - | 7,Ray 2: ?{Advantage?}
Ray 3: ?{Advantage?}
Ray 4: ?{Advantage?}
Ray 5: ?{Advantage?}
Ray 6: ?{Advantage?}
Ray 7: ?{Advantage?}
Ray 8: ?{Advantage?}   Cast at level **7** - | 8,Ray 2: ?{Advantage?}
Ray 3: ?{Advantage?}
Ray 4: ?{Advantage?}
Ray 5: ?{Advantage?}
Ray 6: ?{Advantage?}
Ray 7: ?{Advantage?}
Ray 8: ?{Advantage?}
Ray 9: ?{Advantage?}   Cast at level **8** - | 9,Ray 2: ?{Advantage?}
Ray 3: ?{Advantage?}
Ray 4: ?{Advantage?}
Ray 5: ?{Advantage?}
Ray 6: ?{Advantage?}
Ray 7: ?{Advantage?}
Ray 8: ?{Advantage?}
Ray 9: ?{Advantage?}
Ray 10: ?{Advantage?}   Cast at level **9** - }[Roll Damage](~bob|ScorchDmg)}} And the damage macro, currently linked as (~bob|ScorchDmg): &{template:npcaction}{{rname=Scorching Ray Damage roll}}{{description=**Scorching Ray** hits for a total of** [[ [[?{How many rays hit?|1}*2]]d6[BASE] + [[?{How many rays critically hit?|0}*2]]d6[CRIT] ]] fire damage**, ?{How many rays hit?} rays hit the target and ?{How many rays critically hit?} of those critically hit}} It's all personal preference, really - there's plenty of ways to handle it. The one above for example, only asks for advantage once. I couldn't decide whether having a potential 9 Queries would be too much, so instead I put a "Level 0" option in the drop down to cast a single ray as required. But if you're generally casting 3 rays, the 3 Queries in one macro is probably a more convenient way to do it. I've never had to cast anything with so many attack rolls in a game, and have no idea which way I'd find easiest.