• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Health Regeneration based on missing health

Status
Not open for further replies.
Level 7
Joined
Feb 23, 2020
Messages
253
Hello!
Is there a way to make an ability for a unit that increases its health regeneration based on each 1% of its missing life?

Thanks in advance.
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
If you want to increase its total health regen by some percentage, it will be pretty difficult as there is no way to directly query what a unit's current HP regen is (attributes, items, other abilities, blight, etc. might change from the default unit regen set in the OE). If it should be something like "unit gains 0.05 hp/s for each 1% health missing" then yes it can be done much more simply.
 
Level 7
Joined
Feb 23, 2020
Messages
253
If you want to increase its total health regen by some percentage, it will be pretty difficult as there is no way to directly query what a unit's current HP regen is (attributes, items, other abilities, blight, etc. might change from the default unit regen set in the OE). If it should be something like "unit gains 0.05 hp/s for each 1% health missing" then yes it can be done much more simply.

Yes that is what i mean, maybe i explained myself bad. But how do you do that? Still quite a beginner with triggers :p
 
Level 7
Joined
Feb 23, 2020
Messages
253
Regen Learn
Events
Unit - A unit Begins casting an ability
Conditions
(Ability being cast) Equal to Regen
Actions
Trigger - Turn on Rage Regen <gen>

Rage Regen
Events
Time - Every 1.00 seconds of game time
Conditions
Actions
Set VariableSet TempReal = (TempReal + 1.00)
Unit - Set life of RegenUnit to TempReal%

This is what i did, but it doesnt work. I also tried this:

Rage Learn
Events
Unit - A unit Learns a skill
Conditions
(Learned Hero Skill) Equal to Regen
Actions
Trigger - Turn on Rage Regen <gen>

But it doesnt work either :/
 
Level 7
Joined
Feb 23, 2020
Messages
253
Rage Learn
Events
Unit - A unit Learns a skill
Conditions
(Learned Hero Skill) Equal to Wind Walk
Actions
Trigger - Turn on Rage Regen <gen>


Rage Regen
Events
Time - Every 0.50 seconds of game time
Conditions
Actions
Set VariableSet TempReal = (TempReal + 200.00)
Set VariableSet RegenUnit = (Learning Hero)
Unit - Set life of RegenUnit to TempReal%


This is what i've done but it does not work, what am i doing wrong?
 
Level 6
Joined
Dec 31, 2017
Messages
138
Try something like this

Rage Learn
Events
Unit - A unit Learns a skill
Conditions
(Learned Hero Skill) Equal to Wind Walk
Actions
Trigger - Turn on Rage Regen <gen>
Add (Triggering unit) to Rage_regen_group


Rage Regen
Events
Time - Every 0.50 seconds of game time
Conditions
Actions
For every unit in Rage_regen_group do {
Set VariableSet TempReal = (TempReal + 200.00)
Set VariableSet RegenUnit = (Learning Hero)(Picked unit)
Unit - Set life of RegenUnit to TempReal%
}

This will try to set every hero's (that learned the ability) health to 200%, 400%, 600% and so on every half second.
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
The previous one, i want it to be like a passive, not an active ability.

If you want to increase its total health regen by some percentage, it will be pretty difficult as there is no way to directly query what a unit's current HP regen is (attributes, items, other abilities, blight, etc. might change from the default unit regen set in the OE).
If it should be something like "unit gains 0.05 hp/s for each 1% health missing" then yes it can be done much more simply.
These are both passive abilities that work in different ways.
 
Level 7
Joined
Feb 23, 2020
Messages
253
Try something like this

Rage Learn
Events
Unit - A unit Learns a skill
Conditions
(Learned Hero Skill) Equal to Wind Walk
Actions
Trigger - Turn on Rage Regen <gen>
Add (Triggering unit) to Rage_regen_group


Rage Regen
Events
Time - Every 0.50 seconds of game time
Conditions
Actions
For every unit in Rage_regen_group do {
Set VariableSet TempReal = (TempReal + 200.00)
Set VariableSet RegenUnit = (Learning Hero)(Picked unit)
Unit - Set life of RegenUnit to TempReal%
}

This will try to set every hero's (that learned the ability) health to 200%, 400%, 600% and so on every half second.


The ability works now! Thank you so much for that, but when i learn it, the heros HP it set to that percentage that i chose, I.E (TempReal + 1), and also. Other abilities for this hero have HP as resource, so when he uses it, it somehow uses that HP as resource, and then it pops back to its HP as it was before using the ability.
 
Last edited:
Level 6
Joined
Dec 31, 2017
Messages
138
Well, it comes from the way you "heal" your unit.

TempReal isn't nullified between iterations, so it steadely grows from 0 to infinity.

You should set life of your unit to current life of your unit plus something.
for example set TempReal = CurrentLifePercent + 5(1-(CurrentLifePercent)/100)
this will heal 5% of total life (every 0.5 sec) when unit is nearly dead and heal nothing when its's not damaged.
 
Level 7
Joined
Feb 23, 2020
Messages
253
Well, it comes from the way you "heal" your unit.

TempReal isn't nullified between iterations, so it steadely grows from 0 to infinity.

You should set life of your unit to current life of your unit plus something.
for example set TempReal = CurrentLifePercent + 5(1-(CurrentLifePercent)/100)
this will heal 5% of total life (every 0.5 sec) when unit is nearly dead and heal nothing when its's not damaged.

How do you find "CurrentLifePercent + 5(1-(CurrentLifePercent)/100)"?
Im kind of a rookie, sorry for all the questions :p
 
Level 6
Joined
Dec 31, 2017
Messages
138
There is a function to do it: Screenshot

No problem, but I strongly recomend finding such functions on your own.
At least spend some time trying to do so.

Most of the time you'll be fine just choosing the most convinient option at each step.
And even if you didn't succeed, some idea of availible functions could help in the furure.
 
Level 7
Joined
Feb 23, 2020
Messages
253
There is a function to do it: Screenshot

No problem, but I strongly recomend finding such functions on your own.
At least spend some time trying to do so.

Most of the time you'll be fine just choosing the most convinient option at each step.
And even if you didn't succeed, some idea of availible functions could help in the furure.

Yeah thanks a lot man! Been trying to create a lot of things by own but some parts i get really stuck with. I did find that, but i thought it was a function that was "currentlifepercent", is that a variable of some sort?
 
Level 7
Joined
Feb 23, 2020
Messages
253
No, I ment "Unit - Percentage Life of (Picked unit)". It just seemed a little bit too long to use in a sentence.

I almost figured it out with these variables:


Actions
-------- Closest to work, but works in reverse --------
Set VariableSet TempReal = ((Percentage life of (Picked unit)) + (1.00 - (1.00 - ((Life of (Picked unit)) / 100.00))))

-------- This work, but just to a certain amount of health. --------
Set VariableSet TempReal = (((Percentage life of (Picked unit)) + 1.00) + (1.00 - ((Life of (Picked unit)) / 100.00)))

-------- This work, but just as an ordinary regen, doesnt increase on lower health --------
Set VariableSet TempReal = (((Percentage life of (Picked unit)) + 1.00) + (1.00 - ((Life of (Picked unit)) / (Max life of (Picked unit)))))

But still, i cant seem to make it so that its barerly noticeabe at high hp, and much stronger on low hp.
 
Level 6
Joined
Dec 31, 2017
Messages
138
-------- Closest to work, but works in reverse --------
Set VariableSet TempReal = ((Percentage life of (Picked unit)) + (1.00 - (1.00 - ((Life of (Picked unit)) / 100.00))))
let p = ((Percentage life of (Picked unit)) to make it easier to read

You want to set health of your unit to
p + r*f where r is max regeneration rate, f is factor that equals 0 when unit is at full health and equals 1 when unit at 0 health.

I suggest f = (1 - p/100), so if r = 1.00

TempReal = p + r*(1 - p/100) = ((Percentage life of (Picked unit)) + 1.00 - (((Percentage life of (Picked unit)) / 100)
 
Level 7
Joined
Feb 23, 2020
Messages
253
let p = ((Percentage life of (Picked unit)) to make it easier to read

You want to set health of your unit to
p + r*f where r is max regeneration rate, f is factor that equals 0 when unit is at full health and equals 1 when unit at 0 health.

I suggest f = (1 - p/100), so if r = 1.00

TempReal = p + r*(1 - p/100) = ((Percentage life of (Picked unit)) + 1.00 - (((Percentage life of (Picked unit)) / 100)

It works correctly if its for each 1%, thank you so much! :) But say if i'd want the ability to have levels, I.E:
Level 1: 1%
Level 2: 2%
What number do i change if i want to change that? Been trying to change every "1" there is, but then it just works as an ordinary % of max hp regen.
 
Last edited:
Level 6
Joined
Dec 31, 2017
Messages
138
What number do i change if i want to change that? Been trying to change every "1" there is, but then it just works as an ordinary % of max hp regen.
You should change r

((Percentage life of (Picked unit)) + 2*(1.00 - (((Percentage life of (Picked unit)) / 100)) = ((Percentage life of (Picked unit)) + 2.00 - 2*(((Percentage life of (Picked unit)) / 100) = ((Percentage life of (Picked unit)) + 2.00 - (((Percentage life of (Picked unit)) / 50)
 
Status
Not open for further replies.
Top