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

Critical damage added reusing dice with a pseudo if-else?

I was wondering if there is a way to combine a reuse dice result like $[[0]] or $[[1]] with the if-else math trick [[{1d20=20}]]d8 for rolling a 1d8 damage when is critical. If a 20 equals 20 the answer is 1 [true], otherwise is 0 [false]. So if is true, the 1 combine with the d8 for a 1d8 and rolls the extra damage.  I tested the [[{1d20=20}]]d8 expression and works, but I want to create a macro where first throw a separate 1d20 for attack and that result be saved in a reuse dice $[[0]].  I tried to use the if-else math trick with that, but didn't read it right. Something like this template... &{template:default} {{name= Critical Test}} {{ Attack=[[1d20]] }}{{ Damage =[[  [[{$[[0]]=20}]]d8  ]]}}. I even tried using combinations like [[{$[[0]]=20}]]d8 and others but nothing works. I could make an inline roll to work inside another, but the third time fails... So maybe for someone worked with this or have a better approach?
1624522798

Edited 1624534385
GiGs
Pro
Sheet Author
API Scripter
You can never use $[[0]] rolls in any kind of arithmetic, or logic testing. You need to construct one roll, and extract the subrolls from that. Like &{template:default} {{name= Critical Test}} [[  [[{[[1d20]]=20}]]d8 ]] {{ Attack=$[[0]] }}{{ Damage =$[[2]]}} Wont this show 0 damage if damage is not a critical? To show normal damage, with critical included, you could do something like &{template:default} {{name= Critical Test}} [[  [[{[[1d20]]=20}]]d8 +1d8 ]] {{ Attack=$[[0]] }}{{ Damage =$[[2]]}}
1624534850
GiGs
Pro
Sheet Author
API Scripter
I just tested it, and looks like you cant do this [[{[[1d20]]=20}]]d8 Making that inner 1d20 an inline roll means causes it to fail, so I don't see any way to do what you need.
1624535218
GiGs
Pro
Sheet Author
API Scripter
Correction: here's a method that works, using a different approach: &{template:default} {{name= Critical Test}} [[[[{0,[[1d20]]-19}kh1]]d8]] {{ Attack=$[[0]] }} {{Critical Damage=$[[2]]}} and with normal damage included (assuming its a d8) &{template:default} {{name= Attack Roll}}  [[[[{0,[[1d20]]-19}kh1]]d8 +1d8]] {{ Attack=$[[0]] }} {{Damage if Hit=$[[2]]}}
1624535780

Edited 1624535920
GiGs
Pro
Sheet Author
API Scripter
If you want to show normal damage and total damage if crit separately, and also handle crit rolls other than 20, you can use this roll: &{template:default} {{name= Critical Test}}  [[[[{{0,[[1d20]]-19}kh1,1d1}dh1 *1]]d8 +[[1d8]]]] {{ Attack=$[[0]] }} {{Damage if Hit=$[[2]]}}{{Damage If Crit=$[[3]]}} Just change the [[1d20]]-19 part so that the -19 is 1 less than the critical. If you crit on 18, that would be [[1d20]]-17 And if you roll more than 1 dice on a critical, change this part: *1]]d8 to, say *2]]d8 for d8 on crits. Any part of this roll can be changed to reference to character attributes, so you don't have to create a new macro for every character.
Excellent  GiGs , that's exactly the idea I was looking for... I tried even calling character data and works like a charm. This is basically my macro: /em &{template:default} {{name= Critical Test}}[[[[{0,[[1d20r<1 + @{NAME|dexterity_mod}[ModDex] + @{NAME|pb}[Proficiency] + 2[Magic] + 2]]-29}kh1]]d8[Radiant] + 1d8[Radiant] + @{NAME|dexterity_mod}[ModDex] + 2[Magic] ]]{{ Attack=$[[0]] }}{{ Damage =$[[2]]}}{{===========}} Thanks a lot. Guess you worked with that problem before. What could be your approach if instead of 2 or 3 d8 for a critical, you have another dice like sneak attack... [[1d8[NormalDmg] + 2d6[Sneak] ]] Or more maybe... like a blood hunter rite dice added to that... [[1d8[NormalDmg] + 2d6[Sneak] + 1d4[RiteDmg] ]] For a bloohunter/thief for example... His critical would be a combination of dices. If I try it with more d20 it would be an individual roll for each one, so I would need to make some kind of connection between those, I guess [[[[{{0,[[1d20]]-19}kh1,1d1}dh1 *1]]d8 + [[[[{{0,[[1d20]]-19}kh1,1d1}dh1 *2]]d6 + [[1d8 + 2d6[Sneak] ]]]] How you could connect that in only one 1d20 roll? GiGs said: If you want to show normal damage and total damage if crit separately, and also handle crit rolls other than 20, you can use this roll: &{template:default} {{name= Critical Test}}  [[[[{{0,[[1d20]]-19}kh1,1d1}dh1 *1]]d8 +[[1d8]]]] {{ Attack=$[[0]] }} {{Damage if Hit=$[[2]]}}{{Damage If Crit=$[[3]]}} Just change the [[1d20]]-19 part so that the -19 is 1 less than the critical. If you crit on 18, that would be [[1d20]]-17 And if you roll more than 1 dice on a critical, change this part: *1]]d8 to, say *2]]d8 for d8 on crits. Any part of this roll can be changed to reference to character attributes, so you don't have to create a new macro for every character.
1624621560
GiGs
Pro
Sheet Author
API Scripter
First, if you change NAME in the above macro to selected , you'll be able use the same macro for any character - just select their token and run it. You'll have to be sure they have the relevant attributes though. aikidosama said: What could be your approach if instead of 2 or 3 d8 for a critical, you have another dice like sneak attack... [[1d8[NormalDmg] + 2d6[Sneak] ]] Or more maybe... like a blood hunter rite dice added to that... [[1d8[NormalDmg] + 2d6[Sneak] + 1d4[RiteDmg] ]] For a bloohunter/thief for example... His critical would be a combination of dices. I would create an attribute for the damage roll, and link that attribute in the macro. So you have an attribute named @{NAME|Damage-dice} which contains 1d8[Radiant] + @{NAME|dexterity_mod}[ModDex] + 2[Magic] you could have in the macro: }[[[[{0,[[1d20r<1 + @{NAME|dexterity_mod}[ModDex] + @{NAME|pb}[Proficiency] + 2[Magic] + 2]]-29}kh1]]d8[Radiant] + @{NAME|Damage-dice}]] You can experiment with different names - exactly how best to do this depends on your character sheet. But probably the best bet is to have a normal-damage for each weapon, and for criticals, have a critical-target, critical-dice, and critical-multiplier for each. But looking at your macro, it seems you've broken the link between critical damage roll and the actual attack roll. That 29 target will need to be recalcuated any time the modifiers change, which undermines the idea of using character references.You can get around that by calculating the total. Instead of -29 , use -(19+@{NAME|dexterity_mod}[ModDex] + @{NAME|pb}[Proficiency] + 2[Magic] + 2) So that 29 total is calculated each time the modifiers change. For your multiple d20 rolls question: what does each roll represent? Are they completely separate attacks, or rolls with advantage, or what? This might be getting too complex for a macro!
Thanks for your answer  GiGs And yes, I playing with the idea to create this macro with selected for a token. For now I'm just playing only with the idea to add the damage to the critical for me and then expand it to the rest of the players.  I would create an attribute for the damage roll, and link that attribute in the macro. So you have an attribute named @{NAME|Damage-dice} which contains 1d8[Radiant] + @{NAME|dexterity_mod}[ModDex] + 2[Magic] you could have in the macro: }[[[[{0,[[1d20r<1 + @{NAME|dexterity_mod}[ModDex] + @{NAME|pb}[Proficiency] + 2[Magic] + 2]]-29}kh1]]d8[Radiant] + @{NAME|Damage-dice}]] You can experiment with different names - exactly how best to do this depends on your character sheet. But probably the best bet is to have a normal-damage for each weapon, and for criticals, have a critical-target, critical-dice, and critical-multiplier for each. But looking at your macro, it seems you've broken the link between critical damage roll and the actual attack roll. That 29 target will need to be recalcuated any time the modifiers change, which undermines the idea of using character references.You can get around that by calculating the total. Instead of -29 , use -(19+@{NAME|dexterity_mod}[ModDex] + @{NAME|pb}[Proficiency] + 2[Magic] + 2) So that 29 total is calculated each time the modifiers change. I tried the @{NAME|Damage-dice}  attribute, but seems that break the macro in some way, so finally works with the -19 plus the others modifiers mostly like you show up here. For your multiple d20 rolls question: what does each roll represent? Are they completely separate attacks, or rolls with advantage, or what? This might be getting too complex for a macro! No, in fact is only one 1d20 attack. I playing with this Bloodhunter/thief and when attacks and hit, the damage runs like this 1d8[Radiant] damage from a dawnbringer sword 2d6[Sneak]  damage from a sneak attack of the thief 1d4[Rite] thunder damage from a rite attack of the bloodhunter So I have a macro that shows the attack in one line, then the damage in other line and then a third line the crit damage. So if you see the green 20 critical in the first line, you have to sum manually the second and third line.  Sometimes a fourth line if sneaks and so on.  And that's why I create this post, to make only 1 line of damage when hits critical.  Your idea is just what I was looking for &{template:default} {{name= Critical Test}} [[[[{0,[[1d20]]-19}kh1]]d8]] {{ Attack=$[[0]] }} {{Critical Damage=$[[2]]}} But playing in some way to make 1d8 + 2d6 + 1d4 damage in the critical. Right now only the 1d8 damage could be added in the critical. And yes... I guess is maybe to complex for a macro, but still trying... any ideas? Thanks again.
1624708853
GiGs
Pro
Sheet Author
API Scripter
Do all those damage rolls get rolled again on a critical? I don't know the system youre playing, but in most systems, it's just the base damage you roll again, and everythign else is just rolled once. Unfortunately there's no way to use the d20 roll multiple times. If they were separate independent d20 rolls, you could do something like [[[[{0,[[1d20]]-19}kh1]]d8 + [[{0,[[1d20]]-19}kh1]]d6 + [[{0,[[1d20]]-19}kh1]]d6 + [[{0,[[1d20]]-19}kh1]]d4]] What you could do is have the d20 completely separate, and show the normal and critical (+normal) damage, and just use the line that is appropriate for the hit. Or you could do what several sheets do, and have a button to roll the damage again, for critical hits (you wont be able to add it automatically though). Unfortunately, you cant do better than these options without the API, a Pro subscriber benefit.
1624830452

Edited 1624830482
Yes, all in one roll on a critical. Because in a critical, all dices doubled. Example: One attack with the sword making 1d8 + 2d6 + 1d4 + 5 and if critical 2d8 + 4d6 + 2d4 + 5. Only the dices doubled. Yes, sadly are not independent d20 rolls. And yes, I am doing that, separating in 2 lines, the normal damage and the critical damage apart. I create this post trying to only use one line.  I was trying all of this with free susbscriber to give those to all my players partners. Anyway, I still going to search a way to if possible... and for now, have two lines for separate damage. Thanks a lot  GiGs ,   for all the help and your answers. You gave me good information and I have better undestanding of the macros.  in D&D 5e, I  GiGs said: Do all those damage rolls get rolled again on a critical? I don't know the system youre playing, but in most systems, it's just the base damage you roll again, and everythign else is just rolled once. Unfortunately there's no way to use the d20 roll multiple times. If they were separate independent d20 rolls, you could do something like [[[[{0,[[1d20]]-19}kh1]]d8 + [[{0,[[1d20]]-19}kh1]]d6 + [[{0,[[1d20]]-19}kh1]]d6 + [[{0,[[1d20]]-19}kh1]]d4]] What you could do is have the d20 completely separate, and show the normal and critical (+normal) damage, and just use the line that is appropriate for the hit. Or you could do what several sheets do, and have a button to roll the damage again, for critical hits (you wont be able to add it automatically though). Unfortunately, you cant do better than these options without the API, a Pro subscriber benefit.
1624841553
GiGs
Pro
Sheet Author
API Scripter
aikidosama said: Anyway, I still going to search a way to if possible... Let me urge you to avoid wasting time on this. It can't be done. Well there is one way (and only one way). That is to calculate the odds of the damage roll, getting a weight for every possible damage result, and build a rollable table - then you can replace the roll in the macro with the rollable table. This will be very tedious to create without the API. And you would need a different table for every possible damage roll: one for 1d8 + 2d6 + 1d4 + 5, another for  1d8 + 2d6 + 1d4 + 6, and so on.
Mmm... that's interesting... I was thinking in rollable tables two days ago, not so very  far from your idea, but I was thinking in having a table of 20 with will be the same roll 20 at the end, but I wasn't sure yet how to create it and making it work. Giving a weight sounds better. And yes... the idea was very complicated to write but maybe could do (I guess)  But you look at the problem differently or I am not seeing it... why need a different table for each damage roll? I was thinking only one table with the dices damages and sum the modifiers to the formula.
1624963931
GiGs
Pro
Sheet Author
API Scripter
You dont need a table for each roll , you ned a separate table for each different group of dice. d8+2d6+d4 will need a different table than d8+2d6+d6 for example. I forgot you could simply add the constant modifier - that should work. But if dice change, a new table is needed.
So, what you are saying is that I need a table with same weight for all the lines of a table having the result of a combination of dices like d8+2d6+d4, (starting from back) 1+1+1+1 1+1+1+2 1+1+1+3 1+1+1+4 1+1+2+1 1+1+2+2 1+1+2+3 1+1+2+4 ...and so on? And that will be something like this, right? [[[[{{0,[[1d20]]-19}kh1,1d1}dh1]][[1t[crit_d8_2d6_d4]]] + [[1d8+2d6+1d4]] ]] I guess that is your idea? GiGs said: You dont need a table for each roll , you ned a separate table for each different group of dice. d8+2d6+d4 will need a different table than d8+2d6+d6 for example. I forgot you could simply add the constant modifier - that should work. But if dice change, a new table is needed.
1625081564

Edited 1625081637
GiGs
Pro
Sheet Author
API Scripter
Yes, thats the idea. You can use anydice.com to calculate the weights (export the table result, and multiply each % by the amount needed to make the smallest % equal 1; the rest will then be correct). For the actual roll: the original I suggested was [[[[{{0,[[1d20]]-19}kh1,1d1}dh1 *1]]d8 +[[1d8]]]] To use the table, you'd just replace the first d8 with the table call, so for that it would be: [[[[{{0,[[1d20]]-19}kh1,1d1}dh1 *1]]t[crit_d8_2d6_d4] +[[1d8]]]] The normal way to call a table is 1t[table] - but the 1 here is the number of rolls. You are replacing that with your critical calculation, and it will usually work out as zero, and only sometimes 1.
I never used the anydice.com and I was then confused before... so instead of using the calculation of the dices and the result of the sum of those, anydice give me how possible is for each number to appear from 4 (minimun) to 24 (maximum)  But I am some lost in this part... what you mean, multiply? That result didn't send a 100% weights? Because what the table will send is the result, not the percentage or I missing something? GiGs said: --> and multiply each % by the amount needed to make the smallest % equal 1; the rest will then be correct. And yes, I guess that making the perfect solution using tables, yes... Only adding insted of [[1d8]] this at the end [[1d8 + 2d6 + 1d4]] for the normal roll and works tidy. [[[[{{0,[[1d20]]-19}kh1,1d1}dh1 *1]]t[crit_d8_2d6_d4] +[[1d8]]]] The normal way to call a table is 1t[table] - but the 1 here is the number of rolls. You are replacing that with your critical calculation, and it will usually work out as zero, and only sometimes 1.
1625137202

Edited 1625137485
GiGs
Pro
Sheet Author
API Scripter
So for anydice, here's the basic dice roll: <a href="https://anydice.com/program/23054" rel="nofollow">https://anydice.com/program/23054</a> You then click the export button and copy out the whole text, giving you this: "output 1",14.000000000012207,3.5118845842844437,4,24 #,% 4,0.0868055555556 5,0.347222222222 6,0.868055555556 7,1.73611111111 8,2.95138888889 9,4.51388888889 10,6.25 11,7.98611111111 12,9.46180555556 13,10.4166666667 14,10.7638888889 15,10.4166666667 16,9.46180555556 17,7.98611111111 18,6.25 19,4.51388888889 20,2.95138888889 21,1.73611111111 22,0.868055555556 23,0.347222222222 24,0.0868055555556 The first 2 lines aren't necessary. Note it then shows you the number, followed by a percentage. Thats showing you what the percentage chance of each possible roll of the damage is. The problem for rollable tables, you need integers for the weights, not percentages. So you have to copy those into a spreadsheet, separate the numbers at commas, and multiply the second column of numbers by the factor that makes the smallest percentage number equal exactly 1. Luckily spreadsheets have formulae that make this easy. Here's one for this specific roll Using that you can find you need to create a rollable table with the following item names and weights: Name&nbsp; Weight 4&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 1 5&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 4 6&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 10 7&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 20 8&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 34 9&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 52 10&nbsp;&nbsp;&nbsp; &nbsp; 72 11&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 92 12&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 109 13&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 120 14&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 124 15&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 120 16&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 109 17&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 92 18&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 72 19&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 52 20&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 34 21&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 20 22&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 10 23&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 4 24&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 1 And then the really tedious part begins - creating the rollable table and entering those values one by one. As I said, this is a tedious process. And remember, if you ever want to use a different set of dice, you have to go through this whole process each time, making a new table.
Oh, I get it now. It's 1 divided the first percentage given in anydice. I understand now.&nbsp; I see is tedious yes, but at least is a way to get the sum of all of the criticals dices. And when done, I could export and import the tables via json to use in other games.&nbsp; GiGs said: Here's one for this specific roll Using that you can find you need to create a rollable table with the following item names and weights: Name&nbsp; Weight 4&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 1 5&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 4 6&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 10 7&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 20 8&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 34 9&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 52 10&nbsp;&nbsp;&nbsp; &nbsp; 72 11&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 92 12&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 109 13&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 120 14&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 124 15&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 120 16&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 109 17&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 92 18&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 72 19&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 52 20&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 34 21&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 20 22&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 10 23&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 4 24&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 1 And then the really tedious part begins - creating the rollable table and entering those values one by one. As I said, this is a tedious process. And remember, if you ever want to use a different set of dice, you have to go through this whole process each time, making a new table. Really thanks for all your help ,&nbsp; GiGs . I finally have all my questions resolve.
1625261509
GiGs
Pro
Sheet Author
API Scripter
You're welcome. :)