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

I dont know how to indicate simple (I think) condition

Status
Not open for further replies.
Level 2
Joined
Jul 13, 2017
Messages
5
I have a little question. I created something like this:

Event:
Unit X - dies
Action:
Unit Y changes ownership to Neutral Hostile
Unit Y replaces with Unit Z using Maximum HP and Mana


I want to make condition that Unit Y must be alive, but I don't know how. Could you help?
 
Level 11
Joined
Jun 2, 2004
Messages
849
Honestly I'm just repeating what I've heard from other people and have never experienced any bugs myself. The "unit is alive" GUI condition apparently isn't always accurate and it's usually better to check HP. Dead units also have a "UNIT_TYPE_DEAD" unit type which I check as well, though you have to do that in a custom script since there's no GUI option for it.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
The GUI conditions check whether hp <= 0:
JASS:
function IsUnitDeadBJ takes unit whichUnit returns boolean
    return GetUnitState(whichUnit, UNIT_STATE_LIFE) <= 0
endfunction
A unit is considered dead, if hp <= 0.405.

  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Custom script: local unit u
      • Unit - Set life of Rifleman 0000 <gen> to 0.40
      • Unit - Set life of Rifleman 0000 <gen> to 8.00
      • Game - Display to (All players) the text: (String((Life of Rifleman 0000 <gen>)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Rifleman 0000 <gen> is alive) Equal to True
        • Then - Actions
          • Game - Display to (All players) the text: alive
        • Else - Actions
          • Game - Display to (All players) the text: dead
      • Custom script: set u = gg_unit_hrif_0000
      • Custom script: if( IsUnitType(u, UNIT_TYPE_DEAD) or GetUnitTypeId(u) == 0) then
      • Game - Display to (All players) the text: really dead
      • Custom script: else
      • Game - Display to (All players) the text: really alive
      • Custom script: endif
Rifleman will die because hp<=0.405, but after that you set his hp to 8 and the text message will print 8. Also conditions to check whether the unit is alive/dead will be wrong afterwards. It's very rare though to set hp of a dead unit.

I found a method here [code=jass] Checking if a unit is dead - Wc3C.net to check if the unit is really dead. It uses UNIT_TYPE_DEAD like Kaiyuu said.

I would guess it also causes problems with reincarnation. You can argue whether a reincarnating unit is dead.
 
Status
Not open for further replies.
Top