InvulnerabilityChecker

Codes & Snippets

9 years
edited 8 years
A simple snippet used to check if a unit is invulnerable. False positives from mana shields are also accounted for.

Code (jass) Select
library InvulnerabilityChecker

    function CheckInvulnerability takes unit u returns boolean
        local real origHP = GetWidgetLife(u)
        local real origMP = GetUnitState(u, UNIT_STATE_MANA)
        local boolean check
        call UnitDamageTarget(u, u, 0.01, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, null)
        set check = GetWidgetLife(u) == origHP and GetUnitState(u, UNIT_STATE_LIFE) == origMP
        call SetWidgetLife(u, origHP)
        call SetUnitState(u, UNIT_STATE_MANA, origMP)
        return check
    endfunction

endlibrary