• 🏆 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] Less HP more Armor?

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2011
Messages
460
Create a system that checks ranges of hp and apply a custom "Devotion Aura" spell to the unit in a 0.0 radius and compare the missing hp like

If Unit's Current HP is less than or equal to Unit's Max HP and If Unit's Current HP is Greater than or equal to (Unit's Max HP * .9) then check if unit has the ability (just for iteration, you can loop this if you do more work on it) and then set the level to the % range HP missing.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Set real = Max life of unit / Current life of unit
If real <= 10 then
set lvl of YourArmorGivingAbility = real.

That can be a 1 Seg periodic event with units that have that ability in a loop. Or trigger on Damage dealt with a damage detection system.

If "set lvl of YourArmorGivingAbility = real." doesn't work then "set lvl of YourArmorGivingAbility = Convert Real to Integer(real)". The game will round the value.
 
Level 15
Joined
Jan 27, 2007
Messages
948
Taking your ideas I worked something out. Check it please; I'd like to know if this is MUI and leakless! thanks for the help guys !

  • Berserking Armor
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer I) from 1 to 8, do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units of type Berserker) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Percentage life of (Picked unit)) Less than or equal to 10.00
                • Then - Actions
                  • Unit - Set level of Berserking Armor for (Picked unit) to 10
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Percentage life of (Picked unit)) Greater than or equal to 10.01
                      • (Percentage life of (Picked unit)) Less than or equal to 20.00
                    • Then - Actions
                      • Unit - Set level of Berserking Armor for (Picked unit) to 9
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Percentage life of (Picked unit)) Greater than or equal to 20.01
                          • (Percentage life of (Picked unit)) Less than or equal to 30.00
                        • Then - Actions
                          • Unit - Set level of Berserking Armor for (Picked unit) to 8
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Percentage life of (Picked unit)) Greater than or equal to 30.01
                              • (Percentage life of (Picked unit)) Less than or equal to 40.00
                            • Then - Actions
                              • Unit - Set level of Berserking Armor for (Picked unit) to 7
                            • Else - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • (Percentage life of (Picked unit)) Greater than or equal to 40.01
                                  • (Percentage life of (Picked unit)) Less than or equal to 50.00
                                • Then - Actions
                                  • Unit - Set level of Berserking Armor for (Picked unit) to 6
                                • Else - Actions
                                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    • If - Conditions
                                      • (Percentage life of (Picked unit)) Greater than or equal to 50.01
                                      • (Percentage life of (Picked unit)) Less than or equal to 60.00
                                    • Then - Actions
                                      • Unit - Set level of Berserking Armor for (Picked unit) to 5
                                    • Else - Actions
                                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                        • If - Conditions
                                          • (Percentage life of (Picked unit)) Greater than or equal to 60.01
                                          • (Percentage life of (Picked unit)) Less than or equal to 70.00
                                        • Then - Actions
                                          • Unit - Set level of Berserking Armor for (Picked unit) to 4
                                        • Else - Actions
                                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                            • If - Conditions
                                              • (Percentage life of (Picked unit)) Greater than or equal to 70.01
                                              • (Percentage life of (Picked unit)) Less than or equal to 80.00
                                            • Then - Actions
                                              • Unit - Set level of Berserking Armor for (Picked unit) to 3
                                            • Else - Actions
                                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                • If - Conditions
                                                  • (Percentage life of (Picked unit)) Greater than or equal to 80.01
                                                  • (Percentage life of (Picked unit)) Less than or equal to 90.00
                                                • Then - Actions
                                                  • Unit - Set level of Berserking Armor for (Picked unit) to 2
                                                • Else - Actions
                                                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                    • If - Conditions
                                                      • (Percentage life of (Picked unit)) Greater than or equal to 90.01
                                                      • (Percentage life of (Picked unit)) Less than or equal to 99.99
                                                    • Then - Actions
                                                      • Unit - Set level of Berserking Armor for (Picked unit) to 2
                                                    • Else - Actions
                                                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                        • If - Conditions
                                                          • (Percentage life of (Picked unit)) Equal to 100.00
                                                        • Then - Actions
                                                          • Unit - Set level of Berserking Armor for (Picked unit) to 1
                                                        • Else - Actions
Also if you have any better ideas tell me!
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
As already said...

  • Berserker Group
    • Events
      • A Unit enters (Playable map area)
    • Conditions
      • Unit-Type of (Triggering Unit) equal to Berserker
    • Actions
      • Unit - Add (Triggering Unit) to BerserkerGroup
  • Berserking Armor
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in BerserkerGroup and do (Actions)
        • Loop - Actions
          • Set TUnit = (Picked Unit)
          • Set RealVariable = ((100.00 - Percentaje Life of TUnit) / 10) <-- Just an example.
          • Unit - Set level of Berserking Armor for TUnit to (Convert Real to Integer (RealVariable))
The formula is on the "Real Variable" You don't need anything else. Just create the formula that becomes 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 based on the unit HP. The game will convert it to a integer and set the ability level to that.

Sorry, I don't have time right now to think about it, but I know for sure that this is a much better way than your if/then/else chain.

Converting the Real to an Integer will remove the decimals leaving it as a whole number, an integer. Ability levels are Integers. I'm not sure if WC rounds the Reals up or down... But it works anyway.

It's MUI, it's Leakless, you just require that RealVariable (can have any name, and you replace it in the Custom script If udg_YourRealVariableName.
 
the math is wrong... Real variable should 10*[[(Life of unit)/(Max life of unit)] + 0.5]...

because at 483 hp which is less than 50%, the ability should already be giving 5 armor, not 2, so the ability should be level 5...

wc3 rounds down when converting real to integer... so adding the 0.5 will ensure that if the decimal is at least .5, it will be rounder "up"

483*10/1000 = 4.83 --> 4

483*((10/100) + 0.5) = 5.33 --> 5
 
  • Set Real_BA = (10.0 x (((Life of TUnit)/(Max life of TUnit)) + 0.50)))
You should divide the life value first before adding the 0.5... the one you posted, added the 0.5 to the max life of TUnit...

oh wait... I think it should be...

  • Set Real_BA = (10.0 x ((((Max life of TUnit) - (Life of TUnit))/(Max life of TUnit)) + 0.50)))
because it should increase with increasing missing life value...
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
¡THAT's THE WAY! I didn't even test the formula, but the right way is testing by yourself and trying with different ways to achieve what you want. ¡Congratulations!

You don't need an specific real variable for this. You can use either a Temporal real variable or a local. Actually, the main idea is to convert this later to Jass and use locals (Several of us can help you with that and it's pretty easy).

I found an easier way to do it; I tested it and it works, look:

Set Real_BA = (11.00 - ((Percentage life of (Picked unit)) / 10.00))

let's say we have 70% life:

11 - 70 / 10
11 - 7
4

And I guess that the ability is level 4, but at lvl 1 it gives 0 armor... right?

Actually the ability should give it's max armor (10) when the unit has 10% hp, since having the ability at max level when the percentage of life is 0% isn't quite usefulll.

Ability should have 10 levels, begin at level 1 giving 0, then you can give 1.1, 2.2, 3.3. ,4.4, 5.5, 6.6, 7.7, 8.8, 9.9.... or start the ability at lvl 2 with 2 armor already, then 3, 4, 5, 6...
 
Level 15
Joined
Jan 27, 2007
Messages
948
Actually the ability should give it's max armor (10) when the unit has 10% hp, since having the ability at max level when the percentage of life is 0% isn't quite usefulll.

I thought about that at some point, and that's when I figured out the formula was 11 - bla/bla, instead of 10 - asd/asd

I think it works that way, not 100% sure
 
Status
Not open for further replies.
Top