• 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.
 
still doesn't work ;/

Did you copy it after my edit?

*EDIT* After a few minutes of internal testing , I have finally made the script work just fine. Here it is!

LUA:
local spellret = false
 
local function getDirectionTo(pos1, pos2)
	local dir = SOUTH
	if(pos1.x > pos2.x) then
		dir = EAST
		if(pos1.y > pos2.y) then
			dir = SOUTH
		elseif(pos1.y < pos2.y) then
			dir = NORTH
		end
	elseif(pos1.x < pos2.x) then
		dir = WEST
		if(pos1.y > pos2.y) then
			dir = SOUTH
		elseif(pos1.y < pos2.y) then
			dir = NORTH
		end
	elseif(pos1.y > pos2.y) then
		dir = SOUTH
	elseif(pos1.y < pos2.y) then
		dir = NORTH
	end
 
	return dir
end
 
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 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)
			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)
			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)
			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)
			workpos.x = workpos.x+1
		until workpos.x == tpos.x+1
	end
	if table.find(worktable, ppos) then
	    table.remove(worktable, ppos)
	end
	if table.find(worktable, tpos) then
	    table.remove(worktable, tpos)
	end
	for i = 1, table.maxn(worktable) do
	worktable[i].stackpos = 0
	    if not isWalkable(worktable[i], true, false, true, true) then
		    ret = false
		    break
		end
	    if i == table.maxn(worktable) then
	        ret = true
	    end
	end
	if ret == true then
	    spellret = true
	end
    return true
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)
        if((tpos.y) > (ppos.y)) then
	    	actualpos = {x=tpos.x,y=tpos.y+1,z=tpos.z}
	    elseif((tpos.y) < (ppos.y)) then
	    	actualpos = {x=tpos.x,y=tpos.y-1,z=tpos.z}
	    elseif((tpos.x) < (ppos.x)) then
	    	actualpos = {x=tpos.x-1,y=tpos.y,z=tpos.z}
	    elseif((tpos.x) > (ppos.x)) then
	    	actualpos = {x=tpos.x+1,y=tpos.y,z=tpos.z}
		end
	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

I'm sorry it took me so long :/
Anyways, Enjoy!

Happy to help,
Zum~
 
Last edited:
Back
Top