• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[Solved] Health and mana restoration on levelup

Status
Not open for further replies.
Level 8
Joined
Mar 12, 2008
Messages
437
Instead of having HP and mana healed when a hero levels up (or when a unit receives a HP/MP bonus in general, I assume), I want the percentage to remain constant. Found nothing in gameplay constants. How to?
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Are you talking about the "default" HP/MP "healed" by Warcraft III Games when your Hero levels up ?

It is not a form of "healing", it's just that Hero has attribute that is called as Strength and if your Hero has an increment of Strength by greater than or equal to 1 when level up, it will adjust your HP Percentage accordingly, not "heal" you exactly.

For example;
Current Hero HP: 400/1000
Hero levels up: Each level up gains 3 Strength; each Strength gives +17 HP
Current Hero HP: 400/1000 + (17 * 3) = 451/1051

This is the mechanics, so what do you want to do exactly ?

You can also modify it via trigger to;
  • Melee Initialization
    • Events
      • Unit - A unit Gains a level
    • Conditions
    • Actions
      • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 50.00)
Trigger above will "heal" Hero by 50 upon level up

You can also "heal" it by percentage;
  • Melee Initialization
    • Events
      • Unit - A unit Gains a level
    • Conditions
    • Actions
      • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + (0.10 x (Max life of (Triggering unit))))%
Trigger above will "heal" Hero by 10% of its Max HP upon level up
 
Level 8
Joined
Mar 12, 2008
Messages
437
Are you talking about the "default" HP/MP "healed" by Warcraft III Games when your Hero levels up ?

Yes, that's it. As edo494 said, 451/1051 is a larger percentage than 400/1000, so the hero will actually be healed. What I want is to retain the percentage health; in this case it would be 420/1051, so that it equals the 40% it had before leveling.

Now that I know the mechanics, adjusting the HP shouldn't be too hard, but the tricky part is to detect every strength bonus. I assume using a periodic trigger would be the easiest.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
What you really meant was;
400/1000
Hero levels up
400/1051

Is this what you meant ?
To retain the HP ?

but the tricky part is to detect every strength bonus
What do you meant by this ?
The Strength per level, and X bonus HP per Strength are all set in Gameplay Constants, so there would be no problem as you define them yourselves, you have the power.

Why the need of periodic trigger by the way ?
 
Level 8
Joined
Mar 12, 2008
Messages
437
What you really meant was;
400/1000
Hero levels up
400/1051

Is this what you meant ?
To retain the HP ?

No, retain the HP percentage. This is what I want:

400/1000 = 40%
Hero levels up
420/1051 = 40%

What do you meant by this ?
The Strength per level, and X bonus HP per Strength are all set in Gameplay Constants, so there would be no problem as you define them yourselves, you have the power.
My heroes don't have integers (whole numbers) as Strength per level. For example, if your strength per level is 1.5, it will alternate between gaining 1 str and 2 str.

Why the need of periodic trigger by the way ?

I assume this will be the easiest way to detect a HP changes, since it can happen in many ways. Level up, items, upgrades, etc.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240

  • Untitled Trigger 029
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set hash = (Last created hashtable)
      • -------- -------------------- --------
      • -------- HP per STR --------
      • -------- -------------------- --------
      • Custom script: call SaveReal(udg_hash, StringHash("STRHP"), 0, 25)
      • -------- -------------------- --------
      • -------- STR per level for Paladin (Hpal) --------
      • -------- -------------------- --------
      • Custom script: call SaveReal(udg_hash, 'Hpal', 0, 2.7)
      • -------- -------------------- --------
  • Untitled Trigger 016
    • Events
      • Unit - A unit Gains a level
    • Conditions
    • Actions
      • Set u = (Triggering unit)
      • Custom script: set udg_r1 = LoadReal(udg_hash, GetUnitTypeId(udg_u), 0)
      • Custom script: set udg_r2 = LoadReal(udg_hash, StringHash("STRHP"), 0)
      • Set r3 = (Real(((Hero level of u) - 1)))
      • Set r3 = (Real(((Integer((r3 x r1))) - (Integer(((r3 - 1.00) x r1))))))
      • Set r3 = (r3 x r2)
      • Unit - Set life of u to (((Max life of u) x ((Life of u) - r3)) / ((Max life of u) - r3))


Let me know if you need it in a map file.
 
Level 8
Joined
Mar 12, 2008
Messages
437
Thanks, that looks good.

Implemented it, doesn't work...
  • Events
    • Map initialization
  • Actions
    • Hashtable - Create a hashtable
    • Set H = (Last created hashtable)
    • Custom script: call SaveReal(udg_H, StringHash("STRHP"), 0, 4)
    • Custom script: call SaveReal(udg_H, StringHash("INTMP"), 1, 8)
    • Custom script: call SaveReal(udg_H, 'O002', 0, 0.6)
    • Custom script: call SaveReal(udg_H, 'O002', 1, 0.65)
^ examples for one of the heroes
  • HeroHP fix
    • Events
      • Unit - A unit Gains a level
    • Conditions
    • Actions
      • Set U[1] = (Triggering unit)
      • -------- LIFE --------
      • Custom script: set udg_R[1] = LoadReal(udg_H, GetUnitTypeId(udg_U[1]), 0)
      • Custom script: set udg_R[2] = LoadReal(udg_H, StringHash("STRHP"), 0)
      • Set R[3] = (Real(((Hero level of U[1]) - 1)))
      • Set R[3] = (Real(((Integer((R[3] x R[1]))) - (Integer(((R[3] - 1.00) x R[1]))))))
      • Set R[3] = (R[2] x R[3])
      • Unit - Set life of U[1] to (((Max life of U[1]) x ((Life of U[1]) - R[3])) / ((Max life of U[1]) - R[3]))
      • -------- MANA --------
      • Custom script: set udg_R[1] = LoadReal(udg_H, GetUnitTypeId(udg_U[1]), 1)
      • Custom script: set udg_R[2] = LoadReal(udg_H, StringHash("INTMP"), 1)
      • Set R[3] = (Real(((Hero level of U[1]) - 1)))
      • Set R[3] = (Real(((Integer((R[3] x R[1]))) - (Integer(((R[3] - 1.00) x R[1]))))))
      • Set R[3] = (R[2] x R[3])
      • Custom script: call SetUnitManaBJ( udg_U[1], ( ( GetUnitStateSwap(UNIT_STATE_MAX_MANA, udg_U[1]) * ( GetUnitStateSwap(UNIT_STATE_MANA, udg_U[1]) - udg_R[3] ) ) / ( GetUnitStateSwap(UNIT_STATE_MAX_MANA, udg_U[1]) - udg_R[3] ) ) )

I'm quite sure I copied everything correctly (not entirely sure about the mana bit, but otherwise yes). Nevertheless, it neither worked before I added the mana parts.
 
Status
Not open for further replies.
Top