HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Is unit dead?

07-25-2008, 02:21 PM#1
d07.RiV
How do I correctly check if a unit is dead or alive?
The BJ method, GetUnitState(u,UNIT_STATE_LIFE)<=0 usually works, but if SetUnitState(u,UNIT_STATE_LIFE,..) was used after the unit died, this will no longer work (the HP will change but the unit will remain dead).
The same method can kill a unit if life is set to anything <=.405 and that works correctly - hp is set to 0 after that.
07-25-2008, 02:26 PM#2
Alexander244
IsUnitType(u, UNIT_TYPE_DEAD)
07-25-2008, 02:29 PM#3
DioD
Before checking unit type also check its ID, units can decay.
07-25-2008, 02:43 PM#4
Flame_Phoenix
There is a better way:
Collapse JASS:
GetWidgetLife(whichUnit) > 0.405
07-25-2008, 03:13 PM#5
d07.RiV
Isnt GetWidgetLife the same as GetUnitState (u, UNIT_STATE_LIFE) for units?
Thanx for the UNIT_STATE_DEAD thing though. Since its for heroes, I shouldn't worry about decay.
07-25-2008, 07:33 PM#6
Flame_Phoenix
No. getWidgetLife is also a native, and more efficient because it only takes one argument.
07-25-2008, 07:37 PM#7
Here-b-Trollz
UNIT_TYPE_DEAD is the preferred method.
07-25-2008, 07:47 PM#8
Flame_Phoenix
Quote:
UNIT_TYPE_DEAD is the preferred method.
Why ?? Since when ?? xD
Please give rep++ to ALL those who helped you =P
07-25-2008, 07:50 PM#9
Alexander244
Since you could set the hp of dead units.
07-25-2008, 07:51 PM#10
Flame_Phoenix
Quote:
Since you could set the hp of dead units.
You can also use "SetWidgetLife(widget, hp)"... also faster =P
07-25-2008, 07:52 PM#11
Alexander244
And in that case GetWidgetLife(u) < 0.405 would return false for a dead unit.. .. ..
07-25-2008, 07:55 PM#12
Flame_Phoenix
Quote:
And in that case GetWidgetLife(u) < 0.405 would return false for a dead unit.. .. ..
Wtf !? NO! it would return true !
07-25-2008, 07:57 PM#13
Alexander244
You are able to set a units life above 0.405 after it has died..
07-25-2008, 08:48 PM#14
DioD
If you have problems with this methods you can make dummy attacker with zero damage attack targeting everything and order it to attack unit, attempt to attack dead unit will fail.

Also you can try to damage unit with zero damage.

Add expiration timer and check for it.

You can try to do anything that dead unit cannot do.
07-25-2008, 09:00 PM#15
darkwulfv
Huh. I always used GetWidgetLife(unit) < .406 and I've never ever had a problem with it. (Maybe because I don't go around randomly changing the HP of dead units, which is about the only thing that could break that, that I can think of.)

Although I guess IsUnitType(unit, UNIT_TYPE_DEAD) == true //(don't forget the '== true') would be the "safe" way in the event you're changing dead units' health.