• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Structure Health Upgrade/Advancement (Retain Current Health + Upgrade/Advancement)

Level 3
Joined
Dec 29, 2019
Messages
15
Situation: I have a structure that has health upgrade and advancement. The structure does not have a regeneration or repair feature.

Problem: I want the health upgrade to add with the current health, the issue sometimes it does, sometimes it does not and sometimes it add but less the value of the upgrade. I want it to be consistent and to be the exact value.

Let's say my Structure has 1 current HP and a max of 6 HP, so 1/6.
It has an upgrade (3 stage/level), which would add +1 max HP adding up to +3 max HP.
So, what I want is, after the upgrade (which is +1 max hp) it should have 2/7 health, adding both to current and max HP.
But it does not, it stays 1/7, 1/8, and it did increase its current to 2/9 health after the third upgrade which is I don't understand.
It seems inconsistent.

I could just probably +1 current hp per upgrade, but the problem is with that... it does increase the current hp randomly.
So, it could work most of times but if that randomly occurs it would add +2 current hp instead, which is not okay.

Another problem on top of that, so the structure has now upgraded its health to 2/9.
It also has an advancement which would change its max health to 10.
It's just adding another 1 max HP, but no... after the advancement, the 2/9 HP would turn to 5/10 HP.

Afterword: I admit that I have a lack of knowledge regarding this, maybe I just need to configure some constant or in object editor, or probably need to resort to triggering. But I don't know where to look first so I ask for help, thank you whomever you are that is reading this!
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,877
When you increase the Max HP of a unit, it's current HP is not increased at all. These are two separate stats. The reason current HP would increase or decrease when Max HP is adjusted is because it needs to change to reflect the unit's current Percentage HP.

For example:
When your unit has 1/6 HP, it's current HP Percentage is equal to ~16% (1/6 = 0.16).
When your unit gains +1 max HP, the current HP updates to reflect 16% of 7 which is 1.12. So you only gain around 0.12 HP, not 1.00.

Then Warcraft 3 converts Reals to Integers for the intent of displaying them on the UI, which can introduce rounding and other oddities. A unit with 0.80 HP will show up as having 1 HP in it's UI text, because the alternative would be to display 0 which wouldn't make any sense.

But a possible solution to your problem would be to trigger the life increase:
  • Events
    • Unit - A unit Finishes an upgrade
  • Conditions
  • Actions
    • Set Variable MyUnit = (Triggering unit)
    • Set Variable CachedLife = (Life of UNIT)
    • Unit - Set Max HP of MyUnit to (Max HP of MyUnit + 1)
    • Unit - Set life of MyUnit to (CachedLife + 1.00)
 
Last edited:
Level 3
Joined
Dec 29, 2019
Messages
15
When you increase the Max HP of a unit, it's current HP is not increased at all. These are two separate stats. The reason current HP would increase or decrease when Max HP is adjusted is because it needs to change to reflect the unit's current Percentage HP.

For example:
When your unit has 1/6 HP, it's current HP Percentage is equal to ~16% (1/6 = 0.16).
When your unit gains +1 max HP, the current HP updates to reflect 16% of 7 which is 1.12. So you only gain around 0.12 HP, not 1.00.

Then Warcraft 3 converts Reals to Integers for the intent of displaying them on the UI, which can introduce rounding and other oddities.

But a possible solution to your problem would be to trigger the life increase:
  • Events
    • Unit - A unit Finishes an upgrade
  • Conditions
  • Actions
    • Set Variable MyUnit = (Triggering unit)
    • Set Variable CachedLife = (Life of UNIT)
    • Unit - Set Max HP of MyUnit to (Max HP of MyUnit + 1)
    • Unit - Set life of MyUnit to (CachedLife + 1.00)
Thank you for the fast response!

That is a clear explanation, I think I understand now.
Off to editor now.

UPDATE: For Future Reference
That trigger works perfectly, though it took me a while to realize that those triggered max health + carry over to advancement.
So, that +# Max HP adds up to the new max hp of the unit that has advanced.

So, if your unit have 10/10 unit which has 20/20 (+10) max hp upgrade (via that trigger).
And your advancement unit has 20/20 himself, it would turn to 30/30 instantly after advancing since the +10 max hp from before carries over.


[SOLVED]
 
Last edited:
Level 45
Joined
Feb 27, 2007
Messages
5,578
You could resolve that issue by tracking the upgrade event and then manually resetting the hp of the units. Don't even need to cache a table of various base HPs, just spawn a new copy of the unit, check its max hp, set the upgrading unit's HP to that, and then remove the bonus unit.
 
Top