local spellret = false
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
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
local function getDirectionTo(pos1, pos2)
local dir = SOUTH
if(pos1.x > pos2.x) then
dir = WEST
if(pos1.y > pos2.y) then
dir = NORTHWEST
elseif(pos1.y < pos2.y) then
dir = SOUTHWEST
end
elseif(pos1.x < pos2.x) then
dir = EAST
if(pos1.y > pos2.y) then
dir = NORTHEAST
elseif(pos1.y < pos2.y) then
dir = SOUTHEAST
end
elseif(pos1.y > pos2.y) then
dir = NORTH
elseif(pos1.y < pos2.y) then
dir = SOUTH
end
return dir
end
local function verifyTiles(cid, tid, ppos, tpos)
local workpos = {x=0,y=0,z=0}
local worktable = {}
local ret = false
if((tpos.y) > (ppos.y)) then
workpos.x = tpos.x
workpos.z = tpos.z
workpos.y = ppos.y
repeat
table.insert(worktable, workpos.y+1)
until workpos.y = tpos.y+1
elseif((tpos.y) < (ppos.y)) then
workpos.x = tpos.x
workpos.z = tpos.z
workpos.y = ppos.y
repeat
table.insert(worktable, workpos.y-1)
until workpos.y = tpos.y-1
elseif((tpos.x) < (ppos.x)) then
workpos.x = ppos.x
workpos.z = tpos.z
workpos.y = tpos.y
repeat
table.insert(worktable, workpos.x-1)
until workpos.x = tpos.x-1
elseif((tpos.x) > (ppos.x)) then
workpos.x = ppos.x
workpos.z = tpos.z
workpos.y = tpos.y
repeat
table.insert(worktable, workpos.x+1)
until workpos.x = tpos.x+1
end
for i = 1, #worktable do
if not isWalkable(worktable[i], false, false, true, true, true)
ret = false
break
end
end
if i == #worktable then
ret = true
end
if ret == true then
spellret = true
return true
end
return false
end
function onCastSpell(cid, var)
local spellname = "xx" -- change xx to your spell's name, make sure to keep the quotation marks as they are , DO NOT REMOVE THEM!
local config = {
t = getCreatureTarget(cid),
pld = getPlayerLookDirection(cid),
exhaust = xxx, -- change xxx to any empty storage value in your server
exhausttime = xx -- change this to the cooldown you want of your spell, make it 0 if you dont want a cooldown
}
local ppos, tpos = getThingPos(cid), getThingPos(getCreatureTarget(cid))
local actualpos, newlookdir = {}, 0
if((exhaustion.check(cid, config.exhaust)) == false) then
exhaustion.set(cid, config.exhaust, config.exhausttime)
newlookdir = getDirectionTo(ppos, tpos)
else
doPlayerSendCancel(cid, "You may not cast " .. spellname .. " for " ..exhaustion.get(cid, config.exhaust).." more seconds.")
return true
end
verifyTiles(cid, tid, ppos, tpos)
if (spellret == true) then
doTeleportThing(cid, actualpos)
doCreatureSetLookDirection(cid, newlookdir)
addEvent(doSendMagicEffect, 50, getThingPos(cid), CONST_ME_TELEPORT)
else
doSendMagicEffect(ppos, CONST_ME_POFF)
doPlayerSendCancel(cid, "There are some obstacles in the way.")
end
return true
end