diff --git a/gamemodes/terrortown/entities/entities/ttt_traitor_button/shared.lua b/gamemodes/terrortown/entities/entities/ttt_traitor_button/shared.lua index 0ddcdba44..d509bf30c 100644 --- a/gamemodes/terrortown/entities/entities/ttt_traitor_button/shared.lua +++ b/gamemodes/terrortown/entities/entities/ttt_traitor_button/shared.lua @@ -1,6 +1,16 @@ --- Special button usable from range if your role has access to it -CreateConVar("ttt2_tbutton_admin_show", "0", SERVER and {FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED} or {FCVAR_REPLICATED}, "Always show the buttons to admins in range", 0, 1) +local cv_tbutton = CreateConVar("ttt2_tbutton_admin_show", "0", {FCVAR_ARCHIVE, FCVAR_NOTIFY}, "Always show the buttons to admins in range", 0, 1) + +if SERVER then + hook.Add("TTT2SyncGlobals", "AddTButtonGlobals", function() + SetGlobalBool(cv_tbutton:GetName(), cv_tbutton:GetBool()) + end) + + cvars.AddChangeCallback(cv_tbutton:GetName(), function(cv, old, new) + SetGlobalBool(cv_tbutton:GetName(), tobool(tonumber(new))) + end) +end if CLIENT then net.Receive("TTT2SendTButtonConfig", function(len, ply) diff --git a/gamemodes/terrortown/gamemode/client/cl_targetid.lua b/gamemodes/terrortown/gamemode/client/cl_targetid.lua index 7227054b1..342881897 100644 --- a/gamemodes/terrortown/gamemode/client/cl_targetid.lua +++ b/gamemodes/terrortown/gamemode/client/cl_targetid.lua @@ -497,7 +497,7 @@ function HUDDrawTargetIDTButtons(tData) local client = LocalPlayer() local ent = tData:GetEntity() - local admin_mode = GetConVar("ttt2_tbutton_admin_show") + local admin_mode = GetGloablBool("ttt2_tbutton_admin_show", false) if not IsValid(client) or not client:IsTerror() or not client:Alive() or not IsValid(ent) or ent:GetClass() ~= "ttt_traitor_button" or tData:GetEntityDistance() > ent:GetUsableRange() then @@ -543,7 +543,7 @@ function HUDDrawTargetIDTButtons(tData) end -- only add more information if in admin mode - if not admin_mode:GetBool() or not client:IsAdmin() then return end + if not admin_mode or not client:IsAdmin() then return end local but = TBHUD.focus_but @@ -597,7 +597,7 @@ function HUDDrawTargetIDTButtons(tData) tData:AddDescriptionLine() -- adding empty line tData:AddDescriptionLine( - ParT("tbut_admin_mode_only", {cv = admin_mode:GetName()}), + ParT("tbut_admin_mode_only", {cv = "ttt2_tbutton_admin_show"}), COLOR_ORANGE ) end diff --git a/gamemodes/terrortown/gamemode/client/cl_tbuttons.lua b/gamemodes/terrortown/gamemode/client/cl_tbuttons.lua index 575195424..43dbd94bc 100644 --- a/gamemodes/terrortown/gamemode/client/cl_tbuttons.lua +++ b/gamemodes/terrortown/gamemode/client/cl_tbuttons.lua @@ -95,7 +95,7 @@ end -- @return boolean whether the request was sent to server -- @realm client function TBHUD:ToggleFocused(teamMode) - local buttonChecks = self.focus_but and IsValid(self.focus_but.ent) and self.focus_but.admin and self.focus_stick >= CurTime() and GetConVar("ttt2_tbutton_admin_show"):GetBool() + local buttonChecks = self.focus_but and IsValid(self.focus_but.ent) and self.focus_but.admin and self.focus_stick >= CurTime() and GetGlobalBool("ttt2_tbutton_admin_show", false) if buttonChecks then net.Start("TTT2ToggleTButton") @@ -146,7 +146,7 @@ function TBHUD:Draw(client) local pos, scrpos, d local focus_but local focus_d, focus_scrpos_x, focus_scrpos_y = 0, midscreen_x, midscreen_y - local showToAdmins = GetConVar("ttt2_tbutton_admin_show"):GetBool() + local showToAdmins = GetGlobalBool("ttt2_tbutton_admin_show", false) -- draw icon on HUD for every button within range for _, val in pairs(self.buttons) do