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

How to edit serversave.lua script

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
592
Reaction score
64
hi, how can i add clean map warnings like
Map clean in 5 minutes.
Map clean in 3 minutes.
Map clean in 1 minutes.
Map cleaned. Because im thinking to use this code as a map clean and server save at the same time. So original code
LUA:
local shutdownAtServerSave = false
local cleanMapAtServerSave = true

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 logout.", MESSAGE_STATUS_WARNING)
    addEvent(serverSave, 60000)
end

local function firstServerSaveWarning()
    broadcastMessage("Server is saving game in 3 minutes. Please logout.", MESSAGE_STATUS_WARNING)
    addEvent(secondServerSaveWarning, 120000)
end

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

And i did something like this, not sure if its right or not so i need like confirmation

LUA:
local shutdownAtServerSave = false
local cleanMapAtServerSave = true

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

        if cleanMapAtServerSave then
        cleanMap()
        broadcastMessage("Map cleaned.", MESSAGE_STATUS_WARNING)
        end

        Game.setGameState(GAME_STATE_NORMAL)
    end
end

local function secondServerSaveWarning()
    broadcastMessage("Map clean in 1 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(serverSave, 60000)
end

local function firstServerSaveWarning()
    broadcastMessage("Map clean in 3 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(secondServerSaveWarning, 120000)
end

function onTime(interval)
    broadcastMessage("Map clean in 5 minutes.", MESSAGE_STATUS_WARNING)
    Game.setGameState(GAME_STATE_STARTUP)
    addEvent(firstServerSaveWarning, 120000)
    return not shutdownAtServerSave
end
 
Solution
Okay i tested it works just fine but there is one stuff that i dont like. It kick player from the game when map is cleaned. Is it possible to not to kick player?
Try this one:

LUA:
function onThink(interval)
    broadcastMessage("Map cleaning in 5 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(broadcastMessage, 2 * 60 * 1000, "Map cleaning in 3 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(broadcastMessage, 4 * 60 * 1000, "Map cleaning in 1 minute.", MESSAGE_STATUS_WARNING)
    addEvent(function()
        saveServer()
        cleanMap()
        broadcastMessage("Map cleaned.", MESSAGE_STATUS_WARNING)
    end, 5 * 60 * 1000)
    return true
end
hi, how can i add clean map warnings like
Map clean in 5 minutes.
Map clean in 3 minutes.
Map clean in 1 minutes.
Map cleaned. Because im thinking to use this code as a map clean and server save at the same time. So original code
LUA:
local shutdownAtServerSave = false
local cleanMapAtServerSave = true

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 logout.", MESSAGE_STATUS_WARNING)
    addEvent(serverSave, 60000)
end

local function firstServerSaveWarning()
    broadcastMessage("Server is saving game in 3 minutes. Please logout.", MESSAGE_STATUS_WARNING)
    addEvent(secondServerSaveWarning, 120000)
end

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

And i did something like this, not sure if its right or not so i need like confirmation

LUA:
local shutdownAtServerSave = false
local cleanMapAtServerSave = true

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

        if cleanMapAtServerSave then
        cleanMap()
        broadcastMessage("Map cleaned.", MESSAGE_STATUS_WARNING)
        end

        Game.setGameState(GAME_STATE_NORMAL)
    end
end

local function secondServerSaveWarning()
    broadcastMessage("Map clean in 1 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(serverSave, 60000)
end

local function firstServerSaveWarning()
    broadcastMessage("Map clean in 3 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(secondServerSaveWarning, 120000)
end

function onTime(interval)
    broadcastMessage("Map clean in 5 minutes.", MESSAGE_STATUS_WARNING)
    Game.setGameState(GAME_STATE_STARTUP)
    addEvent(firstServerSaveWarning, 120000)
    return not shutdownAtServerSave
end
Looks like it should work fine. Best way to know for sure is to test it.
 
Looks like it should work fine. Best way to know for sure is to test it.
Hmm weird it should be fine but when i change from time to interval it gives warning
XML:
<globalevent name="Server Save" interval="360000" script="serversave.lua" />
Says Event onThink not found. scipts/serversave.lua
 
Hmm weird it should be fine but when i change from time to interval it gives warning
XML:
<globalevent name="Server Save" interval="360000" script="serversave.lua" />
Says Event onThink not found. scipts/serversave.lua
Change function onTime(interval) to function onThink(interval)
 
Change function onTime(interval) to function onThink(interval)
Okay i tested it works just fine but there is one stuff that i dont like. It kick player from the game when map is cleaned. Is it possible to not to kick player?
 
Okay i tested it works just fine but there is one stuff that i dont like. It kick player from the game when map is cleaned. Is it possible to not to kick player?
Try this one:

LUA:
function onThink(interval)
    broadcastMessage("Map cleaning in 5 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(broadcastMessage, 2 * 60 * 1000, "Map cleaning in 3 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(broadcastMessage, 4 * 60 * 1000, "Map cleaning in 1 minute.", MESSAGE_STATUS_WARNING)
    addEvent(function()
        saveServer()
        cleanMap()
        broadcastMessage("Map cleaned.", MESSAGE_STATUS_WARNING)
    end, 5 * 60 * 1000)
    return true
end
 
Last edited:
Solution
Try this one:

LUA:
function onThink(interval)
    broadcastMessage("Map cleaning in 5 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(broadcastMessage, 2 * 60 * 1000, "Map cleaning in 3 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(broadcastMessage, 4 * 60 * 1000, "Map cleaning in 1 minute.", MESSAGE_STATUS_WARNING)
    addEvent(function()
        saveServer()
        cleanMap()
        broadcastMessage("Map cleaned.", MESSAGE_STATUS_WARNING)
    end, 5 * 60 * 1000)
    return true
end
Yes it works everything is perfect but for some reason these two
addEvent(broadcastMessage, 2 * 60 * 1000, "Map cleaning in 3 minutes.", MESSAGE_STATUS_WARNING)
addEvent(broadcastMessage, 4 * 60 * 1000, "Map cleaning in 1 minute.", MESSAGE_STATUS_WARNING)
doesnt go on server-log it shows up on default while broadcastMessage("Map cleaning in 5 minutes.", MESSAGE_STATUS_WARNING) shows up on server-log which is fine maybe it have to be like this?
broadcastMessage, 2 * 60 * 1000, "Map cleaning in 3 minutes.", MESSAGE_STATUS_WARNING)
broadcastMessage, 4 * 60 * 1000, "Map cleaning in 1 minute.", MESSAGE_STATUS_WARNING)
 
Yes it works everything is perfect but for some reason these two
addEvent(broadcastMessage, 2 * 60 * 1000, "Map cleaning in 3 minutes.", MESSAGE_STATUS_WARNING)
addEvent(broadcastMessage, 4 * 60 * 1000, "Map cleaning in 1 minute.", MESSAGE_STATUS_WARNING)
doesnt go on server-log it shows up on default while broadcastMessage("Map cleaning in 5 minutes.", MESSAGE_STATUS_WARNING) shows up on server-log which is fine maybe it have to be like this?
broadcastMessage, 2 * 60 * 1000, "Map cleaning in 3 minutes.", MESSAGE_STATUS_WARNING)
broadcastMessage, 4 * 60 * 1000, "Map cleaning in 1 minute.", MESSAGE_STATUS_WARNING)
Yeah, that is strange. You can try this alternative, but if this doesn't go to server log then I'm not sure.

LUA:
    broadcastMessage("Map cleaning in 5 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(function() broadcastMessage("Map cleaning in 3 minutes.", MESSAGE_STATUS_WARNING) end, 2 * 60 * 1000)
    addEvent(function() broadcastMessage("Map cleaning in 1 minutes.", MESSAGE_STATUS_WARNING) end, 4 * 60 * 1000)
    addEvent(function()
        saveServer()
        cleanMap()
        broadcastMessage("Map cleaned.", MESSAGE_STATUS_WARNING)
    end, 5 * 60 * 1000)
    return true
end
 
Yeah, that is strange. You can try this alternative, but if this doesn't go to server log then I'm not sure.

LUA:
    broadcastMessage("Map cleaning in 5 minutes.", MESSAGE_STATUS_WARNING)
    addEvent(function() broadcastMessage("Map cleaning in 3 minutes.", MESSAGE_STATUS_WARNING) end, 2 * 60 * 1000)
    addEvent(function() broadcastMessage("Map cleaning in 1 minutes.", MESSAGE_STATUS_WARNING) end, 4 * 60 * 1000)
    addEvent(function()
        saveServer()
        cleanMap()
        broadcastMessage("Map cleaned.", MESSAGE_STATUS_WARNING)
    end, 5 * 60 * 1000)
    return true
end
works
 
Back
Top