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

How can I use TokenMod to adjust bar1 by a roll but to a maximum result?

Roll20, I am attempting to script a parry that a token makes to ward off damage that already received damage by a different macro. To this end, I was thinking of using !tokenmod to adjust bar1 by a roll but only up to a maximum result. Like 1d8(max4). The following will not work because if damage taken is above the perry it will heal the token. Does anyone have an idea as to how to do this? !token-mod {{   --set bar1_value|[[{@{selected|bar1}+floor(1d8+@{Selected|Dexterity_Mod}-?{How much damage was inflicted by the attack|0}),@{selected|bar1|max}+0d0}kl1]]  --report     all|"{name} ***perries {bar1_value:abschange} hit points of damage!***"     gm|"{name} has {bar1_value}/{bar1_max} hp"   --ids @{selected|token_id}  }} Thank you!!!
1625949896

Edited 1625955940
The Aaron
Roll20 Production Team
API Scripter
Something like this: !token-mod {{ --set bar1_value|+[[{(1d8+@{Selected|Dexterity_Mod}),?{How much damage was inflicted by the attack|0}d1}kl1]]! --report all|"{name} ***parries {bar1_value:abschange} hit points of damage!***" gm|"{name} has {bar1_value}/{bar1_max} hp" --ids @{selected|token_id} }} You can simplify the set by using the + for a relative change and the ! on the end to tell it not to go over the bar max.  The { , }kl1 will prevent it from being larger than whatever number is typed into the query.
Aaron, when I test this macro, nothing seems to happen at all...
1625955929
The Aaron
Roll20 Production Team
API Scripter
Ah, I fixed it in the above, was missing d1 for the second half of the group.  Something I've noticed over the years is that some errors are shown in the console log instead of the chat window.  If you run something and it appears to do nothing, look in the console log and you'll usually see the error!
It works! Good to know about the console log. Thank you Aaron! With your help, I am a geologist who is slowly learning to program :D
1625965945
The Aaron
Roll20 Production Team
API Scripter
Lol. =D. Just consider yourself a diamond in the rough, I suppose. =D