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

Condition 'unit is alive' doesnt work properly.

Status
Not open for further replies.
Level 3
Joined
Dec 22, 2009
Messages
39
When i am using the boolean unit is alive condition, it still considers a unit alive even if it is dead. I tried to check it using this trigger
[trigger=trigger]Untitled Trigger 001
Events
Player - Player 1 (Red) skips a cinematic sequence
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Player_Hero[1] is alive) Equal to True
Then - Actions
Game - Display to (All players) the text: Hero Alive
Else - Actions
Set testg = (Units owned by Player 1 (Red) matching ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) is alive) Equal to True)))
Unit Group - Pick every unit in testg and do (Actions)
Loop - Actions
Game - Display to (All players) the text: ((Name of (Picked unit)) + is alive.)[/trigger]

So, that trigger was supposed to show the message "Hero Alive" if 'Player_Hero[1] is alive', and another using a unit group that uses a matching condition. This trigger does indeed work, but even if the units are dead, it still works. How can i fix it?

EDIT:
Same for 'unit is dead' condition. units are always alive even if dead ingame.
 
Level 20
Joined
Apr 14, 2012
Messages
2,901
When i am using the boolean unit is alive condition, it still considers a unit alive even if it is dead. I tried to check it using this trigger
[trigger=trigger]Untitled Trigger 001
Events
Player - Player 1 (Red) skips a cinematic sequence
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Player_Hero[1] is alive) Equal to True
Then - Actions
Game - Display to (All players) the text: Hero Alive
Else - Actions
Set testg = (Units owned by Player 1 (Red) matching ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) is alive) Equal to True)))
Unit Group - Pick every unit in testg and do (Actions)
Loop - Actions
Game - Display to (All players) the text: ((Name of (Picked unit)) + is alive.)[/trigger]

So, that trigger was supposed to show the message "Hero Alive" if 'Player_Hero[1] is alive', and another using a unit group that uses a matching condition. This trigger does indeed work, but even if the units are dead, it still works. How can i fix it?

EDIT:
Same for 'unit is dead' condition. units are always alive even dead ingame.

This might be too obvious to ask but have you set that hero variable to anything before the event happens?
 
Level 4
Joined
May 25, 2009
Messages
100
I created the exact Trigger in my map and everything is fine o_O
Maybe you manipulate the units or testg in some other Triggers?
Do you have other Triggers which are using the Variables?
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
This test map verified that the check does work

Instructions:
1. Press ESC key to check either the unit is Alive or Dead
2. Enter "-test" (without the quote) to kill the unit
3. Press ESC key to check current state of that unit now
 

Attachments

  • AliveCheck.w3x
    12.8 KB · Views: 74
Level 20
Joined
Apr 14, 2012
Messages
2,901
This test map verified that the check does work

Instructions:
1. Press ESC key to check either the unit is Alive or Dead
2. Enter "-test" (without the quote) to kill the unit
3. Press ESC key to check current state of that unit now

That's defskull for 'ya! Fixing triggers at the speed of light minus internet connection10!! (Just an expression of extreme awe)
 
I can't check how the UnitAlive BJ is scripted internally, because I don't have the editor available, but there are some abilities messing with certain parameters post mortem.
Like tranquility healing dead units, raising their life above 0 even though they are still dead.
Also IsUnitType(unit, UNIT_TYPE_DEAD) returns false if the unit has been removed from the game.
Both issues might be your problem here.

For a sure-fire way to check for dead units, use this as a custom script (requires a global unit variable called "unit" and a global boolean called "isAlive"):

if GetUnitTypeId(udg_unit) == 0 or IsUnitType(udg_unit, UNIT_TYPE_DEAD) then
set udg_isAlive = false
else
set udg_isAlive = true
endif
 
Last edited:
Level 23
Joined
Apr 16, 2012
Messages
4,041
just from curiosity, wont the GetUnitType(udg_unit) == 0 true after the unit decayed?

JASS:
//===========================================================================
function IsUnitDeadBJ takes unit whichUnit returns boolean
    return GetUnitState(whichUnit, UNIT_STATE_LIFE) <= 0
endfunction

//===========================================================================
function IsUnitAliveBJ takes unit whichUnit returns boolean
    return not IsUnitDeadBJ(whichUnit)
endfunction

so yea, that is quite shit so I recommend using what Zwiebelchen suggests

btw you can check all blizzard.j code on http://jass.sourceforge.net/doc/api/Blizzard_j-source.shtml
 
just from curiosity, wont the GetUnitType(udg_unit) == 0 true after the unit decayed?
Yes. But this behaviour is exactly what you want for a "true" IsUnitAlive/Dead check.
JASS:
//===========================================================================
function IsUnitDeadBJ takes unit whichUnit returns boolean
    return GetUnitState(whichUnit, UNIT_STATE_LIFE) <= 0
endfunction

//===========================================================================
function IsUnitAliveBJ takes unit whichUnit returns boolean
    return not IsUnitDeadBJ(whichUnit)
endfunction
This is exactly what I thought. Though I believe this is not the source of TO's problem, he might still want to fix it.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
If you want an accurate check of IsUnitAlive or not, use this: if GetWidgetLife(u) < 0.405
Unit dies in Warcraft when they reach a Hit Point below 0.405 (tested and verified), not 0.
Therefore a check of that value will determine if the unit has actually "died" or not.
 
If you want an accurate check of IsUnitAlive or not, use this: if GetWidgetLife(u) < 0.405
Unit dies in Warcraft when they reach a Hit Point below 0.405 (tested and verified), not 0.
Therefore a check of that value will determine if the unit has actually "died" or not.
It's not safe, as there are abilities that heal dead units, like tranquility.
 
it may not even work, because most of the unittypes doent work when adding to units
True. I just thought I should point out this possibility, because I'm not 100% sure if adding the DEAD type to a unit is possible or not (I know that it doesn't work for the UNIT_TYPE_GROUND, for example). If it isn't, then the above method is a surefire way to go sure the unit is alive or not.
 
Level 3
Joined
Dec 22, 2009
Messages
39
Actually, i tried to create a new map. And with that new map, everything works fine. i think the problem is exclusive to my map.
I dont think there is a problem with my trigger, the problem is with the condition 'unit is alive'/'unit is dead' itself. I dont know why the condition was broken. Maybe it has to do with the Physical Damage Detection for GUI v1.0.0.1 system . I am using that system, but i am not sure if it has something to do with making the condition erroneous and I can't just remove the system because my map is heavily dependant on that system because i dont know jass.

EDIT:
Nevermind guys, I found a solution. Thank you all for the help, i appreciate it.

[trigger=Add dead units]Unit Dies
Events
Unit - A unit Dies
Conditions
((Dying unit) is in DeadUnits) Equal to False
Actions
Unit Group - Add (Dying unit) to DeadUnits[/trigger]

so when a hero is revived or a creep is respawned they will be removed.
[trigger=Remove From Dead Group]Remove From Dead Group
Events
Unit - A unit enters (Playable map area)
Conditions
((Dying unit) is in DeadUnits) Equal to True
Actions
Unit Group - Remove (Dying unit) from DeadUnits[/trigger]

still, i dont know why the condition 'unit is alive' doesnt work in my map.
 
Last edited:
still, i dont know why the condition 'unit is alive' doesnt work in my map.
We already answered your question.
The reason for that is, that you can change the health of a dead unit in WC3. The unit won't get revived that way, but it's internal life will still change. The GUI check for "is alive" just checks wether the health of the unit is 0. If the unit gets healed post mortem, the condition will break. There are even object editor spells that heal dead units, like tranquility, so again, blizzard failed at this.

I don't think the GUI damage detection system is to blame here. I'd rather say some AoE/HoT healing abilities in your map target dead units aswell.

However, the correct way to check wether a unit is alive is this one:
JASS:
if GetUnitTypeId(udg_unit) == 0 or IsUnitType(udg_unit, UNIT_TYPE_DEAD) then
set udg_isAlive = false
else
set udg_isAlive = true
endif
Simply copy all lines into custom text and create the globals "unit" (unit) and "isAlive" (boolean) and you are set.

Or (if those 5 lines are too much for your taste) you could make a trigger called "UnitIsAlive", convert it to custom text and then c'n'p this inside:
JASS:
function IsUnitAlive takes unit u returns boolean
  return not (GetUnitTypeId(udg_unit) == 0 or IsUnitType(udg_unit, UNIT_TYPE_DEAD))
endfunction
and then always use
  • Custom Script: set udg_isAlive = IsUnitAlive(udg_Unit)
 
Necroing this just because this BJ function is just so useless and wanted to add a useful copy-and-paste code for all projects (based on Zwiebelchen's answer)

JASS:
    function IsUnitDead takes unit u returns boolean
        if GetUnitTypeId(u) == 0 or IsUnitType(u, UNIT_TYPE_DEAD) then
            return true
        endif
        return false
    endfunction

    function IsUnitAlive takes unit u returns boolean
        return not IsUnitDead(u)
    endfunction
 
Last edited:
Level 21
Joined
Jul 10, 2009
Messages
481
Necroing this just because this BJ function is just so useless and wanted to add a useful copy-and-paste code for all projects (based on Zwiebelchen's answer)
Today's common practice is to use the UnitAlive native instead of the BJ-function.
The native is part of common.ai (not common.j), so if you are coding in Jass, you need to declare it via native UnitAlive takes unit u returns boolean to make it available. You might also need to enable JassHelper to get it working.
 
Status
Not open for further replies.
Top