Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TargetID: Make ttt_idenfity_body_woconfirm replicated; move and clean up additional ConVars surrounding corpses/ragdolls #1692

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,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)

Expand Down
56 changes: 38 additions & 18 deletions gamemodes/terrortown/gamemode/server/sv_corpse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -60,8 +47,41 @@ 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.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 })

-- networked data abstraction layer
local dti = CORPSE.dti
local config = CORPSE.cv

---
-- Sets a CORPSE found state
Expand Down Expand Up @@ -160,13 +180,13 @@ 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)
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")

Expand Down Expand Up @@ -200,7 +220,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

Expand Down Expand Up @@ -278,7 +298,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
Expand Down Expand Up @@ -640,7 +660,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

Expand Down
29 changes: 0 additions & 29 deletions gamemodes/terrortown/gamemode/server/sv_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,33 +130,6 @@ local map_switch_delay = CreateConVar(
0
)

---
-- @realm server
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(
"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(
Expand Down Expand Up @@ -505,8 +478,6 @@ function GM:SyncGlobals()
)
end

SetGlobalBool("ttt2_confirm_team", confirm_team:GetBool())

---
-- @realm server
hook.Run("TTT2SyncGlobals")
Expand Down
11 changes: 11 additions & 0 deletions gamemodes/terrortown/gamemode/shared/sh_corpse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

---
Expand Down
12 changes: 5 additions & 7 deletions lua/autorun/gs_crazyphysics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -176,8 +175,7 @@ hook.Add("Initialize", "TTT2GSCrazyPhysics", function()
prop_ragdoll = true,
}

cv_ttt_announce_body_found = GetConVar("ttt_announce_body_found")
cv_ttt2_confirm_killlist = GetConVar("ttt2_confirm_killlist")
corpseConfig = CORPSE.cv
end
end)

Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion lua/ttt2/libraries/bodysearch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion lua/ttt2/libraries/targetid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -562,7 +571,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 cv_ttt_identify_body_woconfirm:GetBool()
then
tData:SetSubtitle(ParT("corpse_hint_without_confirm", key_params))
else
Expand Down
Loading