• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! 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