forked from Dadido3/D3stats
Fixes and cleanup
- use Set/GetNWInt() - put everything ZS related in its own file - Added team to permissions - Added font setting
This commit is contained in:
parent
e2db00b0ea
commit
a50c3e0359
@ -1,4 +1,4 @@
|
|||||||
-- Delete HUD and redo if already existent. This will reset the values until the next update from the server
|
-- Delete HUD and redo if already existent. This will reset the displayed values until the next update from the server
|
||||||
if d3stats.D3StatsOverlay then
|
if d3stats.D3StatsOverlay then
|
||||||
d3stats.D3StatsOverlay:Remove()
|
d3stats.D3StatsOverlay:Remove()
|
||||||
d3stats.Overlay_Init()
|
d3stats.Overlay_Init()
|
||||||
@ -14,16 +14,17 @@ function d3stats.Overlay_Init()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Call this function from cl_targetid.lua in the gamemode
|
-- Call this function from cl_targetid.lua in the gamemode. Works for ZS, needs adjustments for other gamemodes.
|
||||||
local colTemp = Color(255, 255, 255)
|
local colTemp = Color(255, 255, 255)
|
||||||
function d3stats.DrawTargetID( ent, fade, x, y )
|
function d3stats.DrawTargetID( ent, fade, x, y )
|
||||||
|
|
||||||
colTemp.a = fade * 255
|
colTemp.a = fade * 255
|
||||||
--util.ColorCopy(COLOR_FRIENDLY, colTemp)
|
--util.ColorCopy(COLOR_FRIENDLY, colTemp)
|
||||||
|
|
||||||
if ent.D3Stats_Level and d3stats.Levels[ent.D3Stats_Level] then
|
local Level = ent:GetNWInt( "D3Stats_Level", 0 )
|
||||||
draw.SimpleTextBlur("Level " .. tostring(ent.D3Stats_Level) .. " \"" .. d3stats.Levels[ent.D3Stats_Level].Name .. "\"", "ZSHUDFontTiny", x, y, colTemp, TEXT_ALIGN_CENTER)
|
if Level > 0 and d3stats.Levels[Level] then
|
||||||
y = y + draw.GetFontHeight("ZSHUDFontTiny") + 4
|
draw.SimpleTextBlur("Level " .. tostring(Level) .. " \"" .. d3stats.Levels[Level].Name .. "\"", d3stats.Font_TargetID, x, y, colTemp, TEXT_ALIGN_CENTER)
|
||||||
|
y = y + draw.GetFontHeight(d3stats.Font_TargetID) + 4
|
||||||
end
|
end
|
||||||
|
|
||||||
return x, y
|
return x, y
|
||||||
|
@ -14,3 +14,4 @@ include( "vgui/overlay.lua" )
|
|||||||
hook.Add( "Initialize", "D3Stats_Init", function ()
|
hook.Add( "Initialize", "D3Stats_Init", function ()
|
||||||
d3stats.Overlay_Init()
|
d3stats.Overlay_Init()
|
||||||
end )
|
end )
|
||||||
|
|
||||||
|
@ -6,24 +6,4 @@ net.Receive( "D3Stats_UpdateXP", function()
|
|||||||
if d3stats and d3stats.D3StatsOverlay then
|
if d3stats and d3stats.D3StatsOverlay then
|
||||||
d3stats.D3StatsOverlay:StatsUpdate( XP, d3stats.CalculateLevel( XP ) )
|
d3stats.D3StatsOverlay:StatsUpdate( XP, d3stats.CalculateLevel( XP ) )
|
||||||
end
|
end
|
||||||
end )
|
|
||||||
|
|
||||||
net.Receive( "D3Stats_UpdateLevels", function()
|
|
||||||
local players = net.ReadUInt( 16 )
|
|
||||||
|
|
||||||
for i = 1, players do
|
|
||||||
local ply = net.ReadEntity()
|
|
||||||
local Level = net.ReadUInt( 16 )
|
|
||||||
ply.D3Stats_Level = Level
|
|
||||||
--print( "Level update: " .. tostring(ply) .." --> " .. tostring(Level))
|
|
||||||
end
|
|
||||||
end )
|
|
||||||
|
|
||||||
net.Receive( "D3Stats_BroadcastLevel", function()
|
|
||||||
local ply = net.ReadEntity()
|
|
||||||
local Level = net.ReadUInt( 16 )
|
|
||||||
|
|
||||||
ply.D3Stats_Level = Level
|
|
||||||
|
|
||||||
--print( "Level broadcast: " .. tostring(ply) .." --> " .. tostring(Level))
|
|
||||||
end )
|
end )
|
26
lua/d3stats/gamemodes/sv_zombiesurvival.lua
Normal file
26
lua/d3stats/gamemodes/sv_zombiesurvival.lua
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
--[[
|
||||||
|
|
||||||
|
Any "zombie survival" gamemode specific code goes in here
|
||||||
|
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- XP rewards for players getting points
|
||||||
|
hook.Add( "PlayerPointsAdded", "D3Stats_ZS_PlayerPointsAdded", function ( ply, points )
|
||||||
|
if points <= d3stats.PlayerPointsAdded_Limit then
|
||||||
|
ply:D3Stats_AddXP( points )
|
||||||
|
end
|
||||||
|
end )
|
||||||
|
|
||||||
|
-- XP rewards for zombies killing humans
|
||||||
|
hook.Add( "PostZombieKilledHuman", "D3Stats_ZS_PostZombieKilledHuman", function ( ply, attacker, dmginfo, headshot, wassuicide )
|
||||||
|
local reward = d3stats.ZombieKilledHuman_Static + d3stats.ZombieKilledHuman_Fraction * ply:Frags()
|
||||||
|
|
||||||
|
reward = math.Clamp( reward, d3stats.ZombieKilledHuman_Min, d3stats.ZombieKilledHuman_Max )
|
||||||
|
|
||||||
|
attacker:D3Stats_AddXP( reward )
|
||||||
|
end )
|
||||||
|
|
||||||
|
-- Message on levelchange
|
||||||
|
hook.Add( "D3Stats_LevelChanged", "D3Stats_ZS_LevelChanged", function ( ply, oldLevel, Level )
|
||||||
|
ply:CenterNotify( Color( 0, 255, 255 ), "You ascended to level " .. tostring( Level ) .. " \"" .. d3stats.Levels[Level].Name .. "\"")
|
||||||
|
end )
|
@ -20,36 +20,16 @@ include( "sh_settings.lua" )
|
|||||||
include( "sh_level.lua" )
|
include( "sh_level.lua" )
|
||||||
include( "sh_concommand.lua" )
|
include( "sh_concommand.lua" )
|
||||||
|
|
||||||
|
include( "gamemodes/sv_zombiesurvival.lua" )
|
||||||
include( "sv_network.lua" )
|
include( "sv_network.lua" )
|
||||||
|
|
||||||
-- XP rewards for players getting points
|
hook.Add( "PlayerInitialSpawn", "D3Stats_PlayerSpawn", function ( ply )
|
||||||
hook.Add( "PlayerPointsAdded", "D3Stats_PlayerPointsAdded", function ( ply, points )
|
|
||||||
if points <= d3stats.PlayerPointsAdded_Limit then
|
|
||||||
ply:D3Stats_AddXP( points )
|
|
||||||
end
|
|
||||||
end )
|
|
||||||
|
|
||||||
-- XP rewards for zombies killing humans
|
|
||||||
hook.Add( "PostZombieKilledHuman", "D3Stats_PostZombieKilledHuman", function ( ply, attacker, dmginfo, headshot, wassuicide )
|
|
||||||
local reward = d3stats.ZombieKilledHuman_Static + d3stats.ZombieKilledHuman_Fraction * ply:GetPoints()
|
|
||||||
|
|
||||||
reward = math.Clamp( reward, d3stats.ZombieKilledHuman_Min, d3stats.ZombieKilledHuman_Max )
|
|
||||||
|
|
||||||
attacker:D3Stats_AddXP( reward )
|
|
||||||
end )
|
|
||||||
|
|
||||||
hook.Add( "PlayerReady", "D3Stats_PlayerReady", function ( ply ) -- TODO: Find a better method than using the PlayerReady hook
|
|
||||||
-- Send all the levels of the other players to ply
|
|
||||||
ply:D3Stats_Net_UpdateLevels()
|
|
||||||
end )
|
|
||||||
|
|
||||||
hook.Add( "PlayerSpawn", "D3Stats_PlayerSpawn", function ( ply )
|
|
||||||
-- Send its own XP
|
-- Send its own XP
|
||||||
ply:D3Stats_Net_UpdateXP()
|
ply:D3Stats_Net_UpdateXP()
|
||||||
|
|
||||||
-- Broadcast the own level to others
|
-- Store level as network and local player variable
|
||||||
ply.D3Stats_Level = ply:D3Stats_GetLevel()
|
ply.D3Stats_Level = d3stats.CalculateLevel( ply:D3Stats_GetXP() )
|
||||||
ply:D3Stats_Net_BroadcastLevel( ply.D3Stats_Level )
|
ply:SetNWInt( "D3Stats_Level", ply.D3Stats_Level )
|
||||||
end )
|
end )
|
||||||
|
|
||||||
local meta = FindMetaTable( "Player" )
|
local meta = FindMetaTable( "Player" )
|
||||||
@ -74,12 +54,11 @@ function meta:D3Stats_SetXP( XP )
|
|||||||
|
|
||||||
self:D3Stats_Net_UpdateXP()
|
self:D3Stats_Net_UpdateXP()
|
||||||
|
|
||||||
-- Broadcast on level change
|
-- Update network variable and send message on level change
|
||||||
local Level = self:D3Stats_GetLevel()
|
local Level = d3stats.CalculateLevel( XP )
|
||||||
if self.D3Stats_Level and self.D3Stats_Level ~= Level then
|
if self.D3Stats_Level and self.D3Stats_Level ~= Level then
|
||||||
self.D3Stats_Level = Level
|
self:SetNWInt( "D3Stats_Level", Level )
|
||||||
self:D3Stats_Net_BroadcastLevel( Level )
|
hook.Call( "D3Stats_LevelChanged" , nil, self, self.D3Stats_Level, Level )
|
||||||
self:CenterNotify( Color( 0, 255, 255 ), "You ascended to level " .. tostring( Level ) .. " \"" .. d3stats.Levels[Level].Name .. "\"")
|
|
||||||
end
|
end
|
||||||
self.D3Stats_Level = Level
|
self.D3Stats_Level = Level
|
||||||
end
|
end
|
||||||
@ -93,14 +72,14 @@ function meta:D3Stats_AddXP( XP )
|
|||||||
end
|
end
|
||||||
|
|
||||||
function meta:D3Stats_GetLevel()
|
function meta:D3Stats_GetLevel()
|
||||||
return d3stats.CalculateLevel( self:D3Stats_GetXP() )
|
return self.D3Stats_Level
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if the players level has the permission
|
-- Check if the players level has the permission
|
||||||
function meta:D3Stats_HasPermission( Permission )
|
function meta:D3Stats_HasPermission( Permission )
|
||||||
|
|
||||||
-- If no one else has this permission, allow it
|
-- If there are too few players with this permission, allow it
|
||||||
if d3stats.Permissions[Permission] and d3stats.Permissions[Permission].AllowIfLessThan and d3stats.Permissions[Permission].AllowIfLessThan > d3stats.CountPermissionPlayers( Permission ) then
|
if d3stats.Permissions[Permission] and d3stats.Permissions[Permission].AllowIfLessThan and d3stats.Permissions[Permission].AllowIfLessThan > d3stats.CountPermissionPlayers( Permission, d3stats.Permissions[Permission].Team ) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -32,13 +32,15 @@ end
|
|||||||
|
|
||||||
-- Count the amount of online players who have the permission
|
-- Count the amount of online players who have the permission
|
||||||
if SERVER then
|
if SERVER then
|
||||||
function d3stats.CountPermissionPlayers( Permission )
|
function d3stats.CountPermissionPlayers( Permission, Team )
|
||||||
local Counter = 0
|
local Counter = 0
|
||||||
|
|
||||||
local players = player.GetAll()
|
local players = player.GetAll()
|
||||||
for key, ply in pairs( players ) do
|
for key, ply in pairs( players ) do
|
||||||
if d3stats.LevelCheckPermission( ply:D3Stats_GetLevel(), Permission ) == true then
|
if Team == nil or pl:Team() == Team then
|
||||||
Counter = Counter + 1
|
if d3stats.LevelCheckPermission( ply:D3Stats_GetLevel(), Permission ) == true then
|
||||||
|
Counter = Counter + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,9 +6,10 @@ Settings and level definitions are stored in here
|
|||||||
|
|
||||||
-- Permissions
|
-- Permissions
|
||||||
-- AllowIfLessThan: If the amount of players who have the permission is lower than this number, allow it anyways
|
-- AllowIfLessThan: If the amount of players who have the permission is lower than this number, allow it anyways
|
||||||
|
-- Team: Reduces count to the specified team. In ZS: TEAM_SURVIVOR = 4
|
||||||
d3stats.Permissions = {
|
d3stats.Permissions = {
|
||||||
["Buy_Hammer"] = { AllowIfLessThan = 2 },
|
["Buy_Hammer"] = { AllowIfLessThan = 2, Team = 4 },
|
||||||
["Use_Hammer"] = { AllowIfLessThan = 2 },
|
["Use_Hammer"] = { AllowIfLessThan = 2, Team = 4 },
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Levels, please sort by XP
|
-- Levels, please sort by XP
|
||||||
@ -53,4 +54,28 @@ d3stats.PlayerPointsAdded_Limit = 200 -- Ignore all "PlayerPointsAdded" callbac
|
|||||||
d3stats.ZombieKilledHuman_Fraction = 1.0 -- Amount of XP a zombie gets of the killed humans points
|
d3stats.ZombieKilledHuman_Fraction = 1.0 -- Amount of XP a zombie gets of the killed humans points
|
||||||
d3stats.ZombieKilledHuman_Static = 100 -- Amount of XP a zombie gets for killing a human
|
d3stats.ZombieKilledHuman_Static = 100 -- Amount of XP a zombie gets for killing a human
|
||||||
d3stats.ZombieKilledHuman_Max = 1000 -- Upper XP reward clamp
|
d3stats.ZombieKilledHuman_Max = 1000 -- Upper XP reward clamp
|
||||||
d3stats.ZombieKilledHuman_Min = 0 -- Lower XP reward clamp
|
d3stats.ZombieKilledHuman_Min = 0 -- Lower XP reward clamp
|
||||||
|
|
||||||
|
-- Fonts
|
||||||
|
if CLIENT then
|
||||||
|
surface.CreateFont( "D3Stats_OverlayFont", {
|
||||||
|
font = "Typenoksidi",
|
||||||
|
extended = true,
|
||||||
|
size = 16,
|
||||||
|
weight = 0,
|
||||||
|
blursize = 0,
|
||||||
|
scanlines = 0,
|
||||||
|
antialias = true,
|
||||||
|
underline = false,
|
||||||
|
italic = false,
|
||||||
|
strikeout = false,
|
||||||
|
symbol = false,
|
||||||
|
rotary = false,
|
||||||
|
shadow = false,
|
||||||
|
additive = false,
|
||||||
|
outline = true,
|
||||||
|
} )
|
||||||
|
|
||||||
|
d3stats.Font_Overlay = "D3Stats_OverlayFont"
|
||||||
|
d3stats.Font_TargetID = "D3Stats_OverlayFont"
|
||||||
|
end
|
@ -1,6 +1,4 @@
|
|||||||
util.AddNetworkString( "D3Stats_UpdateXP" )
|
util.AddNetworkString( "D3Stats_UpdateXP" )
|
||||||
util.AddNetworkString( "D3Stats_UpdateLevels" )
|
|
||||||
util.AddNetworkString( "D3Stats_BroadcastLevel" )
|
|
||||||
|
|
||||||
local meta = FindMetaTable( "Player" )
|
local meta = FindMetaTable( "Player" )
|
||||||
if not meta then return end
|
if not meta then return end
|
||||||
@ -11,25 +9,3 @@ function meta:D3Stats_Net_UpdateXP()
|
|||||||
net.WriteUInt( self:D3Stats_GetXP(), 32 )
|
net.WriteUInt( self:D3Stats_GetXP(), 32 )
|
||||||
net.Send( self )
|
net.Send( self )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Send all player levels to this (self) player
|
|
||||||
function meta:D3Stats_Net_UpdateLevels()
|
|
||||||
net.Start( "D3Stats_UpdateLevels" )
|
|
||||||
|
|
||||||
local players = player.GetAll()
|
|
||||||
|
|
||||||
net.WriteUInt( table.getn( players ), 16 )
|
|
||||||
for k, ply in pairs( players ) do
|
|
||||||
net.WriteEntity( ply )
|
|
||||||
net.WriteUInt( ply:D3Stats_GetLevel(), 16 )
|
|
||||||
end
|
|
||||||
net.Send( self )
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Send the current level of this (self) player to everyone
|
|
||||||
function meta:D3Stats_Net_BroadcastLevel( Level )
|
|
||||||
net.Start( "D3Stats_BroadcastLevel" )
|
|
||||||
net.WriteEntity( self )
|
|
||||||
net.WriteUInt( Level, 16 )
|
|
||||||
net.Broadcast()
|
|
||||||
end
|
|
@ -7,7 +7,7 @@ function PANEL:Init()
|
|||||||
self.Progress:SetSize( 200, 10 )
|
self.Progress:SetSize( 200, 10 )
|
||||||
|
|
||||||
self.Label = vgui.Create( "DLabel", self )
|
self.Label = vgui.Create( "DLabel", self )
|
||||||
self.Label:SetFont("ZSHUDFontTiny")
|
self.Label:SetFont(d3stats.Font_Overlay)
|
||||||
self.Label:SetPos( 10, 25 ) -- Set the position of the label
|
self.Label:SetPos( 10, 25 ) -- Set the position of the label
|
||||||
self:StatsUpdate( 0, 1 )
|
self:StatsUpdate( 0, 1 )
|
||||||
--self.Label:SetDark( 1 ) -- Set the colour of the text inside the label to a darker one
|
--self.Label:SetDark( 1 ) -- Set the colour of the text inside the label to a darker one
|
||||||
|
Loading…
Reference in New Issue
Block a user