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

Replace negative values with 0

Hello there ! A few weeks back, I started using ScriptCards to roll damage in my Fallout game. A nice bloke by the name of David M gave me a solution to the problem I had. David, you're probably gonna read this. Hi there ! The ScriptCard outputs something like this, whenever I use it <a href="https://i.imgur.com/Yux8m4h.png" rel="nofollow">https://i.imgur.com/Yux8m4h.png</a> But I have a problem with weapons that have a low chance to damage big armors. Like in this case, here : <a href="https://i.imgur.com/lMlkVdQ.png" rel="nofollow">https://i.imgur.com/lMlkVdQ.png</a> As you can see, even though the weapon is weak as hell against this armor, it did manage to pierce through a few times and deal some damage. But the negative values returned by all the other attacks ended up negating the few points of damage that went through. The attack ended up dealing -132 damage instead of 15, as it should have. So my question is, is there a way to forbid macros from pumping out negatives values ? So that every single roll under 0 returns a value of 0 ? Thanks for reading this ! And apologies for using external links, posting always fails whenever I paste pictures, for some reason.
1687429111

Edited 1687429157
Gauss
Forum Champion
You want this: {X,0}kh1 Where "X" is whatever damage formula you normally use.&nbsp; For a more specific answer I'd need to know what the damage formula is.&nbsp;
Right, sorry. Here is the formula for rolling damage : --:RollDamage| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=damage|1d[$die] - 1 + [$modDam] - [$netArmor] {FLOOR} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --+|[c][b]Damage [&amp;i]: [$damage][/b][/c] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=totalDamage|[$totalDamage] + [$damage] I think the first line is used for each damage roll, and the third line is used to add them up.
1687477727
David M.
Pro
API Scripter
Try adding this line after what you posted: --?[$totalDamage] -lt 0|=totalDamage;0
1687784058

Edited 1687787686
Hey mate. Thanks for your answer ! I gave it a go, so I ended up with this : &nbsp;&nbsp; --=damage|1d[$die] * [$mod] - [$mod] + [$modDam] - [$netArmor] {FLOOR} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --+|[c][b]Damage [&amp;i]: [$damage][/b][/c] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=totalDamage|[$totalDamage] + [$damage] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --?[$totalDamage] -lt 0|=totalDamage;0 It didn't work on the right value, I think. It did round the Total Damage to 0, but didn't have any influence on the individual lines. I'm looking round the "Damage x" lines that have a negative result to 0 so that the Total Damage can be properly calculated. Right now it gives that sort of result : <a href="https://i.imgur.com/OBCLwzO.png" rel="nofollow">https://i.imgur.com/OBCLwzO.png</a> As you can see, the Total Damage value is the one rounded to 0. I think it's almost there ! :D I did try to apply that syntax you posted to the previous value, like so : --:RollDamage| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=damage|1d[$die] * [$mod] - [$mod] + [$modDam] - [$netArmor] {FLOOR} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --+|[c][b]Damage [&amp;i]: [$damage] -lt 0|=[&amp;damage];0[/b][/c] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=totalDamage|[$totalDamage] + [$damage] Aaaand, I broke it ! I haven't quite figured the syntax. Edit : Alright, so I tried to connect my two braincells together and slapped this in the macro : --:FUNCTIONS| &nbsp; --:RollDamage| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=damage|1d[$die] * [$mod] - [$mod] + [$modDam] - [$netArmor] {FLOOR} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --+|[c][b]Damage [&amp;i]: [$damage][/b][/c] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --?[$damage] -lt 0|=&amp;damage;0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=totalDamage|[$totalDamage] + [$damage] &nbsp; --&lt;| }} Didn't work. But my mate fixed it. Turns out I shouldn't have used a "&amp;" before the "damage;0" -:FUNCTIONS| &nbsp; --:RollDamage| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=damage|1d[$die] * [$mod] - [$mod] + [$modDam] - [$netArmor] {FLOOR} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --+|[c][b]Damage [&amp;i]: [$damage][/b][/c] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --?[$damage] -lt 0|=damage;0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=totalDamage|[$totalDamage] + [$damage] &nbsp; --&lt;| }} This works. It still displays the negative Damage rolls, but only adds up the positive ones. Like so : <a href="https://i.imgur.com/rsVWkiV.png" rel="nofollow">https://i.imgur.com/rsVWkiV.png</a> As you can see, even though I have loads of negative results, they aren't used by the Total Damage calculation. And all the positive lines do add up to 34. Then my mate suggested this tweak : --:FUNCTIONS| &nbsp; --:RollDamage| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=damage|1d[$die] * [$mod] - [$mod] + [$modDam] - [$netArmor] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --?[$damage] -lt 0|=damage;0 {FLOOR} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --+|[c][b]Damage [&amp;i]: [$damage][/b][/c] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=totalDamage|[$totalDamage] + [$damage] &nbsp; --&lt;| }} And boom <a href="https://i.imgur.com/Qo3nf6Y.png" rel="nofollow">https://i.imgur.com/Qo3nf6Y.png</a> Now every single roll that is negative is displayed as a 0. So there you go, it's all good now. Thanks for the help !