Skip to content

Commit

Permalink
moved ttt2_tbutton_admin_show to GlobalBool
Browse files Browse the repository at this point in the history
  • Loading branch information
TimGoll committed Feb 16, 2020
1 parent 7ca323c commit 8a76997
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 3 additions & 3 deletions gamemodes/terrortown/gamemode/client/cl_targetid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gamemodes/terrortown/gamemode/client/cl_tbuttons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8a76997

Please sign in to comment.