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

[JASS] Is TriggerRegisterUnitStateEvent bugged?

Status
Not open for further replies.
Level 14
Joined
Dec 12, 2012
Messages
1,007
Hi,

well the title basically says it all.

Why does this work:

JASS:
library LifeChangeEvent initializer i

    globals
        private trigger LifeChangeEvent
    endglobals

    private function LifeChangeEvent_Actions takes nothing returns nothing
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 10.0, "Unit life changed!")
    endfunction
    
    private function MapInit_Actions takes nothing returns nothing
        call TriggerRegisterUnitStateEvent(LifeChangeEvent, GetEnumUnit(), UNIT_STATE_LIFE, GREATER_THAN, GetWidgetLife(GetEnumUnit()))
    endfunction

    private function i takes nothing returns nothing 
        local group g = CreateGroup()
        set LifeChangeEvent = CreateTrigger()
        call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
        call ForGroup(g, function MapInit_Actions)
        call TriggerAddAction(LifeChangeEvent, function LifeChangeEvent_Actions)
        call DestroyGroup(g)
        set g = null
    endfunction
endlibrary

but this not?

JASS:
library LifeChangeEvent initializer i

    globals
        private trigger LifeChangeEvent
    endglobals

    private function LifeChangeEvent_Actions takes nothing returns nothing
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 10.0, "Unit life changed!")
    endfunction
    
    private function MapInit_Actions takes nothing returns nothing
        // Here is the only difference
        call TriggerRegisterUnitStateEvent(LifeChangeEvent, GetEnumUnit(), UNIT_STATE_LIFE, LESS_THAN, GetWidgetLife(GetEnumUnit()))
    endfunction

    private function i takes nothing returns nothing 
        local group g = CreateGroup()
        set LifeChangeEvent = CreateTrigger()
        call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
        call ForGroup(g, function MapInit_Actions)
        call TriggerAddAction(LifeChangeEvent, function LifeChangeEvent_Actions)
        call DestroyGroup(g)
        set g = null
    endfunction
endlibrary

Is anything known about that strange behaviour?

lfh
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Less than works, but the life has to become bigger than the registered value in order for the less than to trigger again.

So if you register the event for 400 life, then the life must become > 400 before the event triggers again.

You can try registering the value as life-0.01 or something like that.

Note that the registered value does not dynamucally change is the max life of the unit changes during a game.
 
Level 14
Joined
Dec 12, 2012
Messages
1,007
You can try registering the value as life-0.01 or something like that.

Ok thanks. This works, but only if the unit doesn't have to much hitpoints in total.

If I have a unit with e.g. 300000 hitpoints, this won't work due to Wc3 rounding of reals...
Is there a way to solve this? Of course I could just set the value to life-1.0, but this would change the behaviour I intend to.
 
Status
Not open for further replies.
Top