InvulnerabilityChecker

Scripts

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
1
library InvulnerabilityChecker
2
3
    function CheckInvulnerability takes unit u returns boolean
4
        local real origHP = GetWidgetLife(u)
5
        local real origMP = GetUnitState(u, UNIT_STATE_MANA)
6
        local boolean check
7
        call UnitDamageTarget(u, u, 0.01, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, null)
8
        set check = GetWidgetLife(u) == origHP and GetUnitState(u, UNIT_STATE_LIFE) == origMP
9
        call SetWidgetLife(u, origHP)
10
        call SetUnitState(u, UNIT_STATE_MANA, origMP)
11
        return check
12
    endfunction
13
14
endlibrary