LucasFerraz
Systems Analyst
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
How it work:
It will save all houses. House per House. Including offline player's house.
- - - 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
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: