• 🏆 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!

damage = damage - armor (integer)

Level 12
Joined
Oct 28, 2019
Messages
475
Im trying make this, I saw in other thread but didnt get a answer

An unit has 5 amor and takes 8 damage, so the damage taken is 8-5 = 3

  • Show Text Copy Copy
    • Events
      • Game - DamageEvent becomes Equal to 1.00
    • Conditions
    • Actions
      • Set VariableSet TempLoc1 = (Position of DamageEventTarget)
      • Set VariableSet DamageEventAmount = (DamageEventAmount - (Armor of DamageEventTarget))
      • Floating Text - Create floating text that reads (<Empty String> + ((String((Integer(DamageEventAmount)))) + <Empty String>)) at TempLoc1 with Z offset 100.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 0.00% transparency
      • Custom script: call RemoveLocation(udg_TempLoc1)
      • Floating Text - Change (Last created floating text): Disable permanence
      • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
      • Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds
      • Floating Text - Set the velocity of (Last created floating text) to 80.00 towards 90.00 degrees
Im using damage engine, but if the hero has 5 armor, and takes 9 damage, the damage taken is 2.... IDK what is happening I think the armor of the hero is decreasing the damage taken. I´ve put in gameplay constants the damage/armor all 1.00
 
Level 12
Joined
Oct 28, 2019
Messages
475
Do the units have high armor? What about them is different that would cause this?

Maybe their Armor Type is interfering? Like how Heavy armor takes bonus damage from Magic attacks.

Also, you could have other Damage Events interfering.
IDK whats is happening, maybe a error in trigger damage event, I put a armor 1 to all and fixed 4-4 damage to all units to test...

the archer dont hit damage in footman, friendly fire sometimes dont work, sometimes i cant kill my own units, and the enemy cant kill them too.

but must be a error in damage engine, so you think the trigger is right? I will test other damage engine file here
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,552
You can try using the damage event directly instead of relying on Damage Engine:
  • Show Text Copy Copy
    • Events
      • Unit - A unit Takes damage
    • Conditions
    • Actions
      • Set VariableSet TempLoc1 = (Position of (Damage Target))
      • Event Response - Set Damage of Unit Damaged Event to ((Damage taken) - (Armor of DamageEventTarget))
      • Floating Text - Create floating text that reads (String(Integer((Damage taken))) at TempLoc1 with Z offset 100.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 0.00% transparency
      • Custom script: call RemoveLocation(udg_TempLoc1)
      • Floating Text - Change (Last created floating text): Disable permanence
      • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
      • Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds
      • Floating Text - Set the velocity of (Last created floating text) to 80.00 towards 90.00 degrees
But I imagine the issue is that you have other triggers using the Damage Engine which interfere.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
I recommend displaying some debug messages to see what is going on. Specifically print the damage taken, the armor of the unit and the resulting damage you want the unit to take. Pay attention to those when damaging the units that the system is not working correctly for.

You might want to clamp the minimum damage a unit takes to 1 or some small fractional value. I would be concerned that units with high armor could potentially heal from low damage sources by reducing the damage to a negative amount.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,552
I recommend displaying some debug messages to see what is going on. Specifically print the damage taken, the armor of the unit and the resulting damage you want the unit to take. Pay attention to those when damaging the units that the system is not working correctly for.

You might want to clamp the minimum damage a unit takes to 1 or some small fractional value. I would be concerned that units with high armor could potentially heal from low damage sources by reducing the damage to a negative amount.
That has to be it, I'm mad at myself for forgetting that important rule. It makes sense too, if the math in the code is something like this:

Hit Points = Hit Points - Damage.

Then with a negative amount of Damage you end up with a healing effect:
Hit Points = Hit Points - -Damage

Or simplified:
Hit Points = Hit Points + Damage
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,552
So I put a condition.
If damage-armor <= 0 then set damageAmount = 1
Yeah, as long as the damage is >= 0 then it won't heal:
  • Set VariableSet DamageEventAmount = ...
  • If DamageEventAmount Less than 0 Then Set Variable DamageEventAmount = 0
Or you can use the Math - Max function to simplify it into one line:
  • Set VariableSet DamageEventAmount = (Max(0.00, (DamageEventAmount - (Armor of DamageEventTarget))))
This Max function picks the largest of the two numbers. So in this case it either picks 0 or (Damage - Armor).

So if (Damage - Armor) is less than 0 (negative), it will be considered smaller than 0 and won't be picked.

Of course you can change 0 to whatever you want the minimum amount of damage taken to be.
 
Last edited:
Top