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

Linux Auto save every x minutes

thomson9292

New Member
Joined
Feb 28, 2017
Messages
97
Solutions
1
Reaction score
2
Every time my ots crashes all progress is gone. Thy only way to save your progress is to logout from game or manually restart server.

Is it possible to set automatic server save every x period of time?
 
Solution
you can do the same thing with the global save, but set the interval to 900 (15 minutes) and run a loop of all online players and save them
LUA:
function onThink(interval)
    local players = Game.getPlayers()
    for i = 1, #players do
        players[i]:save()
    end
    return true
end
Maybe it's stupid question but is there any way to save at least character progress (eg. every 15min) without restarting server (I mean some kind of save which effects just part of data without saving whole world condition)? I see in globalevent there is only 1 server save per day.

Edit.
@slawkens

tfs. 1.3
 
You can create a creaturescript that would save individual characters (over specific periods of time - it's been done). I'm not sure if latest TFS supports globalevents "every X minutes" but if it doesn't, in the worst case you can copy the global save to occur every 15 minutes. It will be hundred lines in XML but it will work...
 
you can do the same thing with the global save, but set the interval to 900 (15 minutes) and run a loop of all online players and save them
LUA:
function onThink(interval)
    local players = Game.getPlayers()
    for i = 1, #players do
        players[i]:save()
    end
    return true
end
 
Solution
@Xeraphus
Tell me please where I should paste your code? In this file under rest of code?

serversave.lua
LUA:
local shutdownAtServerSave = false
local cleanMapAtServerSave = false

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

    if cleanMapAtServerSave then
        cleanMap()
    end

    saveServer()
end

local function secondServerSaveWarning()
    Game.broadcastMessage('Server is saving game in one minute. Please go to a safe place.', MESSAGE_STATUS_WARNING)
    addEvent(serverSave, 60000)
end

local function firstServerSaveWarning()
    Game.broadcastMessage('Server is saving game in 3 minutes. Please go to a safe place.', MESSAGE_STATUS_WARNING)
    addEvent(secondServerSaveWarning, 120000)
end

function onTime(interval)
    Game.broadcastMessage('Server is saving game in 5 minutes. Please go to a safe place.', MESSAGE_STATUS_WARNING)
    Game.setGameState(GAME_STATE_STARTUP)
    addEvent(firstServerSaveWarning, 120000)
    return not shutdownAtServerSave
end
 
Last edited by a moderator:
you make a new file for it, not paste it in an existing globalevent
you have to register it to a new event in xml too and put interval to 900
XML:
<globalevent type="think" interval="900" script="something.lua"/>
 
Saving players but not saving houses is not a good thing to do. If player takes an item from house, then gets saved (with item in inventory) and then server crashes, item is going to get replicated (since house was not saved after item was took out of it).

I don't know if TFS already has a command or function to call whole server save function (houses and players), but if it doesn't, then it shouldn't be hard to add that on C++ source code.

Also, please take a look at: Smart server save system
 
Back
Top