• 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

LucasFerraz

Systems Analyst
Joined
Jun 10, 2010
Messages
2,858
Reaction score
96
Location
Brazil
Server Save [Optimized, less lag] v2.0

Thank you to Migxxx, Summ for teaching me how to compare pair and odd.
Thank you to Scarlet Ayleid to optimize 'my' script a lot.

How it work:
It will save each hour.
It will only save houses if your server have function doSaveHouse working.
It will save first all character with ID pair and after 5 seconds ID odd.

Globalevents
XML:
    <globalevent name="save" interval="3600000" event="script" value="save.lua"/>

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 doSavePlayerAndHouse(cid)
    doPlayerSave(cid)
    doSaveHouse({getHouseByPlayerGUID(getPlayerGUID(cid))})
    return true
end

local function save()
    for _, cid in ipairs(getPlayersOnline()) do
        if getPlayerGUID(cid) % 2 == 0 then
            doSavePlayerAndHouse(cid)
        else
            addEvent(savesavePlayer, delay, cid)
        end
    end
end
 
 
local function savePlayer(cid)
    doSavePlayerAndHouse(cid)
    return true
end
 
function onThink(interval, lastExecution, thinkInterval)
    addEvent(save, timetosave)
    doBroadcastMessage("Server save within 30 seconds, please mind it may freeze.")
end


How it work:
It will save all houses. House per House. Including offline player's house.

XML:
    <globalevent name="savehouse" interval="3900000" event="script" value="savehouse.lua"/>
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 doSaveHouse(cid)
	doSaveHouse({getHouseByPlayerGUID(getPlayerGUID(cid))})
	return true
end
 
local function save()
	local result = db.getResult("SELECT * FROM houses WHERE (id > 0) ORDER BY id DESC LIMIT 1;")
	for _, cid in ipairs(result) do
		if (result:getID() < 1) then
			return true
        	else
            		addEvent(doSaveHouse, delay, cid)
        	end
	end
end
 
function onThink(interval, lastExecution, thinkInterval)
    addEvent(save, timetosave)
    doBroadcastMessage("Server save within 30 seconds, please mind it may freeze.")
end



- - - Individually version - - -

How it work:
When the character log, start counting his time, every 5 minutes saved.
Individually for each player.

Important Tip:
If not save player's house when he logout, there will be chance to clone.

Creatureevents
XML:
    <event type="login" name="saveOn" event="script" value="saveplayer.lua"/>
    <event type="logout" name="saveOff" event="script" value="saveplayer.lua"/>

Lua:
local config = { --Times are in seconds
    saveInterval = 5 * 60,
    minSaveInterval = 4 * 60,
    maxSaveInterval = 6 * 60,
    storage = 1111
}

local function doSavePlayerAndHouse(cid)
    doPlayerSave(cid)
    doSaveHouse({getHouseByPlayerGUID(getPlayerGUID(cid))})
    return true
end

function saveRepeat(cid)
    if isPlayer(cid) then
        doSavePlayerAndHouse(cid)
        setPlayerStorageValue(cid, config.storage, addEvent(saveRepeat, config.saveInterval*1000, cid))
    end
    return true
end

function onLogin(cid)
    setPlayerStorageValue(cid, config.storage, addEvent(saveRepeat, math.random(config.minSaveInterval, config.maxSaveInterval) * 1000, cid))
    return true
end

function onLogout(cid)
    doSaveHouse({getHouseByPlayerGUID(getPlayerGUID(cid))})
    stopEvent(getPlayerStorageValue(cid, config.storage))
    return true
end
 
Last edited:
Wow, so this is faster than TFS save? It takes 6-8 seconds for me now with 70 players +, is it normal?
 
Wow, so this is faster than TFS save? It takes 6-8 seconds for me now with 70 players +, is it normal?

Imagine 500 players in your server, it will cost around 30 seconds +-.
With my script i think it wont lag more than 2 seconds MAX but my filter end in lv150, you can add more filters

- - - Updated - - -

windows is normal

With my script it wont lag 6-8 seconds
 
What do you mean with end in lvl 150?
So those above lvl 150 wont get saved?
 
"It will save first all character level 50 or less
after it will count 30 seconds and save characters level 51~100
after it will count 30 seconds and save characters level 101~150
after it will count 30 seconds and save characters level 150~"
You can increast this filters to 150~200 and more

- - - Updated - - -

yes yes

tested here !!!
repp++

Did it freezed any second?
 
I think.. can cloned.. whit this...

edit.. remove way to do
 
"It will save first all character level 50 or less
after it will count 30 seconds and save characters level 51~100
after it will count 30 seconds and save characters level 101~150
after it will count 30 seconds and save characters level 150~"
You can increast this filters to 150~200 and more

- - - Updated - - -

Did it freezed any second?

Not freezed using LINUX with 4GB ram
112 On

Added more rates until 300
 
not even a millisecond?

Logically yes, most do not have a long save.

it depends on the operating system, mysql tunner, processor and memory

** Update **

in my server, i use tilelimit = 7
 
Last edited:
:blink: what check this?

if getPlayerGUID(cid) % 2 == 0 then

?
 
It's used to check if character ID in DB is pair or odd
It will save all pair and after all odd it will cause less lag (or no lags)

- - - Updated - - -

I guess it's good enough to cause clones now
 
Looks awesome, i will try it out :D
 
Back
Top