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

Ignoring damage on specific unit

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,337
Hi,

I have tried to write a trigger that basically heals a unit whenever it is damaged for the damage it received.

The trigger sort of works, but for some reason it lets the unit take damage from the first hit of an attacker, then afterwards works correctly.

Thus if a unit hit it for 20 damage, it would have 80/100 health, but then after all attacks would be healed.

JASS:
	static method damageMain takes nothing returns boolean
		local unit u = GetTriggerUnit()
	        call print("healed damage")
		call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_LIFE) + GetEventDamage())
		set u = null
		return false
	endmethod
	
	method setInvuln takes nothing returns nothing
		set invulnTrig = CreateTrigger()
		call TriggerAddCondition(invulnTrig, Condition(function A.damageMain))
		call TriggerRegisterUnitEvent(invulnTrig, u, EVENT_UNIT_DAMAGED)
	endmethod
 
Level 12
Joined
Mar 13, 2012
Messages
1,121
This is a WC 3 bug, just add a 99k health ability then remove it after u heal the unit.
I would not call it a bug, rather a nice feature. When the trigger fires on a EVENT_UNIT_DAMAGED, its actually before the damage is done.

Dat-C3s solution is not optimal and may lead to bugs. If you want a post-heal instead of a pre-heal, a 0.00 timer will do.
 
Status
Not open for further replies.
Top