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

player transfer to position

Keshoo

Newer Rich
Joined
Feb 23, 2010
Messages
166
Reaction score
5
i have script that transfer players from position to other postion after x time but some time its not work as intended it can transfer players from temple and other far away places i dont know where is the problem

Lua:
local transferroom = GlobalEvent("transferoom")

function areaHasPlayer(center, radiusX, radiusY)
    return #Game.getSpectators(center, false, true, radiusX, radiusX, radiusY, radiusY) > 0
end


local roomCenter = Position(32223, 32047, 14)
local radius = {6, 7}
local destination = Position(32207, 32053, 14)

function Dreamcourtsroom.onThink(interval)
    for _, player in pairs(Game.getPlayers()) do
        if not player or player:isInGhostMode() then
            return true
        end
        if areaHasPlayer(roomCenter, unpack(radius)) then
                player:teleportTo(destination)
            end
    end
    return true
end

Dreamcourtsroom:interval(10000)
Dreamcourtsroom:register()
 
Solution
This portion here will stop the onThink before it has a chance to loop through all the players
Lua:
        if not player or player:isInGhostMode() then
            return true
        end

And this function only checks if ANY player is in that area. You should be checking if the specific player you are looking for is in that area.
Lua:
function areaHasPlayer(center, radiusX, radiusY)
    return #Game.getSpectators(center, false, true, radiusX, radiusX, radiusY, radiusY) > 0
end
The problem is that if Any player is in the area, Every single player online that is checked before that player would be teleported to the destination you set.
After that player that is in the area specified is teleported out of the area, then nobody else...
This portion here will stop the onThink before it has a chance to loop through all the players
Lua:
        if not player or player:isInGhostMode() then
            return true
        end

And this function only checks if ANY player is in that area. You should be checking if the specific player you are looking for is in that area.
Lua:
function areaHasPlayer(center, radiusX, radiusY)
    return #Game.getSpectators(center, false, true, radiusX, radiusX, radiusY, radiusY) > 0
end
The problem is that if Any player is in the area, Every single player online that is checked before that player would be teleported to the destination you set.
After that player that is in the area specified is teleported out of the area, then nobody else would be teleported.
Depending on the situation, the entire server could be moved to your destination position, or only 1 person.
(Or if the first person 'online' that was checked was a god character in ghost mode, then nobody would ever be teleported lol)

With the above in mind, here is my suggested edit.
Lua:
local transferroom = GlobalEvent("transferoom")

local roomCenter = Position(32223, 32047, 14)
local radius = {x = 6, y = 7}
local destination = Position(32207, 32053, 14)

function Dreamcourtsroom.onThink(interval)
 
    -- grab the spectators in the area you want to check
    -- this is more efficient, because we are only using the function once, instead of multiple times
    -- also because we are only checking the creatures in the area, not every single person online.
    local spectators = Game.getSpectators(roomCenter, false, true, radius.x, radius.x, radius.y, radius.y)
 
    -- loop through spectators found
    -- if spectators and #spectators > 0 then -- I don't think this is required, but if you encounter errors, add it in
        for i = 1, #spectators do
            local spectator = spectators[i]
            if not spectator:isInGhostMode() then -- we don't need to confirm they are a player, because the third argument in getSpectators is doing that for us already
                spectator:teleportTo(destination)
            end
        end
    -- end
    return true
end

Dreamcourtsroom:interval(10000)
Dreamcourtsroom:register()
 
Last edited:
Solution
thanks working perfect but when i go over and over to test timer if its 10 secs i think timer reduce do i make problem when i go over again on place?
 
thanks working perfect but when i go over and over to test timer if its 10 secs i think timer reduce do i make problem when i go over again on place?
Can you try to english that sentence again?
I don't understand.
 
Can you try to english that sentence again?
I don't understand.
testing transfer timer(10seconds), but when i go the same place again it transfer me too fast is that problem with timer script or i make it debug because i go over and over again
 
testing transfer timer(10seconds), but when i go the same place again it transfer me too fast is that problem with timer script or i make it debug because i go over and over again
You have it set on a global timer onThink.
So that means it will trigger every 10 seconds. 12:00:10 -> 12:00:20 -> 12:00:30

So if you go in at 12:00:07 - you would be teleported out after 3 seconds, since the next onThink cycle would be at 12:00:10.

-- edit
Note: the onThink cycle is started with the server. So if the server starts up at 12:00:03 the next 10 second onThink cycle would be 12:00:13.

Not really relevant to the original explanation, but figured I'd toss it in, to cover any inaccuracies someone might derive from it without any context.
 
Last edited:
Back
Top