Save points at round end

This commit is contained in:
David Vogel 2018-07-15 16:34:14 +02:00
parent 37661dfa68
commit a0222400d1

View File

@ -11,7 +11,7 @@ local settings = {
local function shouldIgnoreMap(mapName)
for k, v in ipairs(settings.IgnoredMaps) do
if string.match(mapName, "^"..v) then return true end
if string.match(string.lower(mapName), "^"..v) then return true end
end
end
@ -19,19 +19,27 @@ local function savePoints(ply)
if shouldIgnoreMap(game.GetMap()) then return end
if ply:Team() == TEAM_HUMAN then
print("### PS Saved: "..ply:GetPoints())
--print("### PS Saved: "..ply:GetPoints())
ply:SetSavedPoints(ply:GetPoints())
end
end
hook.Add("PlayerDeath", "pointsave_death", savePoints)
hook.Add("PlayerDisconnected", "pointsave_disconnect", savePoints)
hook.Add("PostEndRound", "pointsave_postendround", function(winner)
if shouldIgnoreMap(game.GetMap()) then return end
for k, ply in pairs(player.GetAll()) do
savePoints(ply)
end
end)
local function loadPoints(ply)
if shouldIgnoreMap(game.GetMap()) then return end
timer.Simple(0, function()
if IsValid(ply) and ply:Team() == TEAM_HUMAN then
print("### Loaded: "..ply:GetSavedPoints())
--print("### Loaded: "..ply:GetSavedPoints())
ply:SetPoints(ply:GetSavedPoints())
end
end)
@ -40,7 +48,7 @@ end
hook.Add("PlayerSpawn", "pointsave_spawn", loadPoints)
hook.Add("PlayerReadyRound", "pointsave_readyround", loadPoints) -- Fix for ZS:R. Problem: It can be called from client!
-- #### Player meta ####
-- #### Player meta #### TODO: Put in an extra file
local meta = FindMetaTable("Player") -- Get the meta table of player