From 9946c501a7e16316b5d1d00608edae385a66eee2 Mon Sep 17 00:00:00 2001 From: ruby0b <106119328+ruby0b@users.noreply.github.com> Date: Sat, 6 Apr 2024 16:19:46 +0200 Subject: [PATCH] Add locational voice chat range cut-off setting --- CHANGELOG.md | 1 + .../terrortown/gamemode/server/sv_voice.lua | 29 +++++++++++++++++-- lua/terrortown/lang/de.lua | 1 + lua/terrortown/lang/en.lua | 6 ++++ .../menus/gamemode/administration/chat.lua | 14 +++++++++ 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3d1c6bc6..03e3c8ffa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Added `TTT2CanTakeCredits` hook for overriding whether a player is allowed to take credits from a given corpse. (by @Spanospy) - Disabled locational voice during the preparing phase by default - Added a ConVar `ttt_locational_voice_prep` to reenable it +- Added `ttt_locational_voice_range` to set a cut-off radius for the locational voice chat range ### Changed diff --git a/gamemodes/terrortown/gamemode/server/sv_voice.lua b/gamemodes/terrortown/gamemode/server/sv_voice.lua index 123d8b110..6a4f7fbd6 100644 --- a/gamemodes/terrortown/gamemode/server/sv_voice.lua +++ b/gamemodes/terrortown/gamemode/server/sv_voice.lua @@ -35,6 +35,13 @@ local loc_voice = CreateConVar("ttt_locational_voice", "0", {FCVAR_NOTIFY, FCVAR -- stylua: ignore local loc_voice_prep = CreateConVar("ttt_locational_voice_prep", "0", {FCVAR_NOTIFY, FCVAR_ARCHIVE}) +--- +-- @realm server +-- stylua: ignore +local loc_voice_range = CreateConVar("ttt_locational_voice_range", "0", { FCVAR_NOTIFY, FCVAR_ARCHIVE }) + +local loc_voice_range_sq = loc_voice_range:GetInt() ^ 2 + hook.Add("TTT2SyncGlobals", "AddVoiceGlobals", function() SetGlobalBool(sv_voiceenable:GetName(), sv_voiceenable:GetBool()) SetGlobalBool(loc_voice:GetName(), loc_voice:GetBool()) @@ -48,6 +55,10 @@ cvars.AddChangeCallback(loc_voice:GetName(), function(cv, old, new) SetGlobalBool(loc_voice:GetName(), tobool(tonumber(new))) end) +cvars.AddChangeCallback(loc_voice_range:GetName(), function(cv, old, new) + loc_voice_range_sq = tonumber(new) ^ 2 +end) + local function LocationalVoiceIsActive(roundState) return loc_voice:GetBool() and roundState ~= ROUND_POST @@ -148,12 +159,24 @@ function GM:PlayerCanHearPlayersVoice(listener, speaker) if speaker:IsSpec() and isGlobalVoice then -- Check that the speaker was not previously sending voice on the team chat - return PlayerCanHearSpectator(listener, speaker, roundState) + can_hear, is_locational = PlayerCanHearSpectator(listener, speaker, roundState) elseif isGlobalVoice then - return PlayerCanHearGlobal(roundState) + can_hear, is_locational = PlayerCanHearGlobal(roundState) else - return PlayerCanHearTeam(listener, speaker, speakerTeam) + can_hear, is_locational = PlayerCanHearTeam(listener, speaker, speakerTeam) + end + + -- If the listener is too far away from the speaker, they can't hear them at all + if + can_hear + and is_locational + and loc_voice_range_sq > 0 + and listener:GetPos():DistToSqr(speaker:GetPos()) > loc_voice_range_sq + then + can_hear = false end + + return can_hear, is_locational end --- diff --git a/lua/terrortown/lang/de.lua b/lua/terrortown/lang/de.lua index f968d855c..18341ecdc 100644 --- a/lua/terrortown/lang/de.lua +++ b/lua/terrortown/lang/de.lua @@ -1669,6 +1669,7 @@ L.label_voice_drain_admin = "Entladung pro Tick für Admins und öffentliche Ord L.label_voice_drain_recharge = "Aufladungsrate pro Tick wenn nicht gesprochen wird" L.label_locational_voice = "Aktiviere Proximity Sprachchat für lebende Spieler" L.label_locational_voice_prep = "Aktiviere Proximity Sprachchat während der Vorbereitungszeit" +L.label_locational_voice_range = "Proximity Sprachchat Reichweite" L.label_armor_on_spawn = "Spielerrüstung beim (Neu-)Spawnen" L.label_prep_respawn = "Aktiviere automatischen Respawn während der Vorbereitungszeit" L.label_preptime_seconds = "Vorbereitungszeit in Sekunden" diff --git a/lua/terrortown/lang/en.lua b/lua/terrortown/lang/en.lua index 4af52a9b1..0f9d343b2 100644 --- a/lua/terrortown/lang/en.lua +++ b/lua/terrortown/lang/en.lua @@ -1669,6 +1669,7 @@ L.label_voice_drain_admin = "Drain per tick for admins and public policing roles L.label_voice_drain_recharge = "Recharge rate per tick of not voice chatting" L.label_locational_voice = "Enable proximity voice chat for living players" L.label_locational_voice_prep = "Enable proximity voice chat during preparing phase" +L.label_locational_voice_range = "Proximity voice chat range" L.label_armor_on_spawn = "Player armor on (re-)spawn" L.label_prep_respawn = "Enable instant respawn during preparing phase" L.label_preptime_seconds = "Preparing time in seconds" @@ -2220,3 +2221,8 @@ L.help_locational_voice_prep = [[By default the proximity chat is disabled in th Note: Proximity chat is always disabled during the post round phase.]] L.help_voice_duck_spectator = "Ducking spectators makes other spectators quieter in comparison to living players. This can be useful if one wants to listen closely to the discussions of the living players." + +-- 2024-04-06 +L.help_locational_voice_range = [[This convar constrains the maximum range at which players can hear each other. It does not change how the volume decreases with distance but rather sets a hard cut-off point. + +Set to 0 to disable this cut-off.]] diff --git a/lua/terrortown/menus/gamemode/administration/chat.lua b/lua/terrortown/menus/gamemode/administration/chat.lua index 460dce5a0..483648d96 100644 --- a/lua/terrortown/menus/gamemode/administration/chat.lua +++ b/lua/terrortown/menus/gamemode/administration/chat.lua @@ -73,6 +73,20 @@ function CLGAMEMODESUBMENU:Populate(parent) master = enbLocVoice, }) + form3:MakeHelp({ + label = "help_locational_voice_range", + master = enbLocVoice, + }) + + form3:MakeSlider({ + serverConvar = "ttt_locational_voice_range", + label = "label_locational_voice_range", + min = 0, + max = 3000, + decimal = 0, + master = enbLocVoice, + }) + local form4 = vgui.CreateTTT2Form(parent, "header_textchat") form4:MakeCheckBox({