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

Wound calculation macro

1556581305

Edited 1556581427
Mike deBoston
Compendium Curator
The basic formula for wounds is netDamage / 4, rounded down (in Savage Worlds). That's an easy: /r floor( ?{net damage|5} /4) BUT, if net damage is <= 3 and the target is shaken, then it should be 1 wound. Can someone help me write a formula that prompts for net damage and shaken status? I know how to prompt for Shaken, but can't figure the math. If it helps, isShaken is a character sheet attribute. This macro will still be useful even if it's only possible for characters and not general purpose. ?{Shaken|No,0|Yes,1} Net Damage Shaken =Wounds 3 No 0 3 Yes 1 4 No 1 4 Yes 1 5 No 1 5 Yes 1 8 No 2 8 Yes 2 Maybe this isn't possible without the API... but it feels like it could be. Thanks in advance!
1556583915
GiGs
Pro
Sheet Author
API Scripter
This is probably doable by nesting a different formulae within each of the shaken options, something like /r ?{Shaken|No,floor( ?{net damage} /4)|Yes,{floor( ?{net damage} /4),1}kh1} You will have to deal with html entity replacements though (the above formula wont work - you'll need to change some of the characters), and you also have to handle if damage is 0 or less, which adds an extra level of nesting. An API script based solution would be better, and you can probably do it with Power Cards. Look for its thread.
1556596770
Mike deBoston
Compendium Curator
THAT is brilliant. I hadn't thought of using a condition to prompt for the data, with each using it a different way. Brilliant. As soon as I finalize this, I'll post here.
1556627902
GiGs
Pro
Sheet Author
API Scripter
For the dividing point between <1 damage and 1 damage on the shaken side, instead of {floor( ?{net damage} /4),1}kh1 this formula should work {floor( ?{net damage} /4),ceil(?{net damage}/1000)}kh1 The ceil() function rounds UP, so if you divide by a huge number, any positive number will be 1 (which is what we want), and any 0 or negative number will still be 0 or negative, so damage of 0 will be correct. If you can actually have negative numbers, things are a bit more complicated different, but it doesnt look like thats an issue.
1556632067
Mike deBoston
Compendium Curator
That doesn't prompt for net damage twice? How is that? That's a new trick to me. This will solve another dozen problems in the future. And rounding up, another new trick. I tested your first answer (with HTML entities), and it worked fine. Handling negative numbers isn't a requirement if the user types in damage. Wounds = [[ ?{Shaken|No,floor( ?{Net damage} /4)|Yes,{floor( ?{Net damage} /4),1}kh1}} ]] BUT, if I extend this to calculate net damage (prompt for rolled damage and target toughness), then extending the formula to handle negative numbers as you've shown will be important. I've posted the first answer to the Savage Worlds wiki page, and I'll post your second answer later. THANK YOU.
1556634540
GiGs
Pro
Sheet Author
API Scripter
You're welcome! Mike deBoston said: That doesn't prompt for net damage twice? How is that? That's a new trick to me. This will solve another dozen problems in the future. And rounding up, another new trick. When you use a query, it's like creating a variable in other programming languages. As long as the name is the same, it will use the same value in all other places in the macro. You also only need to use the full query once, in the first location. Any other places can just use the title. So if you have, say ?{Shaken|No,0|Yes,1} in the first position, you can reuse it with ?{Shaken} You must be careful to spell it correctly. I cant remember if case matters, but  ?{Shaken?|No,0|Yes,1} is not the same as  ?{Shaken|No,0|Yes,1} Hope this helps! :)
1556640951

Edited 1556641028
Mike deBoston
Compendium Curator
Mind blown. Queries create variables that can be reused within the script. Huh. With this I could even prompt for info in a logical order, instead of where needed by the calculations. Huh. Someday I'll have a pass at improving the Macro docs.
1556641375

Edited 1556641480
GiGs
Pro
Sheet Author
API Scripter
There's a great way to control the order of prompts. If you have a line starting with ! it isnt displayed to chat. So you could have a two line macro like !?{Net damage|0} Wounds = [[ ?{Shaken|No,floor( ?{Net damage} /4)|Yes,{floor( ?{Net damage} /4),1}kh1}} ]] This wont print out the first line, but will prompt users for damage first. You can include as many queries in that first line as you like. Though sometimes the structure of the script requires a certain order (you need that shaken query to be on the second line, I think), but barring rare situations like that, it gives you a lot of flexibility.
1556643101
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Mike deBoston said: Mind blown. Queries create variables that can be reused within the script. Huh. With this I could even prompt for info in a logical order, instead of where needed by the calculations. Huh. Someday I'll have a pass at improving the Macro docs. That's actually a Stupid Trick . :) If you haven't browsed that thread, there's tons of mind-blowing stuff in there.
1556644881
Mike deBoston
Compendium Curator
I've read that thread so many times . keithcurtis said: Mike deBoston said: Mind blown. Queries create variables that can be reused within the script. Huh. With this I could even prompt for info in a logical order, instead of where needed by the calculations. Huh. Someday I'll have a pass at improving the Macro docs. That's actually a Stupid Trick . :) If you haven't browsed that thread, there's tons of mind-blowing stuff in there.
1556685013
Mike deBoston
Compendium Curator
Thank you very much -- I feel like I just leveled up.