function onCastSpell(cid, var)
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 pos = getClosestFreeTile(cid, getPosByDir(getCreaturePosition(cid), getCreatureLookDirection(cid), 2), false, false)
if(not pos or isInArray({pos.x, pos.y}, 0)) or (getTilePzInfo(pos)) or not isWalkable(pos) then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
return false
end
local cpos = getCreaturePosition(cid)
if(doTeleportThing(cid, pos, true)) then
doSendMagicEffect(cpos, CONST_ME_POFF)
doSendMagicEffect(pos, 27)
end
return true
end