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