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

Add locational voice chat range cut-off setting #1503

Merged
merged 1 commit into from
Apr 7, 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 @@ -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

Expand Down
29 changes: 26 additions & 3 deletions gamemodes/terrortown/gamemode/server/sv_voice.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
Expand Down Expand Up @@ -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

---
Expand Down
1 change: 1 addition & 0 deletions lua/terrortown/lang/de.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions lua/terrortown/lang/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.]]
14 changes: 14 additions & 0 deletions lua/terrortown/menus/gamemode/administration/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Loading