• 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+ save lagging server for 3 to 4 seconds

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,210
Solutions
35
Reaction score
206
my server is currently with 30 players online and the save I put every 15 minutes in globalevents.xml (and this lags for 2 to 3 seconds during save)
LUA:
function onThink(interval, lastExecution)
    saveServer()
    return true
end
My computer is not very good and I do not intend to acquire a host for now ... I wanted to "optimize" save
so I saw that there is the function
LUA:
player:save()
Is it possible to create a way of this function to execute in all online, but in parts not to mill?
For example saves 5 players, after 5 seconds saves 5 more, after 5 seconds saves 5 more and so on?
or do you have a better idea than mine?
I believe we all think better together

had thought that way, but it will be the same consumption of the function I'm already using, right?
LUA:
function onThink(interval, lastExecution)
    local players = Game.getPlayers()
    for _, player in ipairs(players) do
        player:save()
    end
    return true
end
 
With this function you can store packages of 5 players in a table:
LUA:
local players = Game.getPlayers()
local saves = {{}}
local count, count2 = 1, 1
for index, player in pairs(players) do
    if index % 6 == 0 then
        count2 = 1
        count = count + 1
        saves[count] = {}
    end
    saves[count][count2] = player.uid
    count2 = count2 + 1
end

And with this you can use that table to save each package every 5 seconds:
LUA:
for index, pids in pairs(saves) do
addEvent(function(pids)
    for k, pid in pairs(pids) do
        local player = Player(pid)
        if player then
            player:save()
        end
    end
    end, (5000 * (index - 1)), pids)
end
 
I'm almost positive that can lead to unintentional item duping if players are not saved all at once.
That is true, if by chance your server crashes or closes at the moment when the players are being saved, or even if someone time the correct time to save can cheat the system and duplicate things from time to time.
 
Also players swapping an item within that 5 second time window where player A was already saved, B was not, A gives item to B, B relogs and gives it back, now both players have the item saved in database.
Not saying that they'll know when to do that, but over time that'll most likely happen at some point cause that time window is bigger than it seems.
 
Back
Top