From bfb6923c043743d4fbfd67831fa5278471c5c222 Mon Sep 17 00:00:00 2001 From: Wryyyong <28753317+Wryyyong@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:40:48 +0800 Subject: [PATCH 1/7] Add global and changecallback for ttt_identify_body_woconfirm so the client can use it --- gamemodes/terrortown/gamemode/server/sv_main.lua | 7 ++++++- lua/ttt2/libraries/targetid.lua | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gamemodes/terrortown/gamemode/server/sv_main.lua b/gamemodes/terrortown/gamemode/server/sv_main.lua index 6c5a7fec0..0f4e02094 100644 --- a/gamemodes/terrortown/gamemode/server/sv_main.lua +++ b/gamemodes/terrortown/gamemode/server/sv_main.lua @@ -132,7 +132,7 @@ local map_switch_delay = CreateConVar( --- -- @realm server -CreateConVar( +local identify_body_woconfirm = CreateConVar( "ttt_identify_body_woconfirm", "1", { FCVAR_NOTIFY, FCVAR_ARCHIVE }, @@ -506,6 +506,7 @@ function GM:SyncGlobals() end SetGlobalBool("ttt2_confirm_team", confirm_team:GetBool()) + SetGlobalBool(identify_body_woconfirm:GetName(), identify_body_woconfirm:GetBool()) --- -- @realm server @@ -520,6 +521,10 @@ cvars.AddChangeCallback(idle_enabled:GetName(), function(cv, old, new) SetGlobalBool(idle_enabled:GetName(), tobool(tonumber(new))) end) +cvars.AddChangeCallback(identify_body_woconfirm:GetName(), function(cv, old, new) + SetGlobalBool(identify_body_woconfirm:GetName(), tobool(tonumber(new))) +end) + --- -- This @{function} is used to load the shop equipments -- @realm server diff --git a/lua/ttt2/libraries/targetid.lua b/lua/ttt2/libraries/targetid.lua index 6179c2fc3..1135e4bd7 100644 --- a/lua/ttt2/libraries/targetid.lua +++ b/lua/ttt2/libraries/targetid.lua @@ -562,7 +562,7 @@ function targetid.HUDDrawTargetIDRagdolls(tData) tData:AddDescriptionLine(TryT("corpse_hint_inspect_limited_details")) elseif bodysearch.GetInspectConfirmMode() == 0 - and not GetConVar("ttt_identify_body_woconfirm"):GetBool() + and not GetGlobalBool("ttt_identify_body_woconfirm", true) then tData:SetSubtitle(ParT("corpse_hint_without_confirm", key_params)) else From b922f5d9034f0bd051ae4353c7a82d2a1d929952 Mon Sep 17 00:00:00 2001 From: Wryyyong <28753317+Wryyyong@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:42:53 +0800 Subject: [PATCH 2/7] Add changecallback for ttt2_confirm_team as well, and grab its name via the ConVar object for consistency with the other globals in the hook --- gamemodes/terrortown/gamemode/server/sv_main.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gamemodes/terrortown/gamemode/server/sv_main.lua b/gamemodes/terrortown/gamemode/server/sv_main.lua index 0f4e02094..6fcf9b8a7 100644 --- a/gamemodes/terrortown/gamemode/server/sv_main.lua +++ b/gamemodes/terrortown/gamemode/server/sv_main.lua @@ -505,8 +505,8 @@ function GM:SyncGlobals() ) end - SetGlobalBool("ttt2_confirm_team", confirm_team:GetBool()) SetGlobalBool(identify_body_woconfirm:GetName(), identify_body_woconfirm:GetBool()) + SetGlobalBool(confirm_team:GetName(), confirm_team:GetBool()) --- -- @realm server @@ -525,6 +525,10 @@ cvars.AddChangeCallback(identify_body_woconfirm:GetName(), function(cv, old, new SetGlobalBool(identify_body_woconfirm:GetName(), tobool(tonumber(new))) end) +cvars.AddChangeCallback(confirm_team:GetName(), function(cv, old, new) + SetGlobalBool(confirm_team:GetName(), tobool(tonumber(new))) +end) + --- -- This @{function} is used to load the shop equipments -- @realm server From de1339f8db7d67b9476b7a0429907f4cecd5673b Mon Sep 17 00:00:00 2001 From: Wryyyong <28753317+Wryyyong@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:51:04 +0800 Subject: [PATCH 3/7] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80fadad21..38a196f77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Fixed console error when dropping ammo for weapons with no AmmoEnt (by @MrXonte) - Fixed client error for a not fully initialized client (by @Histalek) - Fixed the targetID corpse hint not respecting `ttt_identify_body_woconfirm` (by @Histalek) +- Fixed networked values for `ttt_identify_body_woconfirm` and `ttt2_confirm_team` not being updated properly when changed (by @Wryyyong) - Fixed the beacon not being properly translated when placed (by @Histalek) ### Changed From 43aed4c082205025059e0d7f1f8a2b464a2ec3fd Mon Sep 17 00:00:00 2001 From: Wryyyong <28753317+Wryyyong@users.noreply.github.com> Date: Fri, 6 Dec 2024 18:55:29 +0800 Subject: [PATCH 4/7] Unironically I feel like just sticking with GlobalVars would be less of a hassle than this --- .../terrortown/gamemode/server/sv_corpse.lua | 33 ++++++++++--------- .../terrortown/gamemode/server/sv_main.lua | 14 -------- .../terrortown/gamemode/shared/sh_corpse.lua | 11 +++++++ lua/autorun/gs_crazyphysics.lua | 2 +- lua/ttt2/libraries/targetid.lua | 11 ++++++- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/gamemodes/terrortown/gamemode/server/sv_corpse.lua b/gamemodes/terrortown/gamemode/server/sv_corpse.lua index a22405e82..a5697fc55 100644 --- a/gamemodes/terrortown/gamemode/server/sv_corpse.lua +++ b/gamemodes/terrortown/gamemode/server/sv_corpse.lua @@ -30,19 +30,6 @@ local IsValid = IsValid local ConVarExists = ConVarExists local hook = hook ---- --- @realm server -local cvBodyfound = CreateConVar( - "ttt_announce_body_found", - "1", - { FCVAR_NOTIFY, FCVAR_ARCHIVE }, - "If detective mode, announce when someone's body is found" -) - ---- --- @realm server -local cvRagCollide = CreateConVar("ttt_ragdoll_collide", "0", { FCVAR_NOTIFY, FCVAR_ARCHIVE }) - local soundsSearch = { Sound("player/footsteps/snow1.wav"), Sound("player/footsteps/snow2.wav"), @@ -60,8 +47,22 @@ ttt_include("sh_corpse") util.AddNetworkString("TTT2SendConfirmMsg") +--- +-- @realm server +CORPSE.cv.announce_body_found = CreateConVar( + "ttt_announce_body_found", + "1", + { FCVAR_NOTIFY, FCVAR_ARCHIVE }, + "If detective mode, announce when someone's body is found" +) + +--- +-- @realm server +CORPSE.cv.ragdoll_collide = CreateConVar("ttt_ragdoll_collide", "0", { FCVAR_NOTIFY, FCVAR_ARCHIVE }) + -- networked data abstraction layer local dti = CORPSE.dti +local config = CORPSE.cv --- -- Sets a CORPSE found state @@ -160,7 +161,7 @@ function CORPSE.IdentifyBody(ply, rag, searchUID) end -- Announce body - if cvBodyfound:GetBool() and notConfirmed then + if config.announce_body_found:GetBool() and notConfirmed then local subrole = rag.was_role local team = rag.was_team local rd = roles.GetByIndex(subrole) @@ -278,7 +279,7 @@ function CORPSE.ShowSearch(ply, rag, isCovert, isLongRange) end if - GetConVar("ttt_identify_body_woconfirm"):GetBool() + config.identify_body_woconfirm:GetBool() and gameloop.IsDetectiveMode() and not isCovert then @@ -640,7 +641,7 @@ function CORPSE.GetPlayerTeam(rag) end hook.Add("ShouldCollide", "TTT2RagdollCollide", function(ent1, ent2) - if cvRagCollide:GetBool() then + if config.ragdoll_collide:GetBool() then return end diff --git a/gamemodes/terrortown/gamemode/server/sv_main.lua b/gamemodes/terrortown/gamemode/server/sv_main.lua index 6fcf9b8a7..1c01851c1 100644 --- a/gamemodes/terrortown/gamemode/server/sv_main.lua +++ b/gamemodes/terrortown/gamemode/server/sv_main.lua @@ -130,15 +130,6 @@ local map_switch_delay = CreateConVar( 0 ) ---- --- @realm server -local identify_body_woconfirm = CreateConVar( - "ttt_identify_body_woconfirm", - "1", - { FCVAR_NOTIFY, FCVAR_ARCHIVE }, - "Toggles whether ragdolls should be confirmed in gameloop.IsDetectiveMode() without clicking on confirm espacially" -) - --- -- @realm server local confirm_team = CreateConVar( @@ -505,7 +496,6 @@ function GM:SyncGlobals() ) end - SetGlobalBool(identify_body_woconfirm:GetName(), identify_body_woconfirm:GetBool()) SetGlobalBool(confirm_team:GetName(), confirm_team:GetBool()) --- @@ -521,10 +511,6 @@ cvars.AddChangeCallback(idle_enabled:GetName(), function(cv, old, new) SetGlobalBool(idle_enabled:GetName(), tobool(tonumber(new))) end) -cvars.AddChangeCallback(identify_body_woconfirm:GetName(), function(cv, old, new) - SetGlobalBool(identify_body_woconfirm:GetName(), tobool(tonumber(new))) -end) - cvars.AddChangeCallback(confirm_team:GetName(), function(cv, old, new) SetGlobalBool(confirm_team:GetName(), tobool(tonumber(new))) end) diff --git a/gamemodes/terrortown/gamemode/shared/sh_corpse.lua b/gamemodes/terrortown/gamemode/shared/sh_corpse.lua index cab183b28..8604e6857 100644 --- a/gamemodes/terrortown/gamemode/shared/sh_corpse.lua +++ b/gamemodes/terrortown/gamemode/shared/sh_corpse.lua @@ -13,6 +13,17 @@ CORPSE.dti = { INT_CREDITS = 0, } +CORPSE.cv = { + --- + -- @realm shared + identify_body_woconfirm = CreateConVar( + "ttt_identify_body_woconfirm", + "1", + { FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_REPLICATED }, + "Toggles whether ragdolls should be confirmed in gameloop.IsDetectiveMode() without clicking on confirm espacially" + ), +} + local dti = CORPSE.dti --- diff --git a/lua/autorun/gs_crazyphysics.lua b/lua/autorun/gs_crazyphysics.lua index 5cd40f3a2..e33d682fb 100644 --- a/lua/autorun/gs_crazyphysics.lua +++ b/lua/autorun/gs_crazyphysics.lua @@ -176,7 +176,7 @@ hook.Add("Initialize", "TTT2GSCrazyPhysics", function() prop_ragdoll = true, } - cv_ttt_announce_body_found = GetConVar("ttt_announce_body_found") + cv_ttt_announce_body_found = CORPSE.cv.announce_body_found cv_ttt2_confirm_killlist = GetConVar("ttt2_confirm_killlist") end end) diff --git a/lua/ttt2/libraries/targetid.lua b/lua/ttt2/libraries/targetid.lua index 1135e4bd7..07101382b 100644 --- a/lua/ttt2/libraries/targetid.lua +++ b/lua/ttt2/libraries/targetid.lua @@ -37,6 +37,15 @@ local materialDestructible = Material("vgui/ttt/tid/tid_destructible") local materialDNATargetID = Material("vgui/ttt/dnascanner/dna_hud") local materialFire = Material("vgui/ttt/tid/tid_onfire") +local cv_ttt_identify_body_woconfirm + +hook.Add("Initialize", "TTT2TargetID", function() + -- Change check if your terrortown folder is named something different + if engine.ActiveGamemode():lower() == "terrortown" and TTT2 and istable(CORPSE) then + cv_ttt_identify_body_woconfirm = CORPSE.cv.identify_body_woconfirm + end +end) + --- -- This function makes sure local variables, which use other libraries that are not yet initialized, are initialized later. -- It gets called after all libraries are included and `cl_targetid.lua` gets included. @@ -562,7 +571,7 @@ function targetid.HUDDrawTargetIDRagdolls(tData) tData:AddDescriptionLine(TryT("corpse_hint_inspect_limited_details")) elseif bodysearch.GetInspectConfirmMode() == 0 - and not GetGlobalBool("ttt_identify_body_woconfirm", true) + and not cv_ttt_identify_body_woconfirm:GetBool() then tData:SetSubtitle(ParT("corpse_hint_without_confirm", key_params)) else From 7a0d1b2274d411a7c52b80738b790bbe169d16de Mon Sep 17 00:00:00 2001 From: Wryyyong <28753317+Wryyyong@users.noreply.github.com> Date: Fri, 6 Dec 2024 19:25:21 +0800 Subject: [PATCH 5/7] Headache, part 2 --- .../terrortown/gamemode/server/sv_corpse.lua | 22 +++++++++++++++-- .../terrortown/gamemode/server/sv_main.lua | 24 ------------------- lua/autorun/gs_crazyphysics.lua | 12 ++++------ lua/ttt2/libraries/bodysearch.lua | 11 ++++++++- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/gamemodes/terrortown/gamemode/server/sv_corpse.lua b/gamemodes/terrortown/gamemode/server/sv_corpse.lua index a5697fc55..6c1f5b2ba 100644 --- a/gamemodes/terrortown/gamemode/server/sv_corpse.lua +++ b/gamemodes/terrortown/gamemode/server/sv_corpse.lua @@ -56,6 +56,24 @@ CORPSE.cv.announce_body_found = CreateConVar( "If detective mode, announce when someone's body is found" ) +--- +-- @realm server +CORPSE.cv.confirm_team = CreateConVar( + "ttt2_confirm_team", + "0", + { FCVAR_NOTIFY, FCVAR_ARCHIVE }, + "Show team of confirmed player" +) + +--- +-- @realm server +CORPSE.cv.confirm_killlist = CreateConVar( + "ttt2_confirm_killlist", + "1", + { FCVAR_NOTIFY, FCVAR_ARCHIVE }, + "Confirm players in kill list" +) + --- -- @realm server CORPSE.cv.ragdoll_collide = CreateConVar("ttt_ragdoll_collide", "0", { FCVAR_NOTIFY, FCVAR_ARCHIVE }) @@ -167,7 +185,7 @@ function CORPSE.IdentifyBody(ply, rag, searchUID) local rd = roles.GetByIndex(subrole) local roletext = "body_found_" .. rd.abbr local clr = rag.role_color - local bool = GetGlobalBool("ttt2_confirm_team") + local bool = config.confirm_team:GetBool() net.Start("TTT2SendConfirmMsg") @@ -201,7 +219,7 @@ function CORPSE.IdentifyBody(ply, rag, searchUID) net.Broadcast() end - if GetConVar("ttt2_confirm_killlist"):GetBool() then + if config.confirm_killlist:GetBool() then -- Handle kill list local ragKills = rag.kills diff --git a/gamemodes/terrortown/gamemode/server/sv_main.lua b/gamemodes/terrortown/gamemode/server/sv_main.lua index 1c01851c1..708552665 100644 --- a/gamemodes/terrortown/gamemode/server/sv_main.lua +++ b/gamemodes/terrortown/gamemode/server/sv_main.lua @@ -130,24 +130,6 @@ local map_switch_delay = CreateConVar( 0 ) ---- --- @realm server -local confirm_team = CreateConVar( - "ttt2_confirm_team", - "0", - { FCVAR_NOTIFY, FCVAR_ARCHIVE }, - "Show team of confirmed player" -) - ---- --- @realm server -CreateConVar( - "ttt2_confirm_killlist", - "1", - { FCVAR_NOTIFY, FCVAR_ARCHIVE }, - "Confirm players in kill list" -) - --- -- @realm server CreateConVar( @@ -496,8 +478,6 @@ function GM:SyncGlobals() ) end - SetGlobalBool(confirm_team:GetName(), confirm_team:GetBool()) - --- -- @realm server hook.Run("TTT2SyncGlobals") @@ -511,10 +491,6 @@ cvars.AddChangeCallback(idle_enabled:GetName(), function(cv, old, new) SetGlobalBool(idle_enabled:GetName(), tobool(tonumber(new))) end) -cvars.AddChangeCallback(confirm_team:GetName(), function(cv, old, new) - SetGlobalBool(confirm_team:GetName(), tobool(tonumber(new))) -end) - --- -- This @{function} is used to load the shop equipments -- @realm server diff --git a/lua/autorun/gs_crazyphysics.lua b/lua/autorun/gs_crazyphysics.lua index e33d682fb..9c695ce42 100644 --- a/lua/autorun/gs_crazyphysics.lua +++ b/lua/autorun/gs_crazyphysics.lua @@ -164,8 +164,7 @@ local tEntitiesToCheck = { local bTTT local tIdentifyEntities -local cv_ttt_announce_body_found -local cv_ttt2_confirm_killlist +local corpseConfig hook.Add("Initialize", "TTT2GSCrazyPhysics", function() -- Change check if your terrortown folder is named something different @@ -176,8 +175,7 @@ hook.Add("Initialize", "TTT2GSCrazyPhysics", function() prop_ragdoll = true, } - cv_ttt_announce_body_found = CORPSE.cv.announce_body_found - cv_ttt2_confirm_killlist = GetConVar("ttt2_confirm_killlist") + corpseConfig = CORPSE.cv end end) @@ -281,8 +279,8 @@ local function IdentifyCorpse(pCorpse) end end - if cv_ttt_announce_body_found:GetBool() then - if GetGlobalBool("ttt2_confirm_team") then -- TODO adjust the new messages + if corpseConfig.announce_body_found:GetBool() then + if corpseConfig.confirm_team:GetBool() then -- TODO adjust the new messages LANG.Msg("body_found", { finder = "The Server", victim = CORPSE.GetPlayerNick(pCorpse, nil) or pPlayer:GetName(), @@ -298,7 +296,7 @@ local function IdentifyCorpse(pCorpse) end end - if cv_ttt2_confirm_killlist:GetBool() then + if corpseConfig.confirm_killlist:GetBool() then local tKills = pCorpse.kills if tKills then for i = 1, #tKills do diff --git a/lua/ttt2/libraries/bodysearch.lua b/lua/ttt2/libraries/bodysearch.lua index e3fe69922..50e38425a 100644 --- a/lua/ttt2/libraries/bodysearch.lua +++ b/lua/ttt2/libraries/bodysearch.lua @@ -115,6 +115,15 @@ if SERVER then local mathRound = math.Round local mathFloor = math.floor + local cv_ttt2_confirm_killlist + + hook.Add("Initialize", "TTT2BodySearch", function() + -- Change check if your terrortown folder is named something different + if engine.ActiveGamemode():lower() == "terrortown" and TTT2 and istable(CORPSE) then + cv_ttt2_confirm_killlist = CORPSE.cv.confirm_killlist + end + end) + util.AddNetworkString("ttt2_client_reports_corpse") util.AddNetworkString("ttt2_client_confirm_corpse") util.AddNetworkString("ttt2_credits_were_taken") @@ -356,7 +365,7 @@ if SERVER then -- build list of people this player killed, but only if convar is enabled sceneData.killEntityIDList = {} - if GetConVar("ttt2_confirm_killlist"):GetBool() then + if cv_ttt2_confirm_killlist:GetBool() then local ragKills = rag.kills or {} for i = 1, #ragKills do From eacce911e26000fdc4df4a12b3e7b51a88614f43 Mon Sep 17 00:00:00 2001 From: Wryyyong <28753317+Wryyyong@users.noreply.github.com> Date: Fri, 6 Dec 2024 19:30:14 +0800 Subject: [PATCH 6/7] Make stylua happy again --- gamemodes/terrortown/gamemode/server/sv_corpse.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gamemodes/terrortown/gamemode/server/sv_corpse.lua b/gamemodes/terrortown/gamemode/server/sv_corpse.lua index 6c1f5b2ba..03833c1c5 100644 --- a/gamemodes/terrortown/gamemode/server/sv_corpse.lua +++ b/gamemodes/terrortown/gamemode/server/sv_corpse.lua @@ -76,7 +76,8 @@ CORPSE.cv.confirm_killlist = CreateConVar( --- -- @realm server -CORPSE.cv.ragdoll_collide = CreateConVar("ttt_ragdoll_collide", "0", { FCVAR_NOTIFY, FCVAR_ARCHIVE }) +CORPSE.cv.ragdoll_collide = + CreateConVar("ttt_ragdoll_collide", "0", { FCVAR_NOTIFY, FCVAR_ARCHIVE }) -- networked data abstraction layer local dti = CORPSE.dti From 4ec561451aab7ef476d58d9bd6825662390a3b1e Mon Sep 17 00:00:00 2001 From: Wryyyong <28753317+Wryyyong@users.noreply.github.com> Date: Sat, 7 Dec 2024 18:51:11 +0800 Subject: [PATCH 7/7] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38a196f77..725ed1463 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,6 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Fixed console error when dropping ammo for weapons with no AmmoEnt (by @MrXonte) - Fixed client error for a not fully initialized client (by @Histalek) - Fixed the targetID corpse hint not respecting `ttt_identify_body_woconfirm` (by @Histalek) -- Fixed networked values for `ttt_identify_body_woconfirm` and `ttt2_confirm_team` not being updated properly when changed (by @Wryyyong) - Fixed the beacon not being properly translated when placed (by @Histalek) ### Changed @@ -37,6 +36,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Updated old TTT HUD to show name of spectated player (by @somefnfplayerlol) - Changes to the enabled map prefixes will not be announced to players anymore (by @Histalek) - By default only `ttt` and `ttt2` map prefixes are enabled (by @Histalek) +- Updated `ttt_identify_body_woconfirm` to be replicated across the server and client (by @Wryyyong) ## [v0.14.0b](https://github.com/TTT-2/TTT2/tree/v0.14.0b) (2024-09-20)