Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
function IsUnitCycloned takes unit u returns boolean
return GetUnitAbilityLevel(u,'Bcyc')>0 or GetUnitAbilityLevel(u,'Bcy2')>0//Bcyc -> Cyclone, Bcy2 -> Cyclone
endfunction
function IsUnitSleeping takes unit u returns boolean
return (GetUnitAbilityLevel(u,('BUsp'))>0) or (GetUnitAbilityLevel(u,('BUst'))>0)
endfunction
function IsUnitInvulnerable takes unit u returns boolean
return GetUnitAbilityLevel(u,'Avul')==1 or IsUnitSleeping(u) or IsUnitCycloned(u)
endfunction
Big Bad Voodoo and Divine Shield have different buffs than 'Avul'. There are more invulnerability buffs, as well.
Checking if the unit is magic immune is usually enough, as every invulnerable unit is also magic immune.
What you can do is use a dummy caster to cast an ability on that unit. If the order to cast the ability returns false, the unit was untargetable.
I was gonna suggest this, but you could even do it with a regular attack, couldn't you? Make sure it can hit ground and air and order the dummy to attack. The rest is the same.
But what if the unit is in ethereal form? Bribe's suggestion is the best way to go. It's best to make the ability based on Channel with Universal Cast set to true and Targets Allowed not including Invulnerable units.
library InvulnerabilityDetector initializer init
// ------------------------------------------------------------
// Invulnerability Detector
//
// Version: 1.1.2
// Author: Touko-Aozaki
// Contact: [email][email protected][/email]
// [url]http://touko.pe.kr[/url]
// ------------------------------------------------------------
// How to use:
// use function IsUnitInvulnerable(unit) to find out whether
// the unit is invulnerable or not.
// ------------------------------------------------------------
// CHANGELOGS
// [1.1.2]
// Changed name of the library. (won't cause incompatibility as there are no public functions)
// [1.1.1]
// Wards and invisible units are now properly handled.
// [1.1.0]
// Reduced ObjectMerger dependencies; custom dummy is no longer
// used.
// ------------------------------------------------------------
//! external ObjectMerger w3a Afod inv& anam "Invulnerability Detector" aart "" aani "" acat "" aeat "" atat "" alig "" amat "" atar 1 "air,ground,structure,vulnerable,ward" acas 1 3600 amcs 1 0 aran 1 99999.0 aher 0 alev 1 Nfd3 1 0 Nfd1 1 0 Nfd2 1 0.01 arac "other" atp1 1 "" aub1 1 "" ansf ""
globals
private constant integer INV_DETECTOR_CODE = 'inv&'
private constant string INV_DETECTOR_ORDERSTR = "fingerofdeath"
private constant integer DUMMY_UNIT_CODE = 'nshe'
private unit dummy
endglobals
function IsUnitInvulnerable takes unit whichUnit returns boolean
local boolean result = false // default false
if whichUnit != null and GetUnitTypeId(whichUnit) != 0 then
// target is valid
call PauseUnit(dummy, false) // unlock to test the order
if not IsUnitVisible(whichUnit, Player(15)) then
// make sure not to affect any possible game states
call UnitShareVision(whichUnit, Player(15), true)
set result = not IssueTargetOrder(dummy, INV_DETECTOR_ORDERSTR, whichUnit)
call UnitShareVision(whichUnit, Player(15), false)
else
set result = not IssueTargetOrder(dummy, INV_DETECTOR_ORDERSTR, whichUnit)
endif
call PauseUnit(dummy, true) // lock the unit;
endif
return result
endfunction
private function init takes nothing returns nothing
set dummy = CreateUnit(Player(15), DUMMY_UNIT_CODE, 0, 0, bj_UNIT_FACING)
call UnitAddAbility(dummy, INV_DETECTOR_CODE)
call ShowUnit(dummy, false) // makes any unit-type eligible for a dummy
call PauseUnit(dummy, true) // hiding the unit doesn't prevent triggering the event
endfunction
endlibrary
Checking if the unit is magic immune is usually enough, as every invulnerable unit is also magic immune.
