local function isWalkable(pos, creature, proj, pz)-- by Nord
if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
if getTopCreature(pos).uid > 0 and creature then return false end
cr = getThingFromPos({x = pos.x, y = pos.y, z = pos.z, stackpos = STACKPOS_TOP_CREATURE})
if isPlayer(cr.uid) or isMonster(cr.uid) then return false end
if getTileInfo(pos).protection and pz then return false, true end
local n = not proj and 3 or 2
for i = 0, 255 do
pos.stackpos = i
local tile = getTileThingByPos(pos)
if tile.itemid ~= 0 and not isCreature(tile.uid) then
if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
return false
end
end
end
return true
end
function onCastSpell(cid, var)
local target = getThingFromPos(getPlayerLookPos(cid))
if not isCreature(target) then
doPlayerSendCancel(cid, "You must use this spell in a creature.")
return false
end
for x=1,5 do
local direction = getCreatureLookDirection(cid)
if direction == NORTH then
newpos = {x = getThingPos(cid).x, y = getThingPos(cid).y-x, z = getThingPos(cid).z}
elseif direction == EAST then
newpos = {x = getThingPos(cid).x+x, y = getThingPos(cid).y, z = getThingPos(cid).z}
elseif direction == SOUTH then
newpos = {x = getThingPos(cid).x, y = getThingPos(cid).y+x, z = getThingPos(cid).z}
elseif direction == WEST then
newpos = {x = getThingPos(cid).x-x, y = getThingPos(cid).y, z = getThingPos(cid).z}
end
if isWalkable(newpos) or isInArray({1487,1488,1489,1490,1491,1492,1493,1494,1495,1496},getThingFromPos(newpos).itemid) then
doTeleportThing(target.uid, newpos)
doSendMagicEffect(newpos, CONST_ME_POFF)
end
end
return true
end