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

Need help with macro using conditional statements

1605879212
Mago
Pro
Sheet Author
Hello forum, i need help with a simple macro that i just dont understand how to make: in my WH40k game  we use a simple damage calculator that looks like this: /em Damage Calculator /r  ?{Total Damage|0} -  ?{TB + AP|0} however i wanted a more sophisticated damage calculator that takes into account the stat known as penetration, i figured that i would need some conditional statements, i tried, i really did, but i cant crack this, i read the wiki and all but still, im not particularly good at math or complex macros...  This is what im looking for: Total damage - Soak = damage inflicted (if result is 0 No damage is inflicted, this is not important) *Total damage is just a number, no modifiers. *Soak is composed of TB (Toughness Bonus) + AP (armour points) *AP is reduced by PEN (penetration) down to 0 if PEN exceeds AP. *TB is NOT reduced by PEN as per the rules. The problem that i have is that if PEN is higher that AP then PEN also reduces TB on a regular subtraction (-) equation. Example:  Total damage (30), PEN (11), TB (20), AP (10),  30 - (20+ (10-11)) = 30 - 19 = 11 i would need a conditional statement that works like: if PEN exceeds AP then PEN = AP (thus cancelling each other) 30 - (20+ (10 - 11 conditional )) = 30 - (20+0) = 10 Help!
1605881117

Edited 1605881261
Oosh
Sheet Author
API Scripter
Ok, well you can't do actual conditionals just with the dice roller, but I think this will work: [[?{Damage|30}[DMG] - (@{selected|tb}[TB] + [[floor(@{selected|ap}/@{selected|pen})*(@{selected|ap}-@{selected|pen})]][AP BNS])]] This is assuming the Attribute names you supplied are the actual names on the sheet. If not, then this one has Queries: [[?{Damage|30}[DMG] - (?{TB?|20}[TB] + [[floor(?{AP?|10}/?{PEN?|11})*(?{AP?}-?{PEN?})]][AP BNS])]] Probably could've made that a bit simpler and just used a keep highest.... oh well: [[?{Damage|30}[DMG] - (?{TB?|20}[TB] + {?{AP?|10}-?{PEN?|11},0}k1[AP BNS])]]
1605884930
Mago
Pro
Sheet Author
Oosh said: Probably could've made that a bit simpler and just used a keep highest.... oh well: [[?{Damage|30}[DMG] - (?{TB?|20}[TB] + {?{AP?|10}-?{PEN?|11},0}k1[AP BNS])]] This one works like a charm! many thanks!