player stats like fatal

This commit is contained in:
edshot99 2024-12-21 01:37:59 -06:00
parent 95276b7995
commit f1eb5d6921
2 changed files with 136 additions and 0 deletions

View File

@ -0,0 +1,104 @@
local PanelConVar = CreateConVar("cl_stats", 1, {FCVAR_ARCHIVE}, "Show player stats HUD", 0, 1)
local StatsPanel = {}
local X = 0
local Y = 0
function StatsPanel:Init()
local TextColor = Color(255, 255, 255)
local TextFont = "ChatFont"
local SX = 150
local SY = 15
self.Player = LocalPlayer()
self.Frags = vgui.Create("DLabel", self)
self.Frags:SetTextColor(TextColor)
self.Frags:SetFont(TextFont)
self.Frags:SetText("Kills:")
self.Frags:SetPos(X + 5, Y + 20)
self.Frags:SetSize(SX, SY)
self.Deaths = vgui.Create("DLabel", self)
self.Deaths:SetTextColor(TextColor)
self.Deaths:SetFont(TextFont)
self.Deaths:SetText("Deaths:")
self.Deaths:SetPos(X + 5, Y + 50)
self.Deaths:SetSize(SX, SY)
self.Ratio = vgui.Create("DLabel", self)
self.Ratio:SetTextColor(TextColor)
self.Ratio:SetFont(TextFont)
self.Ratio:SetText("K/D:")
self.Ratio:SetPos(X + 5, Y + 80)
self.Ratio:SetSize(SX, SY)
self.Streak = vgui.Create("DLabel", self)
self.Streak:SetTextColor(TextColor)
self.Streak:SetFont(TextFont)
self.Streak:SetText("Killstreak:")
self.Streak:SetPos(X + 5, Y + 110)
self.Streak:SetSize(SX, SY)
end
function StatsPanel:PerformLayout()
self:SetSize(150, 175)
self:SetPos(X, Y)
end
function StatsPanel:Paint(width, height)
surface.SetDrawColor(0, 0, 0, 191.25)
surface.DrawRect(0, 0, width, height)
end
function StatsPanel:Think()
if not IsValid(self.Player) then return end
local frags = self.Player:Frags()
local deaths = self.Player:Deaths()
local ratio = 0
if deaths > 0 then
ratio = frags / deaths
end
self.Frags:SetText("Kills: " .. frags)
self.Deaths:SetText("Deaths: " .. deaths)
self.Ratio:SetText("K/D: " .. ratio)
self.Streak:SetText("Killstreak: " .. self.Player:GetNWInt("playerStreak"))
end
local StatsPanelTbl = vgui.RegisterTable(StatsPanel)
local StatsPanelVgui = nil
hook.Add("InitPostEntity", "edshot_player_stats_panel", function()
if StatsPanelVgui == nil then
StatsPanelVgui = vgui.CreateFromTable(StatsPanelTbl)
end
if not PanelConVar:GetBool() then
StatsPanelVgui:Hide()
end
hook.Remove("InitPostEntity", "edshot_player_stats_panel")
end)
cvars.AddChangeCallback("cl_stats", function(convar, oldValue, newValue)
if newValue == "0" then
StatsPanelVgui:Hide()
elseif newValue == "1" then
StatsPanelVgui:Show()
end
end)
function StatsPanelConfig(CPanel)
CPanel:AddControl("Header", {Description = "Toggle the player statistics HUD."})
CPanel:AddControl("Checkbox", {Label = "Toggle HUD", Command = "cl_stats", min = 0, max = 1, Type = "int"})
end
hook.Add("PopulateToolMenu", "edshot_player_stats_panel_config", function()
spawnmenu.AddToolMenuOption("Options", "Player", "edshot_player_stats_panel_config", "Statistics", "", "", StatsPanelConfig)
end)

View File

@ -0,0 +1,32 @@
local NUKE_KILLSTREAK = 25
local NUKE_SWEP = "m9k_orbital_strike"
hook.Add("PlayerDeath", "edshot_player_stats_killstreak", function(victim, inflictor, attacker)
if IsValid(attacker) and attacker:IsPlayer() then
local deaths = attacker:Deaths()
if not attacker.CDeaths then
attacker.CDeaths = deaths
end
if not attacker.Killstreak then
attacker.Killstreak = 0
end
if deaths > attacker.CDeaths then
attacker.Killstreak = 0
attacker.CDeaths = deaths
else
attacker.Killstreak = attacker.Killstreak + 1
local k1 = attacker.Killstreak / NUKE_KILLSTREAK
local k2 = math.Round(k1)
if (k1 ~= 0) and (k2 == k1) then
attacker:Give(NUKE_SWEP)
end
end
attacker:SetNWInt("playerStreak", attacker.Killstreak)
end
end)