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

Lua TFS 0.4

ausirosiris

Member
Joined
May 23, 2020
Messages
105
Reaction score
22
TFS 0.4
Anyone have a script that teleports all players to a different town in a certain amount of time?
 
Solution
Can i Loop between 4 towns with math.random?
Yes, This should work.
LUA:
local towns = {1, 2, 3, 4}

function onThink(interval, lastExecution, thinkInterval)
    local town = towns[math.random(#towns)]
    local townPosition = getTownTemplePosition(town)
    for _, player in ipairs(getPlayersOnline()) do
        doTeleportThing(player, townPosition)
        doRemoveConditions(player)
    end
    return true
end
and the time i just calibrate with the globalevents, right?!
Right, Unless you wanted it to be on an exact hour then you'll have to use function onTime(cid, interval, lastExecution)
XML:
<globalevent name="scriptNameHere" interval="600000" event="script" value="scriptNameHere.lua"/>
Something like this?
LUA:
local town = {x = 1000, y = 1000, z = 7}

function onThink(interval, lastExecution, thinkInterval)
    for _, player in ipairs(getPlayersOnline()) do
        doTeleportThing(player, town)
        doRemoveConditions(player)
    end
    return true
end
 
Last edited:
Something like this?
LUA:
local town = {x = 1000, y = 1000, z = 7}

function onThink(interval, lastExecution, thinkInterval)
    for _, player in ipairs(getPlayersOnline()) do
        doTeleportThing(player, town)
        doRemoveConditions(player)
    end
    return true
end
Can i Loop between 4 towns with math.random?
and the time i just calibrate with the globalevents, right?!


and, what about a player who just logged in? i need to log in right to current "town"
do i need to create an storage for each town to check on log in?

This will be helpful im going to rewrite i've got an idea now. Thanks
 
Last edited:
Can i Loop between 4 towns with math.random?
Yes, This should work.
LUA:
local towns = {1, 2, 3, 4}

function onThink(interval, lastExecution, thinkInterval)
    local town = towns[math.random(#towns)]
    local townPosition = getTownTemplePosition(town)
    for _, player in ipairs(getPlayersOnline()) do
        doTeleportThing(player, townPosition)
        doRemoveConditions(player)
    end
    return true
end
and the time i just calibrate with the globalevents, right?!
Right, Unless you wanted it to be on an exact hour then you'll have to use function onTime(cid, interval, lastExecution)
XML:
<globalevent name="scriptNameHere" interval="600000" event="script" value="scriptNameHere.lua"/>
 
Last edited:
Solution
Yes, Something like this should work.
LUA:
local towns = {1, 2, 3, 4}

function onThink(interval, lastExecution, thinkInterval)
    local town = towns[math.random(#towns)]
    local townPosition = getTownTemplePosition(town)
    for _, player in ipairs(getPlayersOnline()) do
        doTeleportThing(player, townPosition)
        doRemoveConditions(player)
    end
    return true
end

Right, Unless you wanted it to be on an exact hour then you'll have to use function onTime(cid, interval, lastExecution)
XML:
<globalevent name="scriptNameHere" interval="600000" event="script" value="scriptNameHere.lua"/>
Oh, okok. thank you!
 
Back
Top