• 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

I am very sorry to bump this...

But, I am getting error about a function "doSaveHouse"... I read that Im supposed to add it in my sources... I checked this thread:
http://otland.net/f35/dosavehouse-houseid-145403/
but im not good at C++ so I have no idea where to put these functions.

Also, the individual save (few mins after a player logins) seems not to work... I mean, the script contains the function doSaveHouse which I dont have in my sources but i am not getting any error ;o
 
You will have to use newest revs or add dosavehouse yourself. I cant help you because i couldnt add it too :/
 
Hi what system I use? max 50 players will evo
or in the config I have to change something?
 
I came up with another solution. Saving each player with a delay of i.e. 30 ms to previous one. Should reduce lags to minimum. Cons: if there are 300+ ppl the save can last like 9 s to save all players without lags.

Lua:
function savePlayer(cid)
	return isPlayer(cid) and doPlayerSave(cid)
end

function savePlayers()
	delay = 30 -- In ms (if set to 30 and there are 300 players on the server the save should take 9 s)
	playersOnline = getPlayersOnline() 
	for i = 1, #playersOnline  do
		addEvent(savePlayer, delay * i, playersOnline [i])
	end
	return true
end
 
It is globalevent right?

- - - Updated - - -

What about it?
Lua:
local function doSavePlayerAndHouse(cid)
	doPlayerSave(cid)
	doSaveHouse({getHouseByPlayerGUID(getPlayerGUID(cid))})
	return true
end
 
local function save()
	local delay = 30 -- In ms (if set to 30 and there are 300 players on the server the save should take 9 s)
	local playersOnline = getPlayersOnline() 
	for i = 1, #playersOnline  do
		addEvent(doSavePlayerAndHouse, delay * i, playersOnline [i])
	end
	return true
end

function onThink(interval, lastExecution, thinkInterval)
    addEvent(save, timetosave)
    doBroadcastMessage("Server save within 30 seconds, please mind it may freeze.")
end

Known problem: It will not save all houses. Only online player's house.
 
Last edited:
It is globalevent right?

- - - Updated - - -

What about it?
Lua:
local function doSavePlayerAndHouse(cid)
	doPlayerSave(cid)
	doSaveHouse({getHouseByPlayerGUID(getPlayerGUID(cid))})
	return true
end
 
local function save()
	local delay = 30 -- In ms (if set to 30 and there are 300 players on the server the save should take 9 s)
	local playersOnline = getPlayersOnline() 
	for i = 1, #playersOnline  do
		addEvent(doSavePlayerAndHouse, delay * i, playersOnline [i])
	end
	return true
end

function onThink(interval, lastExecution, thinkInterval)
    addEvent(save, timetosave)
    doBroadcastMessage("Server save within 30 seconds, please mind it may freeze.")
end

Known problem: It will not save all houses. Only online player's house.
Lua:
local function doSavePlayerAndHouse(cid)
	doPlayerSave(cid)
	doSaveHouse({getHouseByPlayerGUID(getPlayerGUID(cid))})
	return true
end

local delay = 30 -- In ms (if set to 30 and there are 300 players on the server the save should take 9 s)
local function save()
	local playersOnline = getPlayersOnline() 
	for i = 1, #playersOnline  do
		addEvent(doSavePlayerAndHouse, delay * i, playersOnline [i])
	end
	return true
end
 
function onThink(interval, lastExecution, thinkInterval)
    addEvent(save, timetosave)
    doBroadcastMessage("Server save within 30 seconds, please mind it takes " .. math.ceil(delay * #getPlayersOnline() / 1000 seconds) .. " seconds to save all players.")
end

Other houses may be saved in another call after the main save. It will still lag less. :p
 
Updated main post:

Save Houses
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
 
Shouldn't I register anything to login.lua if I use the creatureevent save?
 
[Error - GlobalEvents::think] Couldn't execute event: save. Can I help me? please :)
 
Back
Top