You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.4 KiB
Lua

8 years ago
--[[
XP and statistics addon for the "Zombie Survival" gamemode
by David Vogel (Dadido3)
]]
D3stats = D3stats or {}
8 years ago
AddCSLuaFile("sh_settings.lua")
AddCSLuaFile("sh_level.lua")
AddCSLuaFile("sh_concommand.lua")
8 years ago
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("cl_network.lua")
AddCSLuaFile("cl_hud.lua")
AddCSLuaFile("vgui/overlay.lua")
8 years ago
include("sh_settings.lua")
include("sh_level.lua")
include("sh_concommand.lua")
8 years ago
include("gamemodes/sv_zombiesurvival.lua")
include("sv_storage.lua")
include("sv_map.lua")
include("sv_network.lua")
8 years ago
hook.Add("PlayerInitialSpawn", "D3stats_PlayerSpawn", function (ply)
8 years ago
-- Send its own XP
ply:D3stats_Net_UpdateXP()
8 years ago
-- Store level as network and local player variable
ply.D3stats_Level = D3stats.CalculateLevel(ply:D3stats_GetXP())
ply:SetNWInt("D3stats_Level", ply.D3stats_Level)
end)
8 years ago
-- Initialisation
hook.Add("Initialize", "D3stats_Init", function ()
D3stats.Storage.Initialize()
resource.AddFile("resource/fonts/ghoulfriaoe.ttf")
resource.AddFile("resource/fonts/hauntaoe.ttf")
resource.AddFile("resource/fonts/nightaoe.ttf")
end)
local meta = FindMetaTable("Player")
8 years ago
if not meta then return end
function meta:D3stats_GetXP()
local XP = tonumber(self:GetPData("D3stats_XP", "0"))
8 years ago
if not XP then
XP = 0
end
return XP
end
function meta:D3stats_SetXP(XP)
8 years ago
if not XP then
XP = 0
end
self:SetPData("D3stats_XP", tostring(XP))
8 years ago
self:D3stats_Net_UpdateXP()
8 years ago
-- Update network variable and send message on level change
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)
8 years ago
end
self.D3stats_Level = Level
8 years ago
end
function meta:D3stats_AddXP(XP)
8 years ago
if not XP then
XP = 0
end
self:D3stats_SetXP(self:D3stats_GetXP() + XP)
8 years ago
end
function meta:D3stats_GetLevel()
return self.D3stats_Level
8 years ago
end
-- Check if the players level has the permission
function meta:D3stats_HasPermission(Permission)
8 years ago
-- 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
8 years ago
return true
end
return D3stats.LevelCheckPermission(self:D3stats_GetLevel(), Permission)
end