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

TFS 0.X Teleporting after a few seconds

azylsqn

New Member
Joined
Apr 14, 2017
Messages
11
Reaction score
1
Hey, I am looking for a script that teleports a player after a few seconds after using an item about id xxx on an item about id xxx. Did anyone meet with something like that? Greetings.
 
Code:
local exhaust, events = {}, {}
local teleportPos = { x = 0, y = 0, z = 0 }
local exhaustionDelay = 1000
local eventDelay = 1000

function onUse(cid, item, fromPosition, target, toPosition)
    if target.itemid == 2160 then
        local exhaustTime = exhaust[getPlayerGUID(cid)] or 0
        if exhaustTime <= os.time() then
            local eventId = addEvent(function(cid)
                            if isPlayer(cid) then
                                doTeleportThing(cid, teleportPos, false)
                                doSendMagicEffect(teleportPos, CONST_ME_TELEPORT)
                            end
                        end, eventDelay, cid)
            stopEvent(events[getPlayerGUID(cid)] or 0)
            events[getPlayerGUID(cid)] = eventId
            exhaust[getPlayerGUID(cid)] = os.time() +exhaustionDelay
        else
            doPlayerSendCancel(cid, "You are exhausted.")
        end
    end
    return true
end
 
Last edited:
What you are asking for is almost like this other script
Xikini's Free Scripting Service. [0.3.7 & (0.3.6/0.4)]

Lua:
local function delayedTeleport(cid)
    if isPlayer(cid) then
        doTeleportThing(cid, {x = 1000, y = 1000, z = 7})
    end
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if itemEx.itemid == 11111111111 then
        addEvent(delayedTeleport, 3000, cid)
        doPlayerSendTextMessage(cid,  MESSAGE_INFO_DESCR, "You will teleport in 3 seconds.")
    end
    return true
end
 
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

    if(itemEx.itemid == XXXX) then
        doSendMagicEffect(toPosition, CONST_ME_POFF)
        addEvent(doTeleportThing, 1000 * 15, cid, {x = 100, y = 100, z = 7})
        return true
    else
        doPlayerSendCancel(cid, "You need to use it on ...")
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end
  
    return true
end

Edit XXXX to id where it needs to be used
15 to the seconds
x y z to the pos
it on... to where it should be used.
 
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

    if(itemEx.itemid == XXXX) then
        doSendMagicEffect(toPosition, CONST_ME_POFF)
        addEvent(doTeleportThing, 1000 * 15, cid, {x = 100, y = 100, z = 7})
        return true
    else
        doPlayerSendCancel(cid, "You need to use it on ...")
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end
 
    return true
end

Edit XXXX to id where it needs to be used
15 to the seconds
x y z to the pos
it on... to where it should be used.
anytime you pass userdata using any kind of event you should check that data before doing any action with that info, thats why @Xikini uses "isPlayer" function.
 
I need to use the object for another item and then teleport the player.
"Use crowbar on fence, then teleport after xx seconds."
This sentence is just to make explanation easier.

in actions.xml put the crowbar's itemid.
XML:
<action itemid="22222222222" event="script" value="xxxxxxxxxxxxxxxxxx.lua"/>
in the script you want to use, put the fence itemid.

Replace fence and crowbar, with whatever item it is you want to use, of course.
They are just random item examples to make explanation easier.
 
Back
Top