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

Lua TFS 1.2 Why is the server save kicking players every time it saves?

SlayingWorld

Active Member
Joined
Jan 23, 2014
Messages
156
Reaction score
37
Location
USA
As the title follows, i didn't want to leave my server save at every 24 hours to save. So i made an interval to save the server every hour just in case the server crashed or something like that. But every time the server saves, it kicks everyone out of the server, which is something i don't want. This is the code i have:
Code:
local shutdownAtServerSave = false
local cleanMapAtServerSave = false

local function serverSave()
    if shutdownAtServerSave then
        Game.setGameState(GAME_STATE_SHUTDOWN)
    else
        Game.setGameState(GAME_STATE_CLOSED)

        if cleanMapAtServerSave then
            cleanMap()
        end

        Game.setGameState(GAME_STATE_NORMAL)
    end
end

local function secondServerSaveWarning()
    broadcastMessage("Server is saving game in one minute. Please move to a safe area.", MESSAGE_STATUS_WARNING)
    addEvent(serverSave, 60000)
end

local function firstServerSaveWarning()
    broadcastMessage("Server is saving game in 3 minutes. Please move to a safe area.", MESSAGE_STATUS_WARNING)
    addEvent(secondServerSaveWarning, 120000)
end

function onThink(interval)
    broadcastMessage("Server is saving game in 5 minutes. Please move to a safe area.", MESSAGE_STATUS_WARNING)
    Game.setGameState(GAME_STATE_STARTUP)
    addEvent(firstServerSaveWarning, 120000)
    return not shutdownAtServerSave
end

And this is how i have it in .xml
Code:
<globalevent name="Server Save" interval="3600000" script="serversave.lua" />

Is it normal for it to kick players on each save? Is the server meant to do that? Or is there a better code i can use?
 
Do people get kicked or can they just not login anymore after they relog?s And if they get kicked when do they get kicked? Before or after the 5 minute countdown
They get kicked as soon as the server saves. After the 5 minutes are over. Its just a fast kick less than 1 second and they can relog. But if you log out before the 5 minutes are over you cannot log back in until the server save is completed.
 
Give this a try. It works for me.

Code:
<globalevent name="save" interval="7200000" script="save.lua"/>

Code:
local config = {
    broadcast = {120, 30},
    delay = 120,
    events = 30
}

local function executeSave(seconds, iv)
    if(isInArray(config.broadcast, seconds)) then
        broadcastMessage("[Server]: Server save and world clean within " .. seconds .. " seconds, pick up anything you want to keep!", MESSAGE_STATUS_CONSOLE_BLUE)
    end

    if(seconds > 0) then
        addEvent(executeSave, config.events * 1000, seconds - config.events, iv)
    else
        saveServer()
        cleanMap()
        broadcastMessage("[Server]: Thank youl! Next round of server save and world clean in " .. math.floor(iv / 60000) .. " minutes.", MESSAGE_STATUS_CONSOLE_BLUE)
    end
end

function onThink(interval)
    if(table.maxn(config.broadcast) == 0) then
        saveServer()
    else
        executeSave(config.delay, interval)
    end
    return true
end
 
If it's due to the server taking too long to save, consider shelling out more money for an SSD.

Red
 
Game.setGameState(GAME_STATE_CLOSED) will kick all players from the game and prevent them from logging in.
Game.setGameState(GAME_STATE_NORMAL) will allow players to connect as usual.
Game.setGameState(GAME_STATE_STARTUP) will prevent new players from connecting.


Really all you want is the saveServer() function.
Add whatever fruit you like =D

Code:
function onThink(interval)
  saveServer()
end
 
Last edited:
Back
Top