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

TFS 1.X+ [TFS 1.3][Globalevent] save my server every 3 hours.

Eduardo170

Well-Known Member
Joined
Jan 7, 2014
Messages
422
Solutions
3
Reaction score
66
Location
Caracas, Venezuela
I need a globalevent script that save my server every 3 hours, save everything and clean my map, with a message of warning of 5 minutes.
Plus: If possible a talkaction script for my god for when I want save my server.
 
1. here is it
2. something like this maybe:

Lua:
local talk = TalkAction("/save")

function talk.onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local players = Game.getPlayers()
    for i = 1, #players do
        players[i]:save()
    end
    return true
end

talk:register()
 
How do I make this run every 3 hours?
globalevents.xml

change:
<globalevent name="Server Save" time="09:55:00" script="serversave.lua" />

to:
<globalevent name="Server Save" interval="1080000" script="serversave.lua" />

or 10800, I don't remember if interval is in seconds or milliseconds
 
Mmm.
Code:
[Warning - Event::checkScript] Event onThink not found. scripts/serversave.lua


About talkaction...
I created the "scripts" folder, I put talkaction script inside. I reset my server and nothing happen . I dont have idea.
 
my bad, you need to edit the serversave.lua


change onTime to onThink

the talkaction should be working, it doesn't display any message at all, if you want just add:

player:sendCancelMessage("save completed")
 
Solution
clean.lua

Lua:
local shutdownAtServerSave = false 
local cleanMapAtServerSave = true
  
local function serverSave()
    if shutdownAtServerSave then
        Game.setGameState(GAME_STATE_SHUTDOWN)
    else
        Game.setGameState(GAME_STATE_NORMAL)
    end

    if cleanMapAtServerSave then
        cleanMap()
    end
    

    saveServer()
    Game.broadcastMessage("Map was cleaned, next cleaning in 3 hours", MESSAGE_STATUS_WARNING)
end

local function thirdServerSaveWarning()
    addEvent(serverSave, 1000)
end


local function secondServerSaveWarning()
    addEvent(thirdServerSaveWarning, 60000)
    Game.broadcastMessage("Map will be cleared in 1 minute", MESSAGE_STATUS_WARNING)
end


function onThink(interval, lastExecution)
    addEvent(secondServerSaveWarning, 240000)
    Game.broadcastMessage("Map will be cleared in 5 minutes", MESSAGE_STATUS_WARNING)
    return not shutdownAtServerSave
end

Code:
<globalevent name="Clean" interval="10800000" script="clean.lua" />
 
my bad, you need to edit the serversave.lua


change onTime to onThink

the talkaction should be working, it doesn't display any message at all, if you want just add:

player:sendCancelMessage("save completed")
Well, I was doing something wrong xD, mb.

clean.lua

Lua:
local shutdownAtServerSave = false
local cleanMapAtServerSave = true
 
local function serverSave()
    if shutdownAtServerSave then
        Game.setGameState(GAME_STATE_SHUTDOWN)
    else
        Game.setGameState(GAME_STATE_NORMAL)
    end

    if cleanMapAtServerSave then
        cleanMap()
    end
   

    saveServer()
    Game.broadcastMessage("Map was cleaned, next cleaning in 3 hours", MESSAGE_STATUS_WARNING)
end

local function thirdServerSaveWarning()
    addEvent(serverSave, 1000)
end


local function secondServerSaveWarning()
    addEvent(thirdServerSaveWarning, 60000)
    Game.broadcastMessage("Map will be cleared in 1 minute", MESSAGE_STATUS_WARNING)
end


function onThink(interval, lastExecution)
    addEvent(secondServerSaveWarning, 240000)
    Game.broadcastMessage("Map will be cleared in 5 minutes", MESSAGE_STATUS_WARNING)
    return not shutdownAtServerSave
end

Code:
<globalevent name="Clean" interval="10800000" script="clean.lua" />
Thank you!.
 
clean.lua

Lua:
local shutdownAtServerSave = false
local cleanMapAtServerSave = true
 
local function serverSave()
    if shutdownAtServerSave then
        Game.setGameState(GAME_STATE_SHUTDOWN)
    else
        Game.setGameState(GAME_STATE_NORMAL)
    end

    if cleanMapAtServerSave then
        cleanMap()
    end
   

    saveServer()
    Game.broadcastMessage("Map was cleaned, next cleaning in 3 hours", MESSAGE_STATUS_WARNING)
end

local function thirdServerSaveWarning()
    addEvent(serverSave, 1000)
end


local function secondServerSaveWarning()
    addEvent(thirdServerSaveWarning, 60000)
    Game.broadcastMessage("Map will be cleared in 1 minute", MESSAGE_STATUS_WARNING)
end


function onThink(interval, lastExecution)
    addEvent(secondServerSaveWarning, 240000)
    Game.broadcastMessage("Map will be cleared in 5 minutes", MESSAGE_STATUS_WARNING)
    return not shutdownAtServerSave
end

Code:
<globalevent name="Clean" interval="10800000" script="clean.lua" />
its save server code? you just called it clean?
Post automatically merged:

my bad, you need to edit the serversave.lua


change onTime to onThink

the talkaction should be working, it doesn't display any message at all, if you want just add:

player:sendCancelMessage("save completed")
where to add the "player:sendCancelMessage("save completed")" exectly please?
 
Last edited:
Back
Top