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

Lua mission global save

Kahras

Member
Joined
Aug 6, 2012
Messages
101
Reaction score
7
Location
Warsaw
Hi, I am writing asking if anyone has an idea how I could do a mission that resets after server save and the player could do it again?
I'd like someone to guide me, I'll do the rest myself.
 
You need to reset this particular storage on each character. A tip: Do this in globalevents, in startup.
Then, whenever the server starts, it will reset this storage.
Post automatically merged:

Maybe something like this:
Lua:
function onStartup()
    local storageValue = 123456
    db.executeQuery("DELETE FROM `player_storage` WHERE `key`.`".. storageValue .."` = 1;")
end
Post automatically merged:

Also you can reset storage in a way I just thought of:
Whenever the character enters the game, he will have a check if a day has passed. If a day has passed, it will reset the storage.
Lua:
local config = {
    storage = 123456,
}

function onLogin(player)
    local checkStorage = 556655
    if player:getStorageValue(checkStorage) ~= os.date("%d") then
        player:setStorageValue(checkStorage, os.date("%d"))
        player:setStorageValue(config.storage, 0)
    end
end
 
Last edited:
Thanks, that's what I was having trouble with, but now I know everything.
Will use the first option.
I believe if you want it each serverSave you should use this

Lua:
local shutdownAtServerSave = false
local cleanMapAtServerSave = true
local closeAtSave = true
local function serverSave()
    local storageValue = 123456
    db.executeQuery("DELETE FROM `player_storage` WHERE `key`.`".. storageValue .."` = 1;")
    if shutdownAtServerSave then
        Game.setGameState(GAME_STATE_SHUTDOWN)
        if cleanMapAtServerSave then
            cleanMap()
        end

        Game.setGameState(GAME_STATE_NORMAL)
    end
    if closeAtSave then
        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

because onStartup needs a server restart which is not professional to restart the server every 24hours

this script works onTime specified in globalevents.xml you can change it to whatever suits you
 
Back
Top