Unit's dying life point?

waaaks!

Zinctified
Reaction score
255
Each time I check if is a unit dead or not, I always used < 0.405 for checking dead units, and > 0.405 for checking alive units, while some coders use 0.406, so what is the right and accurate value to be used to check dead or alive units?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
IsUnitType(whichUnit,UNIT_TYPE_DEAD).
This is faster than GetWidgetLife and more accurate.
However, the value is 0.403, so far I researched it.
 

Kenny

Back for now.
Reaction score
202
>IsUnitType(whichUnit,UNIT_TYPE_DEAD).
This is faster than GetWidgetLife and more accurate.

Since when? From what I've heard, [ljass]GetWidgetLife()[/ljass] is quite a fast native. And [ljass]IsUnitType()[/ljass] would only be more accurate if your coding is of poor quality.

Also, 0.403 seems a bit off. From most tests, it seems to be around 0.406 or so.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Since when? From what I've heard, GetWidgetLife() is quite a fast native. And IsUnitType() would only be more accurate if your coding is of poor quality.
I benchmarked it. IsUnitType faster about 20%.
 

Azlier

Old World Ghost
Reaction score
461
I won't believe it without the benchmark script.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
scope S initializer Init
private function THE_TRUTH_ABOUT_LIFE_AND_DEATH takes nothing returns nothing
    local unit u = CreateUnit(Player(0),&#039;hfoo&#039;,0,0,0)
    call SetWidgetLife(u,.405)
    call SetWidgetLife(u,9001)
    if GetWidgetLife(u)==0 then
        call BJDebugMsg(&quot;!&quot;)
    endif
    if GetWidgetLife(u)&gt;9000 then
        call BJDebugMsg(&quot;IT&#039;S OVER 9000!&quot;)
    elseif GetWidgetLife(u)&gt;1 then
        call BJDebugMsg(&quot;Well, it&#039;s not 0.&quot;)
    endif
    if IsUnitType(u,UNIT_TYPE_DEAD) then
        call BJDebugMsg(&quot;The Footman is &#039;dead&#039;.&quot;)
    endif
    call UnitRemoveType(u,UNIT_TYPE_DEAD)
    if IsUnitType(u,UNIT_TYPE_DEAD) then
        call BJDebugMsg(&quot;The Footman is not &#039;dead&#039;.&quot;)
    endif
endfunction

private function Init takes nothing returns nothing
    call TimerStart(CreateTimer(),2,true,function THE_TRUTH_ABOUT_LIFE_AND_DEATH)
endfunction
endscope

Someone try?
If anyone thinks it unrealistic, remember that heals over time may exist...

Edit: The remove dead type is completely unrealistic. Let us know if the footman dies, and what displays.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
-The unit died
-'Well, it's not over 0' displayed (the health gets set to the unit's max, in this case 420)
-'The footman is 'dead'.' displayed
-'The footman is not 'dead'.' displayed; the type was properly removed




In other words, Blizzard is froodlenutzskying hilarious. Units die below ~.405 life, and their life gets set to zero on the spot, and it seems they receive a dead type. HOWEVER, you can manipulate the life after that anyway (based on prior life bounds for the unit), AND you can remove the dead type.

So none of these checks are theoretically completely safe.
 

Tom_Kazansky

--- wraith it ! ---
Reaction score
157
>If anyone thinks it unrealistic, remember that heals over time may exist...

for my heals over time spells, I always check if the unit is dead or not first :D
---
But I concern about the speed now

>I won't believe it without the benchmark script.

me too, even though I don't know much about benchmark :eek:
 

Jesus4Lyf

Good Idea™
Reaction score
397
>So none of these checks are theoretically completely safe.
Exactly my point. Which is why [LJASS]IsUnitType(unit,UNIT_TYPE_DEAD)[/LJASS] is the safest, because the user must intentionally remove the type to screw it up. A heal over time could mess with the unit's health, so I don't think it as appropriate.

I might run a benchmark on the issue as well for interest, but personally I'd say people shouldn't use this whole GetWidgetLife nonsense for checking if a unit is dead. It doesn't make much sense, compared to the type check, since health is much more likely to change than removing the UNIT_TYPE_DEAD status, I imagine.

So: Schrödinger's cat
JASS:
function SchrodingersCat takes nothing returns nothing
    local unit u=CreateUnit(Player(15),&#039;hfoo&#039;,0,0,0)
    call SetWidgetLife(u,0)
    call SetWidgetLife(u,9001)
    call UnitRemoveType(u,UNIT_TYPE_DEAD)
endfunction

The footman is both alive and dead.
You could check by issuing a stop order, to see if it is dead, probably. But is there any way to tell without interrupting the unit or something?
I suppose you could have a dummy unit try to issue an order to attack it, and see if it fails, or something... but then what about [LJASS]call ShowUnit(unit,false)[/LJASS]? :p

What a puzzle.
 

Kenny

Back for now.
Reaction score
202
>I might run a benchmark on the issue as well for interest, but personally I'd say people shouldn't use this whole GetWidgetLife nonsense for checking if a unit is dead. It doesn't make much sense.

I have always used [ljass]GetWidgetLife()[/ljass] and not once have I had a problem.

To me, the only way you would cause it to bug is if you don't pay attention when you are coding something.

Also...

[ljass]IsUnitType(unit,UNIT_TYPE_DEAD) == true[/ljass] returns false for non-existant units. Which could also be a problem...
 

Jesus4Lyf

Good Idea™
Reaction score
397
>IsUnitType(unit,UNIT_TYPE_DEAD) == true returns false for non-existant units. Which could also be a problem...
We're all doomed.
WC3 mapping is no longer possible, go home everyone. :p

>To me, the only way you would cause it to bug is if you don't pay attention when you are coding something.
I suppose you're right.
 

Kenny

Back for now.
Reaction score
202
I suppose you could use something like:

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


So if you do attempt to check if a non-existant unit is dead (which to me would be as common as increasing a dead units life) it will still return true as the unit will not have a unit type id. :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top