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

Detect Max Life and Mana change

Status
Not open for further replies.
Hello there, reader.

I thought of a certain approach on how to properly detect change in max life.
Now, I'm not sure if this will work, since I don't have my test environment up and running at the moment, but here's the script:

JASS:
library UnitMaxStateDetect

    //# +nosemanticerror
    private function I2F takes integer i returns real
        set i = i
        return i
    endfunction

    //# +nosemanticerror
    private function F2I takes real r returns integer
        set r = r
        return r
    endfunction

    private function clearInt takes integer i returns integer
        set i = i
        return i
    endfunction

    private function clearReal takes real r returns real
        set r = r
        return r
    endfunction

    function TriggerRegisterUnitMaxLifeEvent takes trigger t, unit u, limitop operation returns event
        return TriggerRegisterUnitStateEvent(t, u, UNIT_STATE_MAX_LIFE, operation, clearReal(I2F(R2I(GetUnitState(u, UNIT_STATE_MAX_LIFE)))) )
    endfunction

    function TriggerRegisterUnitMaxManaEvent takes trigger t, unit u, limitop operation returns event
        return TriggerRegisterUnitStateEvent(t, u, UNIT_STATE_MAX_MANA, operation, clearReal(I2F(R2I(GetUnitState(u, UNIT_STATE_MAX_MANA)))) )
    endfunction
endlibrary
 
Last edited:
Status
Not open for further replies.
Top