WC3JASS

WC3JASS => JASS and vJASS Resources => Codes & Snippets => Topic started by: AGD on September 04, 2016, 12:09:44 AM

Title: InvulnerabilityChecker
Post by: AGD on September 04, 2016, 12:09:44 AM
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