Take Damage Macro for 5th Edition

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
dorpond
RPTools Team
Posts: 5534
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Take Damage Macro for 5th Edition

Post by dorpond »

Hey gang, I have been busy trying to reworking my face to face framework for D&D 5.
It has been such a long time since I coded in Maptool, that I lost my proficiencies with it! :P

According to the rules, characters no longer go into the negatives when they take damage - it stops at 0. However, if they take damage = to their Max HP, then they are dead.

Can you please help me with my current Take Damage macro? It is probably something crazy simple.

Code: Select all

[H:success=input("Damage | "+0 +" | How much damage did you just take? | TEXT")]
[H:abort(success)]

[h: Thp=TempHP]
[h: DamAmt = max(0, Damage - TempHP)]
[h: TempHP = max(0, TempHP - Damage)]
[h: CurrentHP = CurrentHP - DamAmt]

[h:ShowBar = If(CurrentHP >= MaxHP,'setBarVisible("Green","off")','bar.Green=CurrentHP/MaxHP')] 
[h:eval(ShowBar)] 
[h:state.Bloodied = if(CurrentHP <= floor(MaxHP/2), 1, 0)]
[h:state.Dying = if(CurrentHP <= (0), 1, 0)]
[h:state.Dead = if(CurrentHP <= -floor(MaxHP), 1, 0)]

[r:token.name] just got hit for [r:Damage] damage and took [r:DamAmt] damage.<br>
Temporary HP was [r:Thp] and is now [r:TempHP]. <br>
[r:token.name] now has [r:CurrentHP] HP remaining.
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Take Damage Macro for 5th Edition

Post by aliasmask »

You could do something like this:

Code: Select all

[H: abort(input("Damage |0| How much damage did you just take? | TEXT"))]

[H, if(TempHP), code: {
   [H: temp.damage = min(TempHP,Damage)]
   [H: real.damage = Damage - temp.damage]
   [H: TempHP = TempHP - temp.damage]
};{
   [H: temp.damage = 0]
   [H: real.damage = Damage]
}]

[H: CurrentHP = CurrentHP - real.damage]
[H, if(CurrentHP <= -MaxHP): state.Dead = 1]
[H: CurrentHP = max(0,CurrentHP)]
[H, if(! CurrentHP && ! state.Dead): state.Dying = 1]
[H, if(CurrentHP < ceiling(MaxHP/2) && ! state.Dead && ! state.Dying): state.Bloodied]
[H, if(CurrentHP): bar.Green = CurrentHP/MaxHP; setBarVisible("Green",0)]

[R: strformat("%{token.name} was hit for %{Damage} damage.<br>")]
[R, if(temp.damage): strformat("%{temp.damage} was absorbed leaving %{TempHP} temp hitpoints remaining.<br>")]
[R: strformat("%{token.name} takes %{real.damage} and now has %{CurrentHP} hitpoints remaining.")]
 
edit: updated formula.

dorpond
RPTools Team
Posts: 5534
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Re: Take Damage Macro for 5th Edition

Post by dorpond »

You are a rock star, Aliasmask! Thank you!

I tested it out and it works, except, none of the temp hp stuff seems to work. When I add temp HP (4) to the token and then take some damage, all I get on the output is:

"PC Token was hit for 20 damage. PC Token takes 20 and now has 0 hitpoints remaining."

I also notice that the TempHP isn't subtracting at all - I still have 4 remaining after taking that 20 damage.

I'll look through the code to see if I can narrow it down, but if you can spot it quickly, I'd appreciate it.

Thank you for introducing another way of coding it too - some of this stuff I am not familiar with. Fun!

*edit*
So I did some more testing. Gave myself max HP of 16 and then gave 4 Temp.

Steps:
Using your macro, I take 4 damage, and I get this:
"PC Token was hit for 4 damage. PC Token takes 4 and now has 12 hitpoints remaining."
I look at my token properties, and it shows that I now have 12HP and 4 Temp. (incorrect)

Then I healed 1 HP
"PC Token healed for 1 HP and now has 13 HP."
Looking at the token properties, it does show 13HP and 4 Temp.

Then I take 1 damage using your macro again.
"PC Token was hit for 1 damage. 3 was absorbed leaving 1 temp hitpoints remaining. PC Token takes -2 and now has 15 hitpoints remaining."
Looking at the token properties, I now have 15HP and 1 Temp (incorrect)

So something is really screwy and I looked, but can't put my finger on it.
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Take Damage Macro for 5th Edition

Post by wolph42 »

In most cases when something goes haywire in your code while also using token properties is accidental change of token properties by using it as a var inside the code. Now am is pretty strict on this matter so I'm not sure it's actually relevant, but it helps to ALWAYS use identifiers for local (so inside the macro) variables. I usually use loc. e.g. loc.HP, loc.Strenth, etc. you might want to go through your code and check whether all local vars comply with this.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Take Damage Macro for 5th Edition

Post by aliasmask »

Yeah, my formula is wrong. temp.damage should be temp.damage = min(TempHP,Damage) which is either all of what's left of TempHP or Damage, whichever is smaller.

dorpond
RPTools Team
Posts: 5534
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Re: Take Damage Macro for 5th Edition

Post by dorpond »

Thank you so much, AliasMask!
That works like a charm!

I owe you ;)
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

dorpond
RPTools Team
Posts: 5534
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Re: Take Damage Macro for 5th Edition

Post by dorpond »

wolph42 wrote:In most cases when something goes haywire in your code while also using token properties is accidental change of token properties by using it as a var inside the code. Now am is pretty strict on this matter so I'm not sure it's actually relevant, but it helps to ALWAYS use identifiers for local (so inside the macro) variables. I usually use loc. e.g. loc.HP, loc.Strenth, etc. you might want to go through your code and check whether all local vars comply with this.
Yeah, wolph42, there is no doubt that I am a hack when it comes to macros. I get it working just enough for my games and that is as far as it goes. Makes for difficult troubleshooting afterwards, unfortunately...

Thanks for the advice!
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

User avatar
JayIbero
Cave Troll
Posts: 28
Joined: Tue May 18, 2010 10:40 am

Re: Take Damage Macro for 5th Edition

Post by JayIbero »

Here's one I developed from someone else's more basic damage and healing macro that accounts for automatic death from massive damage as well as tracking death saving throws accumulated due to damage while at 0. It also will not heal past full or reduce HP below 0. You will need to have a few states, bars, and properties setup to work with it though. I'm sure it's probably not the most efficient way to do it, but it works for me.

Code: Select all

[h:status = input("hpChange|0|Number of Hit Points","dmgOrHealing|Damage,Healing,Temp|Is the character taking damage, being healed, or gaining temporary hit points?|RADIO|SELECT=0")]
[h:abort(status)]

[h:DSHP = CurrentHP]
    [h:damage = hpChange]
    [h:diff1 = hpChange - CurrentHP - TempHP
]


[if(dmgOrHealing == 0),CODE:
{
    
    [if(hpChange <= TempHP),CODE:
    {
       [h:tempChange = hpChange]
       [h:TempHP = TempHP - hpChange]
       [h:hpChange = 0]
    };{}]
    [if(hpChange > TempHP),CODE:
    {
       [h:tempChange = TempHP]
       [h:hpChange = hpChange - TempHP]
       [h:TempHP = 0]
    };{}]

    [h:CurrentHP = max(0,CurrentHP - hpChange)]
    [h:bar.Health_Jay5e = CurrentHP / MaxHP]
    <b>[r:token.name]</b> takes [r:damage] damage.<br>
    <b>[r:token.name]</b> loses [r:hpChange] hit points and [r:tempChange] temporary hit points.
    [If(diff1 >= MaxHP), code:
{
<b><br>[r:token.name] dies from massive damage!</b>
[h:state.Dead=1]
};{}]

[if(DSHP <= 0),code:
{
[h:status2 = input(
"CritCheck|0|Damage caused by critical hit?|CHECK"
)]
[h:abort(status2)]
[h: DSfail = DSfail + 1 + CritCheck]
 <br><b>[r:token.name]</b> gains [r:1 + CritCheck] failed death saving throws
[h: state.1st_Failed_Death_Save=1]
[h: state.2nd_Failed_Death_Save=if(DSfail > 1, 1, 0)]
};{}]

[if(DSfail >=3),code:
{
<br><b>[r:token.name]</b> has failed 3 death saving throws and dies!
[h:state.Dead=1]
};{}]
[h: state.Stabilized=0]
};{}]

[if(dmgOrHealing == 1),CODE:
{
    [h:diff2 = MaxHP - 
CurrentHP]
    [h:CurrentHP = min(
CurrentHP+hpChange, MaxHP)]
    [h:bar.Health_Jay5e = 
CurrentHP / MaxHP]
    <b>[r:token.name]</b> is healed and gains  [r:min(diff2,hpChange)] hit points. 
[h: DSsuccess = 0]
[h: DSfail = 0]
[h: state.1st_Failed_Death_Save=0]
[h: state.2nd_Failed_Death_Save=0]
[h: state.Stabilized=0]
};{}]

[if(dmgOrHealing == 2),CODE:
{
    [h:TempHP = Max(hpChange,TempHP)]
    <b>[r:token.name]</b> has [r:TempHP] temporary hit points.
};{}]

[h:state.Dying=if(CurrentHP <= 0, 1, 0)]
[h:state.Bloodied=if(CurrentHP <= MaxHP / 2, 1, 0)]
[if(CurrentHP > 0),code:
{
[h:state.Dead=0]
};{}]

Post Reply

Return to “Macros”