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

Create server save by interval.

Ruthless Reign

New Member
Joined
Dec 23, 2009
Messages
5
Reaction score
1
I am trying to add a server save the occurs every 30 mins. I am using TFS 1.0. I tried copying the global event for the daily server save and changing 'time' to 'interval' my script looks like this:
In globalevents.xml;
Code:
<globalevent name="Server Save Hourly" interval="600000" script="intervalserversave.lua"/>
In intervalserversave.lua;
Code:
local shutdownAtServerSave = false
local cleanMapAtServerSave = false

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

        if cleanMapAtServerSave then
            cleanMap()
        end

        Game.setGameState(GAME_STATE_NORMAL)
    end
end

local function secondServerSaveWarning()
    broadcastMessage("2nd Warning.", MESSAGE_STATUS_WARNING)
    addEvent(serverSave, 1000)
end

local function firstServerSaveWarning()
    broadcastMessage("1st Warning.", MESSAGE_STATUS_WARNING)
    addEvent(secondServerSaveWarning, 12000)
end

function onThink(interval, lastExecution)
    Game.setGameState(GAME_STATE_NORMAL)
    addEvent(firstServerSaveWarning, 10000)
    return not shutdownAtServerSave
end

I know the script isn't setup for 30 mins right now but I was putting it as a shorter time to test it. I just wanna make it functional before I put in the actual time.

I used to work on OT's a few years ago been out of the game for a bit. This used to be controlled in the config file so I was a little confused why it was no longer there. If anyone knows how i could add a parameter to the config file that will control an interval server save without shutting down the server. Please let me know. Thank you!
 
Code:
<globalevent name="save" interval="1800000" script="save.lua"/>
Code:
local shutdownAtServerSave = false
local cleanMapAtServerSave = false

local function serverSave()
    if shutdownAtServerSave then
        Game.setGameState(GAME_STATE_SHUTDOWN)
    end
   
    if cleanMapAtServerSave then
        cleanMap()
    end
   
    saveServer()
    Game.setGameState(GAME_STATE_NORMAL)
end

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

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

function onThink(interval)
    broadcastMessage("Server is saving game in 5 minutes. Please go to a safe place.", MESSAGE_STATUS_WARNING)
    addEvent(firstServerSaveWarning, 120000)
    return not shutdownAtServerSave
end
 
Code:
<globalevent name="save" interval="1800000" script="save.lua"/>
Code:
local shutdownAtServerSave = false
local cleanMapAtServerSave = false

local function serverSave()
    if shutdownAtServerSave then
        Game.setGameState(GAME_STATE_SHUTDOWN)
    end
  
    if cleanMapAtServerSave then
        cleanMap()
    end
  
    saveServer()
    Game.setGameState(GAME_STATE_NORMAL)
end

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

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

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


How do you count this seconds/minutes?
Really dont get it. if i want a broadcasted serversave each hour?
 
How do you count this seconds/minutes?
Really dont get it. if i want a broadcasted serversave each hour?

Multiply by 1000 because it's in miliseconds.

For example:
60 seconds = 60 * 1000 = 60000 (this would be an interval of 1 minute)

In 1 hour there are 3600 seconds:
3600 * 1000 = 3600000 (this is the hourly interval)
 
Multiply by 1000 because it's in miliseconds.

For example:
60 seconds = 60 * 1000 = 60000 (this would be an interval of 1 minute)

In 1 hour there are 3600 seconds:
3600 * 1000 = 3600000 (this is the hourly interval)

So i just put in globalua, serversave , "3600000" then it broadcasts and save server every hour?
And if i want each 2 hour it would be 3600000 * 2?
 
So i just put in globalua, serversave , "3600000" then it broadcasts and save server every hour?
And if i want each 2 hour it would be 3600000 * 2?

Yes you got it, in globalevents.xml you would put it like this:
Code:
<globalevent name="Server Save Hourly" interval="3600000" script="intervalserversave.lua"/>
 
Back
Top