local function isWalkable(pos)
pos.stackpos = 0
local tile = getThingfromPos(pos, false)
if tile ~= 0 and not hasProperty(tile.uid, CONST_PROP_BLOCKSOLID) and not isCreature(getTopCreature(pos).uid) then
return true
end
end
local function doTeleportBack(cid, target, pos)
if isPlayer(cid) then
doTeleportThing(cid, pos, false)
end
if isCreature(target) then
doTeleportThing(target, getClosestFreeTile(cid, pos, false), false)
end
doSendMagicEffect(pos, CONST_ME_ENERGYHIT)
return true
end
function onCastSpell(cid, var)
local target, pPos = getCreatureTarget(cid), getCreaturePosition(cid)
if target == 0 then
doSendMagicEffect(pPos, CONST_ME_POFF)
doPlayerSendCancel(cid, "First get a target.")
return false
end
local pos = getClosestFreeTile(cid, getCreaturePosition(target), false)
if not pos or isInArray({pos.x, pos.y}, 0) or getTilePzInfo(pos) or not isWalkable(pos) then
doSendMagicEffect(pPos, CONST_ME_POFF)
doPlayerSendCancel(cid, "Destination not reachable.")
return false
end
doTeleportThing(cid, pos, false)
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)
addEvent(doTeleportBack, 3 * 1000, cid, target, pPos)
return true
end