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

Script Auto Server Save Tfs 1.3

Indahouse

Member
Joined
May 13, 2015
Messages
79
Reaction score
13
Hello i was looking all posts but in majority has not the same as the 12x otserv, we don't use globalevents.xml on this server,
I got a file called Server_save.lua , code:

Lua:
local function ServerSave()
    if configManager.getBoolean(configKeys.SERVER_SAVE_CLEAN_MAP) then
        cleanMap()
    end
    if configManager.getBoolean(configKeys.SERVER_SAVE_CLOSE) then
        Game.setGameState(GAME_STATE_CLOSED)
    end
    if configManager.getBoolean(configKeys.SERVER_SAVE_SHUTDOWN) then
        Game.setGameState(GAME_STATE_SHUTDOWN)
    end
    -- Updating daily reward next server save.
    updateGlobalStorage(DailyReward.storages.lastServerSave, os.time())
    -- Reset gamestore exp boost count.
    db.query('UPDATE `player_storage` SET `value` = 0 WHERE `player_storage`.`key` = 51052')
end

local function ServerSaveWarning(time)
    -- minus one minutes
    local remaningTime = tonumber(time) - 60000
    if configManager.getBoolean(configKeys.SERVER_SAVE_NOTIFY_MESSAGE) then
        Game.broadcastMessage("Server is saving game in " .. (remaningTime/60000) .." minute(s). Please logout.", MESSAGE_STATUS_WARNING)
    end
    -- if greater than one minute, schedule another warning
    -- else the next event will be the server save
    if remaningTime > 60000 then
        addEvent(ServerSaveWarning, 60000, remaningTime)
    else
        addEvent(ServerSave, 60000)
    end
end

-- Function that is called by the global events when it reaches the time configured
-- interval is the time between the event start and the the effective save, it will send an notify message every minute
local serversave = GlobalEvent("serversave")
function serversave.onTime(interval)
    local remaningTime = configManager.getNumber(configKeys.SERVER_SAVE_NOTIFY_DURATION) * 60000
    if configManager.getBoolean(configKeys.SERVER_SAVE_NOTIFY_MESSAGE) then
        Game.broadcastMessage("Server is saving game in " .. (remaningTime/60000) .." minute(s). Please logout.", MESSAGE_STATUS_WARNING)
    end
    addEvent(ServerSaveWarning, 60000, remaningTime)    -- Schedule next event in 1 minute(60000)
    return not configManager.getBoolean(configKeys.SERVER_SAVE_SHUTDOWN)
end
serversave:time("08:15:00")
serversave:register()

On config.lua on server save i put like:

-- Server Save
-- NOTE: serverSaveNotifyDuration in minutes
serverSaveNotifyMessage = true
serverSaveNotifyDuration = 5
serverSaveCleanMap = true
serverSaveClose = false
serverSaveShutdown = false

Well global save at 08h , without close and shutdown.

But i want if was a script error or anything prevent a rollback in game, i try many saves scripts , for auto save each 1 hour, but not working, can anyone help me with this ? And get a simple message like Server Saved.

Thanks for your help
 
After check, the server save, they have cleaned map, and server was not saved.
I have tested another script from this forum today and not work for auto save.
 
If not solved yet, Try this one
Lua:
local cleanMapAtSave = true

local function serverSave(interval)
    if cleanMapAtSave then
        cleanMap()
    end

    saveServer()
    Game.broadcastMessage('Server save complete. Next save in ' .. math.floor(interval / 60000) .. ' minutes!', MESSAGE_STATUS_WARNING)
end

function onThink(interval)
    Game.broadcastMessage('The server will save all accounts within 60 seconds. You might lag or freeze for 5 seconds, please find a safe place.', MESSAGE_STATUS_WARNING)
    addEvent(serverSave, 60000, interval)
    return true
end
XML:
<globalevent interval="3600000" name="AutoSave" script="autosave.lua"/>
 
Back
Top