GU
dúvida

Server save

Por guigiannoni, 20 de ago. de 2015 em Scripts

save
6
2.3k
guigiannoniG
20 de agosto de 2015 às 11:41
Meu servidor não salva automaticamente, como adicionar?


LumusL
20 de agosto de 2015 às 11:43

Qual a versão do seu servidor?

AdministradorA
20 de agosto de 2015 às 11:45
Melhor resposta

Segue abaixo o script.

 

SERVER SAVE GERAL

data/globalevents/globalevents.xml

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

data/globalevents/scripts

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

HOUSE SAVE

<globalevent name="savehouse" interval="3900000" event="script" value="savehouse.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

PLAYER SAVE

<event type="login" name="saveOn" event="script" value="saveplayer.lua"/>
<event type="logout" name="saveOff" event="script" value="saveplayer.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
guigiannoniG
20 de agosto de 2015 às 11:59

Obrigado Daniel!!!

LumusL
20 de agosto de 2015 às 12:04

Obrigado Daniel!!!

Dúvida sanada?
SkyLighS
20 de agosto de 2015 às 12:18

Movido para resolvidos.