Skip to content

Commit

Permalink
fixing #16
Browse files Browse the repository at this point in the history
  • Loading branch information
TimGoll committed Apr 3, 2020
1 parent 6d2bda6 commit 1e5ff72
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
5 changes: 5 additions & 0 deletions lua/classes/shared/sh_defines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if SERVER then
util.AddNetworkString("TTTCAbortClass")
util.AddNetworkString("TTTCChangeCharge")
util.AddNetworkString("TTTCResetChargingWaiting")
util.AddNetworkString("TTTCUpdateScoreboard")

local ttt2_classes = CreateConVar("ttt2_classes", "1", {FCVAR_NOTIFY, FCVAR_ARCHIVE})
local ttt_classes_limited = CreateConVar("ttt_classes_limited", "1", {FCVAR_NOTIFY, FCVAR_ARCHIVE})
Expand All @@ -46,6 +47,10 @@ if SERVER then

cvars.AddChangeCallback(ttt2_classes:GetName(), function(name, old, new)
SetGlobalBool(name, tobool(new))

net.Start("TTTCUpdateScoreboard")
net.WriteBool(tobool(new))
net.Broadcast()
end, "TTT2ClassesCVSyncingToggled")

cvars.AddChangeCallback(ttt_classes_limited:GetName(), function(name, old, new)
Expand Down
48 changes: 29 additions & 19 deletions lua/classes/shared/sh_hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ if SERVER then
return ""
end
end)
else -- CLIENT
end

if CLIENT then
hook.Add("TTTPrepareRound", "TTTCResetClasses", function()
for _, v in ipairs(player.GetAll()) do
v:SetClass(nil)
Expand All @@ -239,32 +241,31 @@ else -- CLIENT
ply.oldClass = hr
end)

-- TODO remove hook if disabled ttt2_classes cvar
hook.Add("TTTScoreboardColumns", "TTTCScoreboardClass", function(pnl)
if GetGlobalBool("ttt2_classes") then
pnl:AddColumn("Class", function(ply, label)
if ply:HasClass() then
local hd = ply:GetClassData()
if not GetGlobalBool("ttt2_classes") then return end

pnl:AddColumn("Class", function(ply, label)
if ply:HasClass() then
local hd = ply:GetClassData()

label:SetColor(hd.color or COLOR_CLASS)

return CLASS.GetClassTranslation(hd)
elseif ply.oldClass then
local hd = CLASS.GetClassDataByIndex(ply.oldClass)
if hd then
label:SetColor(hd.color or COLOR_CLASS)

return CLASS.GetClassTranslation(hd)
elseif ply.oldClass then
local hd = CLASS.GetClassDataByIndex(ply.oldClass)
if hd then
label:SetColor(hd.color or COLOR_CLASS)

return CLASS.GetClassTranslation(hd)
end
elseif not ply:IsActive() and ply:GetNWBool("body_found") then
return "-" -- died without any class
end
elseif not ply:IsActive() and ply:GetNWBool("body_found") then
return "-" -- died without any class
end

label:SetColor(Color(255, 255, 255))
label:SetColor(Color(255, 255, 255))

return "?"
end, 100)
end
return "?"
end, 100)
end)

local function ThinkCharge()
Expand Down Expand Up @@ -328,6 +329,15 @@ else -- CLIENT
end
end
hook.Add("Think", "TTTCThinkCharge", ThinkCharge)

net.Receive("TTTCUpdateScoreboard", function()
-- set the value to the global bool manually because the update of
-- the global bool might come with a delay
SetGlobalBool("ttt2_classes", net.ReadBool() or false)

GAMEMODE:ScoreboardCreate()
GAMEMODE:ScoreboardHide()
end)
end

-- shared because it is predicted
Expand Down

0 comments on commit 1e5ff72

Please sign in to comment.