2018-07-15 10:07:37 +00:00
2018-07-15 10:15:12 +00:00
if engine.ActiveGamemode ( ) ~= " zombiesurvival " then return end
2018-07-15 10:07:37 +00:00
2018-07-15 13:04:12 +00:00
local settings = {
StartingSavedPoints = 100 ,
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 "
}
}
local function shouldIgnoreMap ( mapName )
for k , v in ipairs ( settings.IgnoredMaps ) do
if string.match ( mapName , " ^ " .. v ) then return true end
2018-07-15 10:07:37 +00:00
end
2018-07-15 13:04:12 +00:00
end
2018-07-15 10:07:37 +00:00
2018-07-15 13:04:12 +00:00
local function savePoints ( ply )
if shouldIgnoreMap ( game.GetMap ( ) ) then return end
if ply : Team ( ) == TEAM_HUMAN then
print ( " ### PS Saved: " .. ply : GetPoints ( ) )
ply : SetSavedPoints ( ply : GetPoints ( ) )
2018-07-15 10:07:37 +00:00
end
2018-07-15 13:04:12 +00:00
end
hook.Add ( " PlayerDeath " , " pointsave_death " , savePoints )
hook.Add ( " PlayerDisconnected " , " pointsave_disconnect " , savePoints )
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 ( ) )
ply : SetPoints ( ply : GetSavedPoints ( ) )
2018-07-15 10:07:37 +00:00
end
2018-07-15 13:04:12 +00:00
end )
end
hook.Add ( " PlayerSpawn " , " pointsave_spawn " , loadPoints )
hook.Add ( " PlayerReadyRound " , " pointsave_readyround " , loadPoints ) -- Fix for ZS:R. Problem: It can be called from client!
2018-07-15 10:07:37 +00:00
2018-07-15 13:04:12 +00:00
-- #### Player meta ####
2018-07-15 10:07:37 +00:00
2018-07-15 13:04:12 +00:00
local meta = FindMetaTable ( " Player " ) -- Get the meta table of player
2018-07-15 10:07:37 +00:00
2018-07-15 13:04:12 +00:00
-- Shared methods
2018-07-15 10:07:37 +00:00
2018-07-15 13:04:12 +00:00
function meta : GetSavedPoints ( )
if SERVER then
local points = self : GetPData ( " zs_savedpoints " , settings.StartingSavedPoints )
self : SetNWInt ( " zs_savedpoints " , points )
return points
2018-07-15 10:07:37 +00:00
end
2018-07-15 13:04:12 +00:00
return self : GetNWInt ( " zs_savedpoints " , settings.StartingSavedPoints )
2018-07-15 10:07:37 +00:00
end
2018-07-15 13:04:12 +00:00
if not SERVER then return end
-- Server side methods
function meta : SetSavedPoints ( amount )
self : SetNWInt ( " zs_savedpoints " , amount )
self : SetPData ( " zs_savedpoints " , amount )
2018-07-15 10:07:37 +00:00
end
2018-07-15 13:04:12 +00:00
function meta : AddSavedPoints ( amount )
local points = self : GetSavedPoints ( )
self : SetSavedPoints ( points + amount )
2018-07-15 10:07:37 +00:00
end
2018-07-15 13:04:12 +00:00
function meta : TakeSavedPoints ( amount )
self : AddSavedPoints ( - amount )
2018-07-15 10:07:37 +00:00
end