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 to display % chance of success and failure (5e)

Hi, I'm trying to help my players visualize how likely or unlikely they are to succeed at different tasks, since we're all a little bad at math. I want a macro that you can enter a difficulty class into, then enter the roll bonus, which then calculates the percentage chance of success and failure (d20). Here's what I've got so far: ?{wishper|yes,/w gm|no,} &{template:dmg} {{rname=Percent Chance}} {{damage=1}} {{dmg1flag=1}} {{dmg1=[[{{21-{?{Difficulty Class}-?{Roll Bonus}}}*5}]]%}} {{dmg1type=success (max 95%)}} {{dmg2flag=1}} {{dmg2=[[{100-{{21-{?{Difficulty Class}-?{Roll Bonus}}}*5}}]]%}} {{dmg2type=failure (min 5%)}} {{savedesc=savedesc}} {{savedc=savedc}} My main issue is with the calculation part of the macro: [[{{21-{?{Difficulty Class}-?{Roll Bonus}}}*5}]] This part seems to function normally. When I enter a DC 15 with a +0 bonus, it tells me I have a 30% chance success rate, and a 70% chance failure rate. However, if I enter a -1 bonus with the same DC, it tells me I have a 105% chance success rate. From what I can tell, something about the negative value prevents the  {?{Difficulty Class}-?{Roll Bonus} section from calculating correctly. Instead, it seems to just multiply 21 by 5, ignoring the center part of the calculation. When I hover over the result in the chat this is what I see In this image, the calculation should go like this (I think): [[{{21-{15- -1}}*5}]] ->  [[{{21-{14}}*5}]] ->  [[{{7}*5}]] -> 35 I'm guessing that I've bonked something with all the brackets or order of calculations. But since I have no idea what I'm doing I'm at a loss. If anybody could help me out, or even suggest a whole new approach, that'd be awesome. Thanks!
For some reason, the image didn't post. I'll try again
1692809597

Edited 1692809779
The Aaron
Roll20 Production Team
API Scripter
Try: [[(21-((?{Difficulty Class})-(?{Roll Bonus})))*5]] (Edit: needed one more set of Parenthesis)
1692814672

Edited 1692890500
GiGs
Pro
Sheet Author
API Scripter
The reason (I think) that Aaron's expression works is due to the way roll20 expressions handle signs. If you have a calculation that gives two signs of the same type, it doesn't work properly. So 21-(15--1) will fail, likewise 21++1 would fail (though that wouldnt happen in your case). Putting round brackets around any quantity forces Roll20 to calculate them properly, so 21-((15)-(-1)) works correctly though its a bit of a mess.
Thanks The Aaron! It works perfectly