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

GlobalEvent Server Save [Optimized, less lag] v1.8

As far I know, no.

- - - Updated - - -

I'm sure it can be more optimized but will have some exploits
 
This should make lag even more than default server save...

Bitch please, why people doing shit...
 
No, it doesn't cause lags. (max 2 seconds in a sux dedicated server)
Tested by 5 or more servers with 74~500 players online

I suggest you to test before talking a lot
 
No, it doesn't cause lags. (max 2 seconds in a sux dedicated server)
Tested by 5 or more servers with 74~500 players online

No no, I'm serious... If you were at least experienced and know any differences between Lua and C++ you would understand but you just don't know what you doing and saying.

I can simply explain in few sentences why:

1. Lua is way slower and uses more resources to count every player in-game and then to save player and after save player save his house.
2. TFS server engine is wrote in c++ language this means it is even faster than Lua and default server save going right to engine core and all counting and save is made in TFS engine.

You see we use Lua scripting language to avoid hardcore codings in c++. This should be simple and easy to understand for everybody now.
 
Ok, I agree, just explain now why my LUA is faster than C++ in this case

LUA cannot be faster than C++, in this case ur script is divided on some stages of saving, that's why there's no much lag, I don't support this way of saving, but idea is good.
 
Last edited:
No no, I'm serious... If you were at least experienced and know any differences between Lua and C++ you would understand but you just don't know what you doing and saying.

I can simply explain in few sentences why:

1. Lua is way slower and uses more resources to count every player in-game and then to save player and after save player save his house.
2. TFS server engine is wrote in c++ language this means it is even faster than Lua and default server save going right to engine core and all counting and save is made in TFS engine.

You see we use Lua scripting language to avoid hardcore codings in c++. This should be simple and easy to understand for everybody now.

Doing save by lua makes hardly a difference.
 
I know C++ is better than lua,the point is Server Save by C++ freezes and this lua no.
 
instead of having global saves every X time, why don't you have individual saves every X time?
when a player logs in, you give him an onThink event that after X time the player is saved, that way each player is individually saved independently and it wont cause any lag at all since the chance that 2 or more players will save at the exact same time is next to 0
 
I have both Global Saves in my server, this one that I posted is the one I'm using just one time per day
 
I dont understand why server save is a problem? if it cause freeze for approximately 4 sec, its not the end of your server. also tibia makes. a restart instead of server save, since, it would take alot of time for them to do it.

also I like scarlet proposal
 
instead of having global saves every X time, why don't you have individual saves every X time?
when a player logs in, you give him an onThink event that after X time the player is saved, that way each player is individually saved independently and it wont cause any lag at all since the chance that 2 or more players will save at the exact same time is next to 0

I use this creature script in my server :

Code:
function saveRepeat(cid)
    if not isPlayer(cid) then return true end
    doPlayerSave(cid)
    doPlayerSendTextMessage(cid,19, 'Seu Char foi salvo automaticamente.')
    doSendMagicEffect(getThingPos(cid), 65)
    save = addEvent(saveRepeat, math.random(20,30) *60*1000, cid)
end
 
function onLogin(cid)
    save = addEvent(saveRepeat, math.random(20,30)*60*1000, cid)
    return true
end
 
function onLogout(cid)
    stopEvent(save)
    return true
end
 
@lucas proposal
I was looking at ur code and I see it having 2 problems
first is that you're getting all players twice, which can be rendered unnecessary(see code below)
second, you're repeating code for the odd/pair function just because of the comparison, this bothers me so much

Lua:
-- Local config
local timetosave = 30000 -- It's time to save after broadcast, delay 30 seconds
local delay = 5000 -- It's time to save odd after pair, delay 5 seconds


local function save()
    for _, cid in ipairs(getPlayersOnline()) do
        if getPlayerGUID(cid) % 2 == 0 then
            savePlayer(cid)
        else
            addEvent(savesavePlayer, delay, cid)
        end
    end
end


local function savePlayer(cid)
    doPlayerSave(cid)
    doSaveHouse({getHouseByPlayerGUID(getPlayerGUID(cid))})
    return true
end
 
function onThink(interval, lastExecution, thinkInterval)
    addEvent(save, timetosave)
    doBroadcastMessage("Server save within 30 seconds, please mind it may freeze.")
end
I think this code is much more elegant :)

- - - Updated - - -

I use this creature script in my server :

Code:
function saveRepeat(cid)
    if not isPlayer(cid) then return true end
    doPlayerSave(cid)
    doPlayerSendTextMessage(cid,19, 'Seu Char foi salvo automaticamente.')
    doSendMagicEffect(getThingPos(cid), 65)
    save = addEvent(saveRepeat, math.random(20,30) *60*1000, cid)
end
 
function onLogin(cid)
    save = addEvent(saveRepeat, math.random(20,30)*60*1000, cid)
    return true
end
 
function onLogout(cid)
    stopEvent(save)
    return true
end
Exactly what I mean, but using an onThink script instead of addEvent, that way you don't have to do that check if the player still exists nor the stopEvent if he logs out(if isPlayer(cid) ...)
 
@lucas proposal
I was looking at ur code and I see it having 2 problems
first is that you're getting all players twice, which can be rendered unnecessary(see code below)
second, you're repeating code for the odd/pair function just because of the comparison, this bothers me so much

Lua:
-- Local config
local timetosave = 30000 -- It's time to save after broadcast, delay 30 seconds
local delay = 5000 -- It's time to save odd after pair, delay 5 seconds


local function save()
	for _, cid in ipairs(getPlayersOnline()) do
		if getPlayerGUID(cid) % 2 == 0 then
			savePlayer(cid)
		else
			addEvent(savesavePlayer, delay, cid)
		end
	end
end


local function savePlayer(cid)
	doPlayerSave(cid)
	doSaveHouse({getHouseByPlayerGUID(getPlayerGUID(cid))})
	return true
end
 
function onThink(interval, lastExecution, thinkInterval)
	addEvent(save, timetosave)
	doBroadcastMessage("Server save within 30 seconds, please mind it may freeze.")
end
I think this code is much more elegant :)

- - - Updated - - -


Exactly what I mean, but using an onThink script instead of addEvent, that way you don't have to do that check if the player still exists(if isPlayer(cid) ...)

I'd give rep but I have to spread the love first...
 
@lucas proposal
I was looking at ur code and I see it having 2 problems
first is that you're getting all players twice, which can be rendered unnecessary(see code below)
second, you're repeating code for the odd/pair function just because of the comparison, this bothers me so much

Lua:
-- Local config
local timetosave = 30000 -- It's time to save after broadcast, delay 30 seconds
local delay = 5000 -- It's time to save odd after pair, delay 5 seconds


local function save()
    for _, cid in ipairs(getPlayersOnline()) do
        if getPlayerGUID(cid) % 2 == 0 then
            savePlayer(cid)
        else
            addEvent(savesavePlayer, delay, cid)
        end
    end
end


local function savePlayer(cid)
    doPlayerSave(cid)
    doSaveHouse({getHouseByPlayerGUID(getPlayerGUID(cid))})
    return true
end
 
function onThink(interval, lastExecution, thinkInterval)
    addEvent(save, timetosave)
    doBroadcastMessage("Server save within 30 seconds, please mind it may freeze.")
end
I think this code is much more elegant :)

- - - Updated - - -


Exactly what I mean, but using an onThink script instead of addEvent, that way you don't have to do that check if the player still exists nor the stopEvent if he logs out(if isPlayer(cid) ...)

Updated first post and added your credits
 
I will write a code how I do imagine how should be with less lag. Just because I started to complicate this thread.
 
its true that doing it by sources should in theory be faster, why it is slower, I don't know, I'd have to check the sources to see how the server does the global save, but I can't expect it to be much different then this
 
I will write a code how I do imagine how should be with less lag. Just because I started to complicate this thread.

Now you got it. I think if I share good things with the community, everybody can greatly improve my ideas some way, again, helping the whole community

- - - Updated - - -

Updated main post
 
But one question, i thougt save was made on sources and just executed on lua?
 
Back
Top