• 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!

Solved Teleport back faster than others.

Permamently

New Member
Joined
Jul 23, 2015
Messages
34
Reaction score
3
Hello I'm using this script for teleport players in area 1x1 then teleport them back:
Code:
local function doTeleportBack(cid, tid, pPos, pos)
    if isPlayer(cid) then
        doTeleportThing(cid, pos, false)
    end
    if isPlayer(tid) then
        doTeleportThing(tid, pPos, false)
    end
  
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
    doSendMagicEffect(pPos, CONST_ME_POFF)
    return true
end


function onCastSpell(cid, var)

    local teleports = {{ x=1100, y=44, z=7 }, { x=87, y=466, z=7 }}

    local area1 = teleports[math.random(1,#teleports)]
    local pos = getCreaturePosition(cid)

for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1, false)) do
        if(isPlayer(tid) and getPlayerAccess(tid) <= 1) then
            local pPos = getCreaturePosition(tid)
                if pPos.x == pos.x and pPos.y == pos.y + 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x, y=area1.y + 1, z=area1.z }, false)
                elseif pPos.x == pos.x and pPos.y == pos.y - 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x, y=area1.y - 1, z=area1.z }, false)
                elseif pPos.x == pos.x + 1 and pPos.y == pos.y and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x + 1, y=area1.y, z=area1.z }, false)
                elseif pPos.x == pos.x -1 and pPos.y == pos.y and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x - 1, y=area1.y, z=area1.z }, false)
                elseif pPos.x == pos.x + 1 and pPos.y == pos.y + 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x + 1, y=area1.y + 1, z=area1.z }, false)
                elseif pPos.x == pos.x - 1 and pPos.y == pos.y - 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x - 1, y=area1.y - 1, z=area1.z }, false)
                elseif pPos.x == pos.x - 1 and pPos.y == pos.y + 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x - 1, y=area1.y + 1, z=area1.z }, false)
                elseif pPos.x == pos.x + 1 and pPos.y == pos.y - 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x + 1, y=area1.y - 1, z=area1.z }, false)
                end
            doTeleportThing(cid, area1, false)
            addEvent(doTeleportBack, 5 * 1000, cid, tid, pPos, pos)
        end
    end
    return true
    end
And I want to do that by other spell caster can back faster than teleported enemys.
I mean for example: Player using this teleportation spell "exori mas teleport" then if he want back faster he write for example: "exori mas teleport back"

*Normally he stay there with enemys for 5 seconds if it's imporant.
 
Copy + paste file... change
Code:
addEvent(doTeleportBack, 5 * 1000, cid, tid, pPos, pos)
to
Code:
addEvent(doTeleportBack, 3* 1000, cid, tid, pPos, pos)
for 3 seconds instead of 3.. and make another spell named exori gran mas teleport back
 
If you want to teleport back with another spell you can make a global variable for the old position and call it in the new spell.
Example:
Code:
backposition = {}
Then in the script.
Code:
backposition[cid] = getCreaturePosition(cid)
In the second/new script.
Code:
if backposition[cid] then
     doTeleportThing(cid, backposition[cid])
     backposition[cid] = nil
end

If it should be in the same script, so with the same words to go back, you can do something similar but then in the same script and set backposition[cid] back to nil.
 
@Limos You are the best, its working, thank you very much :)

@edit
I got one more problem if i use "exori mas teleport back" I will back to my main position it's true but after 5 seconds its teleporting me again :/
 
Last edited:
Well your teleport is written here

if backposition[cid] then
doTeleportThing(cid, backposition[cid])
backposition[cid] = nil
end

And your teleport function is still running and does what it does after 5 seconds, so you have to exclude yourself from the function.
You can make it skip you during the loop by checking if the loop is currently on your ID, like, rewrite this line:

if(isPlayer(tid) and getPlayerAccess(tid) <= 1) then

Into:
if(isPlayer(tid) and cid ~= tid and getPlayerAccess(tid) <= 1) then
 
If you want both, so teleport back after 5 seconds with the option to teleport back yourself, you can also check for the variable in the function that is called by addEvent (doTeleportBack), so if backposition[cid] is nill don't teleport back.
 
I got it now, thanks guys :) I got second question, don't want to do next topic.

I have spell X which create item in the ground. Is there anyway that by using spell Y item will delate?
 
post vid to this plz.. im curious as to what your doing, what these spells are and look like
 
Last edited:
I got it now, thanks guys :) I got second question, don't want to do next topic.

I have spell X which create item in the ground. Is there anyway that by using spell Y item will delate?
If the same person who created the item with spell X should be able to remove it with spell Y, you can also use a global variable the same way to store the position of the item in spell X.
Then get the position in spell Y and get the uid of the item by using: getTileItemById(pos, itemid).uid
 
Can you post the full error? Btw you can also just add that code in login.lua instead of using a new script and there is no need to register scripts with type login or logout.
Edit: Already solved.
 
Last edited:
Back
Top