• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Teleport spell

margoh

{{ user.title }}
Joined
Apr 1, 2013
Messages
807
Solutions
18
Reaction score
355
Hello,

I want a spell that teleport us to monster/player which is currently our target.
What I mean? I will show witih SS :D:
Before use spell:
eq75p7.jpg


After use spell:
txcz7t.jpg


When use spell (instant) it should:
  • Teleport to him (if teleport from his left side, teleport to his right side)
  • Changing direction of looking (if i look right, teleport from his left side to his right side, it should change look direction to left side)

Best regards,
margoh.
 
Give this a try, tell me if there is anything wrong with it.
LUA:
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)
	    if((tpos.y) > (ppos.y)) then
	    	actualpos = {x=tpos.x,y=tpos.y+1,z=tpos.z}
	    	newlookdir = 0
	    elseif((tpos.y) < (ppos.y)) then
	    	actualpos = {x=tpos.x,y=tpos.y-1,z=tpos.z}
	    	newlookdir = 2
	    elseif((tpos.x) < (ppos.x)) then
	    	actualpos = {x=tpos.x-1,y=tpos.y,z=tpos.z}
	    	newlookdir = 1
	    elseif((tpos.x) > (ppos.x)) then
	    	actualpos = {x=tpos.x+1,y=tpos.y,z=tpos.z}
	    	newlookdir = 3
        else
	        doPlayerSendTextMessage(cid, "You must be either north, east, south or west of your target to use this spell.", MESSAGE_EVENT_DEFAULT)
	        return false
	    end
	    
	    doTeleportThing(cid, actualpos)
	    doCreatureSetLookDirection(cid, newlookdir)
	    addEvent(doSendMagicEffect, 100, getThingPos(cid), CONST_ME_TELEPORT)
	else
	    doSendMagicEffect(ppos, CONST_ME_POFF)
        doPlayerSendCancel(cid, "You may not cast " .. spellname .. " for " ..exhaustion.get(cid, config.exhaust).." more seconds.")
	end
    return true
end


*EDIT*: Tested and working fine (0.36pl1). Tell me if I can be of more assistance.
 
Last edited:
The script works. Tested it my self. It's awesome. The only thing is.. if I use it on a trainer I can go through the wall. Which only means I can do it with other monsters as well.
 
Add this on libs/050-functions.lua
LUA:
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

And use this:
LUA:
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)
	if((tpos.y) > (ppos.y)) then
		actualpos = {x=tpos.x,y=tpos.y+1,z=tpos.z}
	    	newlookdir = 0
	elseif((tpos.y) < (ppos.y)) then
	    	actualpos = {x=tpos.x,y=tpos.y-1,z=tpos.z}
	    	newlookdir = 2
	elseif((tpos.x) < (ppos.x)) then
	    	actualpos = {x=tpos.x-1,y=tpos.y,z=tpos.z}
	    	newlookdir = 1
	elseif((tpos.x) > (ppos.x)) then
	    	actualpos = {x=tpos.x+1,y=tpos.y,z=tpos.z}
	    	newlookdir = 3
        else
	        doPlayerSendTextMessage(cid, "You must be either north, east, south or west of your target to use this spell.", MESSAGE_EVENT_DEFAULT)
	end
	else
		doPlayerSendCancel(cid, "You may not cast " .. spellname .. " for " ..exhaustion.get(cid, config.exhaust).." more seconds.")
	        return true
	end

	if (isWalkable(tpos, false, false, true, true, true)) then
	    	doTeleportThing(cid, actualpos)
	    	doCreatureSetLookDirection(cid, newlookdir)
	    	addEvent(doSendMagicEffect, 100, getThingPos(cid), CONST_ME_TELEPORT)
	else
	    	doSendMagicEffect(ppos, CONST_ME_POFF)
        	doPlayerSendCancel(cid, "There is no room.")
	end
    	return true
end
 
Last edited:
Remove everything you used on this post, put this spell in your spells.xml then put this script in a your spell's .lua file:
LUA:
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

Always happy to help,
Zum~
 
Last edited:
Error in console:
a6mhkd.jpg


- - - Updated - - -

tried to combine, there aren't any errors on console, but when i try to use it, server is instantaneously stopped
 
This one will definitely work. I'm kinda rusty, I apologize...

LUA:
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

This version is as good as it gets. Refined direction-function, should work perfectly with obstacles, and, although I could have made it much, much shorter, I really don't have the time or the energy required to do so... Nonetheless, It may still be bugged. I need you to tell me if it bugs out again :).

Good luck,
Zum~
 
Try this?
LUA:
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 = getThingPos(cid)
	local tpos = getThingPos(config.t)
	local actualpos, newlookdir = {}, SOUTH
 
	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

Are you sure you are targeting something while casting this? Because it will most likely bug out like that if there is no target...
 
Definitely was the "isWalkable()" function. That shit repeats 255 times per tile x_x

Give this a try:
LUA:
local spellret = false
 
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)
			workpos.y = 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)
			workpos.y = 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)
			workpos.x = 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)
			workpos.x = workpos.x+1
		until workpos.x == tpos.x+1
	end
	local wallpos = workpos
	wallpos.stackpos = 0
	for i = 1, #worktable do
	    if (hasItemProperty(getThingfromPos(wallpos).uid, CONST_PROP_BLOCKSOLID) == 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 = getThingPos(cid)
	local tpos = getThingPos(config.t)
	local actualpos, newlookdir = {}, SOUTH
 
	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
 
LUA:
local spellret = false
 
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)
			workpos.y = 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)
			workpos.y = 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)
			workpos.x = 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)
			workpos.x = workpos.x+1
		until workpos.x == tpos.x+1
	end
	for i = 1, #worktable do
	    local wallpos = worktable[i]
		wallpos.stackpos = 0
	    if (hasItemProperty(getThingfromPos(wallpos).uid, CONST_PROP_BLOCKSOLID) == 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 = getThingPos(cid)
	local tpos = getThingPos(config.t)
	local actualpos, newlookdir = {}, SOUTH
 
	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
 
LUA:
local spellret = false
 
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,stackpos=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)
			workpos.y = 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)
			workpos.y = 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)
			workpos.x = 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)
			workpos.x = workpos.x+1
		until workpos.x == tpos.x+1
	end
	for i = 1, #worktable do
	    local wallpos = worktable[i]
		wallpos.stackpos = 0
	    if (hasItemProperty(getThingfromPos(wallpos).uid, CONST_PROP_BLOCKSOLID) == true) then
		    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 = "Flash Step" -- 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 = 17856, -- change xxx to any empty storage value in your server
		exhausttime = 1 -- change this to the cooldown you want of your spell, make it 0 if you dont want a cooldown
	}
	local ppos = getThingPos(cid)
	local tpos = getThingPos(config.t)
	local actualpos, newlookdir = {}, SOUTH
 
	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

If this doesn't work with you, I'll test it on my own server to see if it's a problem in the script or not... Because I'm starting to run out of options...

*EDIT* : Copy it again, forgot a "then"...
 
Last edited:
Back
Top