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

Using Token-mod for Healing Potion Macro

I found this that Aaron posted a while back on using Token-mod for a Healing Potion macro:

!token-mod {{
  --set
    bar1_value|[[{@{target|Target|bar1}+2d4+2, @{target|Target|bar1|Max}d1}kl1]]
  --report
    all|"{name} takes a healing potion and regains {bar1_value:change}hp."
    gm:control|"{name} change: {bar1_value:before}hp -> {bar1_value}hp (+{bar1_value:before}hp)"
  --ids
    @{target|Target|token_id}
}}

One, this sort of works.  The health bar change works and doesn't exceed hp_max, but the text is wrong. I tried to update it so that the hp change text was correct and to also remove the requirement to select a target and instead just apply the changes to the currently selected token.  But I'm failing miserably.  Can someone help point out what I'm doing wrong here?

!token-mod {{
  --set
    bar1_value|[[{{bar1_value}+2d4+2, {bar1|Max}d1}kl1]]
  --report
    all|"{name} takes a healing potion and regains [[{{bar1_value}-{bar1_value:before}}]]hp."
    gm:control|"{name} hp change: {bar1_value:before} -> {bar1_value} (+[[{{bar1_value}-{bar1_value:before}}]])"

}}
June 12 (4 years ago)

This should work:

!token-mod {{
  --set
    bar1_value|[[{{@{selected|bar1_value}+2d4+2, @{selected|{bar1|Max}d1}kl1]]
 --report
    all|"{name} takes a healing potion and regains [[{{bar1_value}-{bar1_value:before}}]]hp."
    gm:control|"{name} hp change: {bar1_value:before} -> {bar1_value} (+[[{{bar1_value}-{bar1_value:before}}]])"
}}
June 12 (4 years ago)

Edited June 12 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

I've actually made this a bit easier, try:

!token-mod {{
  --set
    bar1_value|+[[2d4+2]]!
 --report
    all|"{name} takes a healing potion and regains {bar1_value:abschange}hp."
    gm:control|"{name} hp change: {bar1_value:before} -> {bar1_value} (+{bar1_value:abschange}hp)"
}}

The ! on the end of the adjustment tells it to bound it to the range of the bar being changed. 

June 12 (4 years ago)

Edited June 12 (4 years ago)

Excellent!  Thanks guys.  I did try @{selected, but I guess I didn't have the syntax correct.  But Aaron's ! to limit the change to the bar max automatically and the abschange works to show the delta.  Much appreciated!  The token-mod part of this macro works great now. 

I've added the resource reduction and a message to show how many are left. 

!modattr --silent --name @{selected|token_name} --repeating_resource_$0_resource_right|-1
!token-mod {{
  --set
    bar1_value|+[[2d4+2]]!
 --report
    all|"{name} takes a healing potion and regains {bar1_value:abschange}hp."
    gm:control|"{name} hp change: {bar1_value:before} -> {bar1_value} (+{bar1_value:abschange}hp)"
}}
/w gm @{selected|token_name} has [[@{selected|repeating_resource_$0_resource_right}-1]] healing potions left

Now, is there any way to check whether the current resource value is >0 (meaning they have a potion to take)? Like adding a 

if @{selected|repeating_resource_$0_resource_right}>0 then

I see that chatsetattr has the --evaluate flag which may accomplish this.  Or would this just have to be manually monitored through the resource quantity output?