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

put delay on player:teleportTo(toPosition)

bizao030188

Member
Joined
Jun 4, 2012
Messages
50
Solutions
2
Reaction score
7
Hi
Is it possible to define delay for functions? For instance if I want to teleport a player after 3 seconds how would I do it?

I appreciate any kind of help!
 
Solution
LUA:
local function teleport(cid, position)
    local player = Player(cid)
    if player then
        player:teleportTo(position)
    end
end

addEvent(teleport, 5000, player:getId(), Position(x, y, z))
Most people use addEvent to get delays.

If your working with player/npc/monsters you'll want to ensure that they are still online/alive, before excecuting scripts like 'teleport' or 'addItem' which require the creatureID in order to function correctly.
 
LUA:
function onUse/onSay/w/e(player, x, x, x, x)
            code to execute before the delay
            local pos = {x = 1000, y = 1000, z = 7}
            addEvent(player:teleportTo(), time_delay_in_miliseconds, pos)
return true
end

or it might be:

LUA:
      addEvent(player:teleportTo(pos), time_delay_in_miliseconds)
 
LUA:
local function teleport(cid, position)
    local player = Player(cid)
    if player then
        player:teleportTo(position)
    end
end

addEvent(teleport, 5000, player:getId(), Position(x, y, z))
 
Solution
I don't think he needs to define a hole new function for teleporting when one already exists.
if you don't create a new function and pass the id of the creature, and don't check if it exists before continuing to execute, the server will crash.
 
LUA:
local function teleport(cid, position)
    local player = Player(cid)
    if player then
        player:teleportTo(position)
    end
end

addEvent(teleport, 5000, player:getId(), Position(x, y, z))

how would it be to execute functions that are created like: function Player.myFunction(self) in events?
 
Back
Top