• 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 Server save more often

Powtreeman

Member
Joined
Sep 26, 2011
Messages
400
Reaction score
6
Location
USA
In tfs 1.0 how do I get it to save more often? I really hate the method of saving once a day.
If power goes out or something else happens the players are screwed.
 
my global event is this

function onTime(interval)
broadcastMessage("Server is saving game in 5 minutes. Please logout.", MESSAGE_STATUS_WARNING)
Game.setGameState(GAME_STATE_STARTUP)
addEvent(firstServerSaveWarning, 120000)
return not shutdownAtServerSave
end

But I want it to save every 30 minutes or an hour or so
 
Then you should use onThink (e.g interval="1800000") instead of onTime (e.g time="08:55:00")
 
It's in MILLIseconds, 30 minutes = 30 * 60 * 1000 = 1800000

You need to change time to interval in globalevents.xml
 
Code:
<globalevent name="Server Save" interval="1800000" script="serversave.lua"/>
 
So I got it to save more often but it still kicks everyone at each save. Here is my full script.
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("", MESSAGE_STATUS_WARNING)
   addEvent(serverSave, 60000)
end

local function firstServerSaveWarning()
   broadcastMessage("", MESSAGE_STATUS_WARNING)
   addEvent(secondServerSaveWarning, 120000)
end

function onThink(interval)
   broadcastMessage("", MESSAGE_STATUS_WARNING)
   Game.setGameState(GAME_STATE_STARTUP)
   addEvent(firstServerSaveWarning, 30)
   return not shutdownAtServerSave
end  [code/]
 
Last edited:

Similar threads

Back
Top