library CreateIllusion initializer Init
globals
private unit IllusionCaster
private constant integer IllusionAbility = 'A000' //item illusion
private constant integer IllusionUnit = 'nalb' //dummy caster
private boolean IsIllusion //used for checking if the illusion was made by system
unit LastCreatedIllusion //as at any time to reference the last illusion made by system
real IllusionCreatedEvent //use to detect when an illusion is created
endglobals
function UnitCreateIllusion takes unit u returns nothing
call SetUnitX(IllusionCaster, GetUnitX(u))
call SetUnitY(IllusionCaster, GetUnitY(u))
call SetUnitOwner(IllusionCaster, GetOwningPlayer(u), false)
call IssueTargetOrderById(IllusionCaster, 852274, u)
call SetUnitOwner(IllusionCaster, Player(15), false)
set IsIllusion = true
endfunction
private function GetIllusion takes nothing returns nothing
if IsIllusion then
set LastCreatedIllusion = GetTriggerUnit()
set IllusionCreatedEvent = 0
set IllusionCreatedEvent = 1
endif
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local region r = CreateRegion()
call RegionAddRect(r, GetPlayableMapRect())
set IllusionCaster = CreateUnit(Player(15), IllusionUnit, 0, 0, 0)
call UnitAddAbility(IllusionCaster, IllusionAbility)
call ShowUnit(IllusionCaster, false)
call TriggerAddAction(t, function GetIllusion)
call TriggerRegisterEnterRegion( t, r, null )
endfunction
endlibrary