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

Solved Problem with save script.

dominique120

Science & Reason
Senator
Premium User
Joined
Jun 16, 2013
Messages
3,881
Solutions
3
Reaction score
1,043
Location
Númenor
I have this error:
Code:
Lua Script Error: [Test Interface]
data/globalevents/scripts/save.lua
data/globalevents/scripts/save.lua:8: attempt to call global 'getBooleanFromStri
ng' (a nil value)
stack traceback:
        [C]: in function 'getBooleanFromString'
        data/globalevents/scripts/save.lua:8: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/save.lua
data/globalevents/scripts/effectile.lua:22: '}' expected (to close '{' at line 1
) near 'effects'

With this script:
Code:
local config = {
    broadcast = {120, 30, 5},
    shallow = "no",
    delay = 120,
    events = 30
}

config.shallow = getBooleanFromString(config.shallow)

local function executeSave(seconds)
    if(isInArray(config.broadcast, seconds)) then
        local text = ""
        if(not config.shallow) then
            text = "Full s"
        else
            text = "S"
        end

        text = text .. "erver save within " .. seconds .. " seconds, please mind it may freeze!"
        doBroadcastMessage(text)
    end

    if(seconds > 0) then
        addEvent(executeSave, config.events * 1000, seconds - config.events)
    else
        doSaveServer(config.shallow)
    end
end

function onThink(interval)
    if(table.maxn(config.broadcast) == 0) then
        doSaveServer(config.shallow)
    else
        executeSave(config.delay)
    end

    return true
end

Its a save script from 0.4 but I'm moving to 1.0 and the default script is a globalsave(afaik)
 
lol.. I'm blind :)

check function 050-function.lua


Code:
function getBooleanFromString(input)
    local tmp = type(input)
    if(tmp == 'boolean') then
        return input
    end

    if(tmp == 'number') then
        return input > 0
    end

    local str = string.lower(tostring(input))
    return (str == "yes" or str == "true" or (tonumber(str) ~= nil and tonumber(str) > 0))
end


and error in...

Code:
data/globalevents/scripts/effectile.lua:22: '}' expected (to close '{' at line 1
) near 'effects'
 
lol.. I'm blind :)

check function 050-function.lua


Code:
function getBooleanFromString(input)
    local tmp = type(input)
    if(tmp == 'boolean') then
        return input
    end

    if(tmp == 'number') then
        return input > 0
    end

    local str = string.lower(tostring(input))
    return (str == "yes" or str == "true" or (tonumber(str) ~= nil and tonumber(str) > 0))
end

and error in...

Code:
data/globalevents/scripts/effectile.lua:22: '}' expected (to close '{' at line 1
) near 'effects'


I'll see if this works when the server saves, now there is no error though, and about the other error I just removes it, I no loner need it.

And TFS does not have a libs folder, I just placed that in global.lua
 
Here you go:
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()
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 onTime(interval)
        broadcastMessage("Server is saving game in 5 minutes. Please go to a safe place.", MESSAGE_STATUS_WARNING)
        Game.setGameState(GAME_STATE_STARTUP)
        addEvent(firstServerSaveWarning, 120000)
        return not shutdownAtServerSave
end
 
in global events.xml i put this

<globalevent name="serversave" interval="3600000" event="script" value="serversave.lua"/>

that is one hour? and that is right or wrong i need help with this X_X

<globalevent name="Server Save" interval="7200000" script="save.lua" />

7200000 is 2 hours
 
Hello guys, i have an error message when i add this line
Code:
    <globalevent name="serverSave" interval="360000" script="serverSave.lua"/>
in globalevents.xml

7nk8.png


Uploaded with ImageShack.us

and yes.. i have the serverSave.lua on the corresponding folder..



Uploaded with ImageShack.us

and i used the code from Printer 4 post above this one.. so this is a little bit confusing :S.. does anyone knows how to fix? i dont know what it's wrong :(..
 
Last edited:
use this script it works fine for me with TFS 1.0
<globalevent name="Server Save" time="09:55:00" script="serversave.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

if u wanna change it to an interval instead of an time change onTime to onThink
 
when i change onTime to onThink same error

[Warning - Event::checkScript] Can not load script: scripts/serverSave.lua
cannot open data/globalevents/scripts/serverSave.lua: No such file or directory
 
Back
Top