• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Detecting a dead unit

Status
Not open for further replies.
Level 20
Joined
Jul 6, 2009
Messages
1,885
I wondered what's the best way of detecting if a unit is dead.
I know 3 ways,but for each of them,someone says it isn't a valid way of doing it
JASS:
1) IsUnitType(unit,UNIT_TYPE_DEAD) == true
2) GetUnitState(unit,UNIT_STATE_LIFE) <= 0
3) GetWidgetLife(unit) < 0.405
Can someone tell me which way should be used? Arguments are welcome.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,208
The problem is apparently it is possible to "heal a dead unit" which means it is still dead but no longer has no life. It will act exactly like a dead unit should (decay, resurrectable/usable corpse) but no longer has 0 life so methods 2 and 3 above will fail.

This however is extreemly rare. Only native spells in certain situations (tranquility I heard is the most common trouble causer) can can cause this. Custom spells can be be made to not cause this by checking if the unit is actually alive before healing it.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
The problem is apparently it is possible to "heal a dead unit" which means it is still dead but no longer has no life. It will act exactly like a dead unit should (decay, resurrectable/usable corpse) but no longer has 0 life so methods 2 and 3 above will fail.

This however is extreemly rare. Only native spells in certain situations (tranquility I heard is the most common trouble causer) can can cause this. Custom spells can be be made to not cause this by checking if the unit is actually alive before healing it.

So...i should use IsUnitType(unit,UNIT_TYPE_DEAD) == true?

And what about AI native UnitAlive as Sevion said?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
They both work the same way. In fact unit-type == dead is a really rare method. The problem with them is that they consider a dead unit with a delay, after its death, while Life detection is instant.

That's odd. In which case? UNIT_TYPE_DEAD for me is even true on a Unit's life becomes Equal To 0 that runs before the death event.

You could also indicate dead units on death like putting them into a group but would then have to trigger/detect resurrections and to clear it up when the unit decays.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Does GetUnitTypeId(u) != 0 returns true on a ghost unit (removed but associated handle not flushed) ?

I don't think that is better to consider an invalid unit as not dead, i means this part of check should be done before that.

Also what if you play with UnitAdd/RemoveType ? (just curious)
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Pharaoh said:
A ghost unit doesn't nullify it, so GetUnitTypeId() would return its normal Id. Returns true on a function that already returns integer is impossible :p

Read again I mean GetUnitTypeId(<unit>) != 0 which is a valid boolean expression ...
Plus i wouldn't make a such statement without testing it, it would returns its normal id but that doesn't mean it will.

Additionally, that kind of UnitAddType() has almost nothing to do with the comparison the function above handles.

UnitAdd/RemoveType(<unit>,UNIT_TYPE_DEAD)

I don't mean it should be used, i said i'm just curious about it.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
GetUnitTypeId(u) == 0 returns true if the unit has been removed (in the case where u is still pointing to its handle), but UNIT_TYPE_DEAD returns false because a removed unit doesn't have any unit-types associated with it any longer.

When filtering out dead units in damage filter,it's best to use IsUnitType(u, UNIT_TYPE_DEAD) or GetUnitTypeId(u) == 0 then?
 
Status
Not open for further replies.
Top