Save points in an interval

This commit is contained in:
David Vogel 2018-07-20 15:49:38 +02:00
parent 4eedec5bb7
commit 1978768a5d

View File

@ -4,6 +4,7 @@ if engine.ActiveGamemode() ~= "zombiesurvival" then return end
local settings = {
StartingSavedPoints = 100,
MinimumPoints = 0,
PointsaveInterval = 30, -- Save points every x seconds
IgnoredMaps = { -- Use $ at the end if you want to define exact map names with versions. (Otherwise it will match with all maps beginning with the given name)
"zs_obj_gauntlet",
"zs_gauntlet_reborn"
@ -19,6 +20,8 @@ end
local function savePoints(ply)
if PointSaving_shouldIgnoreMap(game.GetMap()) then return end
if not ply.PointSaving_Loaded then return end
if ply:Team() == TEAM_HUMAN then
ply:SetSavedPoints(ply:GetPoints())
end
@ -34,7 +37,13 @@ hook.Add("PostEndRound", "pointsave_postendround", function(winner)
end
end)
-- TODO: Save points every minute or so
timer.Create("pointsave_pointsavetimer", settings.PointsaveInterval, 0, function()
if PointSaving_shouldIgnoreMap(game.GetMap()) then return end
for k, ply in pairs(player.GetAll()) do
savePoints(ply)
end
end)
local function loadPoints(ply)
if PointSaving_shouldIgnoreMap(game.GetMap()) then return end
@ -42,6 +51,7 @@ local function loadPoints(ply)
timer.Simple(0, function()
if IsValid(ply) and ply:Team() == TEAM_HUMAN then
ply:SetPoints(ply:GetSavedPoints())
ply.PointSaving_Loaded = true
end
end)
@ -58,7 +68,7 @@ function meta:GetSavedPoints()
if SERVER then
local points = self:GetPData("zs_savedpoints", settings.StartingSavedPoints)
self:SetNWInt("zs_savedpoints", points)
print("### PS Loaded: "..points)
--print("### PS Loaded: "..points)
return points
end
@ -72,7 +82,7 @@ if not SERVER then return end
function meta:SetSavedPoints(amount)
if amount < settings.MinimumPoints then amount = settings.MinimumPoints end
amount = math.Round(amount)
print("### PS Saved: "..amount)
--print("### PS Saved: "..amount)
self:SetNWInt("zs_savedpoints", amount)
self:SetPData("zs_savedpoints", amount)
end