LucasFerraz
Systems Analyst
I guess its safe
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
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
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.
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
-- 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
What this line does?
Code:if getPlayerGUID(cid) % 2 == 0 then