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

Macro for tricky roll involving negative numbers

1512507920

Edited 1512510251
I need a macro for an indie game that treats attribute scores on a scale from -5 to 5.  I can make individualized macros easily enough, but I want to make a macro that can work no matter what value an ability score is. For an ability score of 0, the roll is a straight 1d20. For a positive ability score the roll is (1+ability score)d20kh1. For a negative ability score, the roll is (1+absolute value of ability score)d20kl1. My problem is that I don't know how to write the macro so that it knows whether to keep the highest or the lowest die by checking if the ability score is negative.
1512509049
Lithl
Pro
Sheet Author
API Scripter
I don't think you can get what you want. I think your best bet for a pure macro would be: /roll (1 + abs(@{ability}))d20s That will roll the appropriate number of d20 dice, and sort the results low to high. (You can use "sd" instead of "s" to sort high to low.) Then you can look at the first or last die depending on your needs.
1512509860

Edited 1512510142
Using that macro exactly, except replacing @{ability} with @{Dex}, which is one of my ability scores returns: rolling (1 + abs(1))d20s (1+abs(1)) = 2 I can't get it to actually roll any dice, it just always returns 1+1=2 Incidentally, removing the abs() allows the macro to roll dice, but, obviously, it cannot account for the negative numbers. Putting the abs() part before the 1 in the sum does not make a difference, the macro fails to roll any dice either way.
1512523700

Edited 1512523739
Use double brackets to be sure the dice count resolves to a final number. /roll [[(1 + abs(@{ability})) ]]d20s
1512529355

Edited 1512529958
Silvyre
Forum Champion
Expanding on the macro, you should be able to get the kh1/kl1 functionality you want: [[1 + abs(@{ability})]]d20kh[[1 + (1 - ceil(@{ability} / 100)) * 100]]kl[[1 + ceil(@{ability} / 100) * 100]]
The macro you suggest always returns: 4d20kh1kl1 when I substitute @{ability} with an ability score of -3 that I was using to test.   When I used a positive 3 it returned: 4d20kh100kl1 This does not work, unfortunately.
1512573395
Andreas J.
Forum Champion
Sheet Author
Translator
I've encountered something similar, and I just abandoned the abs() thing(not saying you should). Think it have something to do with math functions resolving  last of all things which makes it problematic.
1512576836

Edited 1512577023
Silvyre
Forum Champion
Jacob said: The macro you suggest always returns: 4d20kh1kl1 when I substitute @{ability} with an ability score of -3 that I was using to test.  Try this: [[1 + abs(@{ability})]]d20kh[[1 + (1 - ceil((@{ability}) / 99)) * 99]]kl[[1 + ceil((@{ability}) / 99) * 99]]
Silvyre said: Try this: [[1 + abs(@{ability})]]d20kh[[1 + (1 - ceil((@{ability}) / 99)) * 99]]kl[[1 + ceil((@{ability}) / 99) * 99]] When @(ability) = 3 it returns:  4d20kh1kl100 When @(ability) = -3 it returns:  4d20kh100kl1 This does not work.
1512594310

Edited 1512594608
Its conditional based on it being one thing or the other (Positive or Negative number). One way might be to prompt the user for this information and based on the answer use one macro versus the other. ?{Is [[@{Ability}]] Pos or Neg?|Is Zero,[[1d20]]|Positive,[[[[1 + abs(@{Ability})]]d20kh1]]|Negative,[[[[1 + abs(@{Ability})]]d20kl1]]} Edit: Changed initial response for "0" that I did not notice the first time around. Information on prompted queries can be found here:&nbsp; <a href="https://wiki.roll20.net/Macros" rel="nofollow">https://wiki.roll20.net/Macros</a> Hope this helps
This should be what you want and it works for me. [[ [[1 + abs(@{ability})]]d20kh[[ceil((@{ability}) / 99)]]+[[1 + abs(@{ability})]]d20kl[[1 - ceil((@{ability}) / 99)]] ]] Thanks to Silvyre for doing the actually difficult problem solving bit
Pretty ingenious!
1512603026

Edited 1512608758
Silvyre
Forum Champion
Jacob said: Silvyre said: Try this: [[1 + abs(@{ability})]]d20kh[[1 + (1 - ceil((@{ability}) / 99)) * 99]]kl[[1 + ceil((@{ability}) / 99) * 99]] When @(ability) = 3 it returns:&nbsp; 4d20kh1kl100 When @(ability) = -3 it returns:&nbsp; 4d20kh100kl1 This does not work. Ah, apparently it's not possible to append both kh and kl to an ungrouped roll. Here's a workaround: /r {[[1 + abs(@{ability})]]d20kh[[1 + (1 - ceil((@{ability}) / 6)) * 5]]}kl1 or [[ {[[1 + abs(@{ability})]]d20kh[[1 + (1 - ceil((@{ability}) / 6)) * 5]]}kl1 ]]
1512604835

Edited 1512605087
Silvyre said: [[ {[[1 + abs(@{ability})]]d20kh[[1 + (1 - ceil((@{ability}) / 6)) * 4]]}kl[[1 + ceil((@{ability}) / 6) * 4]] ]] Now THIS is ingenious! (Although you need to change the *4's to *5's because ability scores of 5 or -5 make you roll 6 dice, but I'll let you off for how clever this solution is ;) EDIT: I think &nbsp;you would only need to change the first *4 as I believe the second one is redudant to the point you can make the last bit just "kl1")
1512608733
Silvyre
Forum Champion
Kyle said: Silvyre said: [[ {[[1 + abs(@{ability})]]d20kh[[1 + (1 - ceil((@{ability}) / 6)) * 4]]}kl[[1 + ceil((@{ability}) / 6) * 4]] ]] Now THIS is ingenious! (Although you need to change the *4's to *5's because ability scores of 5 or -5 make you roll 6 dice, but I'll let you off for how clever this solution is ;) EDIT: I think &nbsp;you would only need to change the first *4 as I believe the second one is redudant to the point you can make the last bit just "kl1") Good calls! Made those changes above.
1512614718

Edited 1512647037
Now this one works! Thanks everyone! [[ {[[1 + abs(@{ability})]]d20kh[[1 + (1 - ceil((@{ability}) / 6)) * 5]]}kl1 ]] Thank you so much! There are also situations in the system that grant advantage, where you treat your score as if it were 1 higher, disadvantage, where you treat your score as if it were 1 lower, or super-advantage, where you treat your score as if it were 2 higher.&nbsp; I came up with the following based on your formula, which seems to work for this, but I admit that I don't fully understand how your formula works, just that it seems to do exactly what I needed and from it I was able to build the rest: Rolling with Advantage: /r {[[1 + abs([[({{@{ability},1}&lt;0})*(1-{0,floor(1-abs(@{ability}-1))}dl1)*((-[[abs(@{ability})]]+1)-[[abs(@{ability})+1]])+[[abs(@{ability})+1]]]])]]d20skh[[1 + (1 - ceil(([[({{@{ability},1}&lt;0})*(1-{0,floor(1-abs(@{ability}-1))}dl1)*((-[[abs(@{ability})]]+1)-[[abs(@{ability})+1]])+[[abs(@{ability})+1]]]]) / 7)) * 6]]}kl1 Rolling with Disadvantage: /r {[[1 + abs([[({{@{ability},1}&lt;0})*(1-{0,floor(1-abs(@{ability}-0))}dl1)*((0-abs(@{ability})-1)-(@{ability}-1))+(@{ability}-1)]])]]d20skh[[1 + (1 - ceil(([[({{@{ability},1}&lt;0})*(1-{0,floor(1-abs(@{ability}-0))}dl1)*((0-abs(@{ability})-1)-(@{ability}-1))+(@{ability}-1)]]) / 7)) * 6]]}kl1 Rolling with Super-Advantage: /r {[[1 + abs([[({{@{ability},1}&lt;0})*(1-{0,floor(1-abs(@{ability}-1))}dl1)*((-[[abs(@{ability})]]+2)-[[abs(@{ability})+2]])+[[abs(@{ability})+2]]]])]]d20skh[[1 + (1 - ceil(([[({{@{ability},1}&lt;0})*(1-{0,floor(1-abs(@{ability}-1))}dl1)*((-[[abs(@{ability})]]+2)-[[abs(@{ability})+2]])+[[abs(@{ability})+2]]]]) / 8)) * 7]]}kl1
You can have the same roll for all 4 just with a query that asks if it it's normal, adv,...etc. like so [[ {[[1 + abs(@{ability}?{Roll Type|Normal,+0|Advantage,+1|Disadvantage,-1|Superadvantage,+2})]]d20kl[[1 + ceil((@{ability}?{Roll Type}) / 8) * 7]]}kh1 ]]