2020-01-22 14:25:58 +00:00
|
|
|
-- Copyright (c) 2020 David Vogel
|
|
|
|
--
|
|
|
|
-- This software is released under the MIT License.
|
|
|
|
-- https://opensource.org/licenses/MIT
|
|
|
|
|
2016-10-05 12:30:35 +00:00
|
|
|
--[[
|
|
|
|
|
|
|
|
XP and statistics addon for the "Zombie Survival" gamemode
|
|
|
|
by David Vogel (Dadido3)
|
|
|
|
|
|
|
|
]]
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
D3stats = D3stats or {}
|
2016-10-05 12:30:35 +00:00
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
AddCSLuaFile("sh_settings.lua")
|
|
|
|
AddCSLuaFile("sh_level.lua")
|
|
|
|
AddCSLuaFile("sh_concommand.lua")
|
2016-10-05 12:30:35 +00:00
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
AddCSLuaFile("cl_init.lua")
|
|
|
|
AddCSLuaFile("cl_network.lua")
|
|
|
|
AddCSLuaFile("cl_hud.lua")
|
|
|
|
AddCSLuaFile("vgui/overlay.lua")
|
2016-10-05 12:30:35 +00:00
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
include("sh_settings.lua")
|
|
|
|
include("sh_level.lua")
|
|
|
|
include("sh_concommand.lua")
|
2016-10-05 12:30:35 +00:00
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
include("gamemodes/sv_zombiesurvival.lua")
|
|
|
|
include("sv_storage.lua")
|
|
|
|
include("sv_map.lua")
|
|
|
|
include("sv_network.lua")
|
2016-10-05 12:30:35 +00:00
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
hook.Add("PlayerInitialSpawn", "D3stats_PlayerSpawn", function (ply)
|
2016-10-05 12:30:35 +00:00
|
|
|
-- Send its own XP
|
2018-08-03 09:22:18 +00:00
|
|
|
ply:D3stats_Net_UpdateXP()
|
2016-10-05 12:30:35 +00:00
|
|
|
|
2016-10-07 07:31:59 +00:00
|
|
|
-- Store level as network and local player variable
|
2018-08-03 09:22:18 +00:00
|
|
|
ply.D3stats_Level = D3stats.CalculateLevel(ply:D3stats_GetXP())
|
|
|
|
ply:SetNWInt("D3stats_Level", ply.D3stats_Level)
|
|
|
|
end)
|
2016-10-05 12:30:35 +00:00
|
|
|
|
2016-10-09 16:11:56 +00:00
|
|
|
-- Initialisation
|
2018-08-03 09:22:18 +00:00
|
|
|
hook.Add("Initialize", "D3stats_Init", function ()
|
|
|
|
D3stats.Storage.Initialize()
|
2016-10-09 16:11:56 +00:00
|
|
|
|
|
|
|
resource.AddFile("resource/fonts/ghoulfriaoe.ttf")
|
|
|
|
resource.AddFile("resource/fonts/hauntaoe.ttf")
|
|
|
|
resource.AddFile("resource/fonts/nightaoe.ttf")
|
2018-08-03 09:22:18 +00:00
|
|
|
end)
|
2016-10-09 16:11:56 +00:00
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
local meta = FindMetaTable("Player")
|
2016-10-05 12:30:35 +00:00
|
|
|
if not meta then return end
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
function meta:D3stats_GetXP()
|
|
|
|
local XP = tonumber(self:GetPData("D3stats_XP", "0"))
|
2016-10-05 12:30:35 +00:00
|
|
|
|
|
|
|
if not XP then
|
|
|
|
XP = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
return XP
|
|
|
|
end
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
function meta:D3stats_SetXP(XP)
|
2016-10-05 12:30:35 +00:00
|
|
|
if not XP then
|
|
|
|
XP = 0
|
|
|
|
end
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
self:SetPData("D3stats_XP", tostring(XP))
|
2016-10-05 12:30:35 +00:00
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
self:D3stats_Net_UpdateXP()
|
2016-10-05 12:30:35 +00:00
|
|
|
|
2016-10-07 07:31:59 +00:00
|
|
|
-- Update network variable and send message on level change
|
2018-08-03 09:22:18 +00:00
|
|
|
local Level = D3stats.CalculateLevel(XP)
|
|
|
|
if self.D3stats_Level and self.D3stats_Level ~= Level then
|
|
|
|
self:SetNWInt("D3stats_Level", Level)
|
|
|
|
hook.Call("D3stats_LevelChanged" , nil, self, self.D3stats_Level, Level)
|
2016-10-05 12:30:35 +00:00
|
|
|
end
|
2018-08-03 09:22:18 +00:00
|
|
|
self.D3stats_Level = Level
|
2016-10-05 12:30:35 +00:00
|
|
|
end
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
function meta:D3stats_AddXP(XP)
|
2016-10-05 12:30:35 +00:00
|
|
|
if not XP then
|
|
|
|
XP = 0
|
|
|
|
end
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
self:D3stats_SetXP(self:D3stats_GetXP() + XP)
|
2016-10-05 12:30:35 +00:00
|
|
|
end
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
function meta:D3stats_GetLevel()
|
|
|
|
return self.D3stats_Level
|
2016-10-05 12:30:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Check if the players level has the permission
|
2018-08-03 09:22:18 +00:00
|
|
|
function meta:D3stats_HasPermission(Permission)
|
2016-10-05 12:30:35 +00:00
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
-- If there are too few players with this permission, allow it anyway
|
|
|
|
if D3stats.Permissions[Permission] and D3stats.Permissions[Permission].AllowIfLessThan and D3stats.Permissions[Permission].AllowIfLessThan > D3stats.CountPermissionPlayers(Permission, D3stats.Permissions[Permission].Team) then
|
2016-10-05 12:30:35 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
return D3stats.LevelCheckPermission(self:D3stats_GetLevel(), Permission)
|
2016-10-09 16:11:56 +00:00
|
|
|
end
|