function Trig_StaffOfTeleportation_OnCast takes nothing returns nothing
local unit u=GetTriggerUnit()
local real x=GetUnitX(u)
local real y=GetUnitY(u)
local real Tx=GetSpellTargetX()
local real Ty=GetSpellTargetY()
local integer counter=0
local boolean ok=true
local boolean targetPointOk=true
local timer t=null
local effect eff1=null
local unit blinker=CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h00L', Tx, Ty, 0.00)
if IssuePointOrder(blinker, "blink", Tx+1.00, Ty+1.00) then
elseif IssuePointOrder(blinker, "blink", 0.00, 0.00) then
//blink ok --> current position walkable :) --or-- //blink ok
else //blink failed...interrupt!
set targetPointOk=false
endif
if targetPointOk then
set eff1=AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", x, y)
set t=CreateTimer()
call TimerStart(t, 4.00, false, null)
loop
exitwhen TimerGetRemaining(t)<=0.00
if (not UnitAlive(u)) or (not UnitChanneling(u)) then
call Msg(GetOwningPlayer(u), "Teleportation interrupted.")
set ok=false
exitwhen true
endif
if counter==3 then //read target coords
set Tx=GetUnitX(blinker)
set Ty=GetUnitY(blinker)
endif
set counter=counter+1
call TriggerSleepAction(0.20)
endloop
call DestroyEffect(eff1)
call DestroyTimer(t)
set t=null
endif
if targetPointOk and ok then
call RemoveUnit(blinker)
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportCaster.mdl", x, y))
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl", Tx, Ty))
call SetUnitPosition(u, Tx, Ty)
//call MsgDev("caster succefully "+I2S(counter))
elseif not targetPointOk then
call Msg(GetOwningPlayer(u), "Teleportation failed.")
call TriggerSleepAction(1.00)
call BlzEndUnitAbilityCooldown(u, ABI_ITEM_TELEPORTATION_WINGS)
endif
call RemoveUnit(blinker)
set blinker=null
set eff1=null
set u=null
endfunction