Ir para conteúdo
  • 0

Server save


guigiannoni

Pergunta

5 respostass a esta questão

Posts Recomendados

  • 0
  • Administrador

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
Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...