Skip to content

Commit

Permalink
Merge pull request #62 from B3none/voice-announcements
Browse files Browse the repository at this point in the history
Added toggle for voice announcements
  • Loading branch information
B3none authored Jan 28, 2024
2 parents 468f2e9 + a2accec commit c6e97a5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ When the plugin is first loaded it will create a `retakes_config.json` file in t
| !removespawn | | Removes the nearest spawn point for the bombsite currently shown. | @css/root |
| !nearestspawn | | Teleports the player to the nearest spawn. | @css/root |
| !scramble | | Scrambles the teams next round. | @css/admin |
| !voices | | Toggles whether or not to hear the bombsite voice announcements. | |
| css_debugqueues | | **SERVER ONLY** Shows the current queue state in the server console. | |

## Stay up to date
Expand Down
44 changes: 41 additions & 3 deletions RetakesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace RetakesPlugin;
[MinimumApiVersion(154)]
public class RetakesPlugin : BasePlugin
{
private const string Version = "1.3.21";
private const string Version = "1.3.22";

#region Plugin info
public override string ModuleName => "Retakes Plugin";
Expand All @@ -28,6 +28,8 @@ public class RetakesPlugin : BasePlugin

#region Constants
public static readonly string LogPrefix = $"[Retakes {Version}] ";

// These two static variables are overwritten in the Load / OnMapStart with config values.
public static string MessagePrefix = $"[{ChatColors.Green}Retakes{ChatColors.White}] ";
public static bool IsDebugMode = false;
#endregion
Expand All @@ -50,6 +52,9 @@ public class RetakesPlugin : BasePlugin
private CsTeam _lastRoundWinner = CsTeam.None;
private Bombsite? _showingSpawnsForBombsite;

// TODO: We should really store this in SQLite, but for now we'll just store it in memory.
private readonly HashSet<CCSPlayerController> _hasMutedVoices = new();

private void ResetState()
{
_currentBombsite = Bombsite.A;
Expand Down Expand Up @@ -84,7 +89,6 @@ public override void Load(bool hotReload)
}

#region Commands

[ConsoleCommand("css_showspawns", "Show the spawns for the specified bombsite.")]
[ConsoleCommand("css_spawns", "Show the spawns for the specified bombsite.")]
[ConsoleCommand("css_edit", "Show the spawns for the specified bombsite.")]
Expand Down Expand Up @@ -389,6 +393,36 @@ public void OnCommandDebugState(CCSPlayerController? player, CommandInfo command

_gameManager.QueueManager.DebugQueues(true);
}

[ConsoleCommand("css_voices", "Toggles whether or not you want to hear bombsite voice announcements.")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
public void OnCommandVoices(CCSPlayerController? player, CommandInfo commandInfo)
{
if (!Helpers.IsValidPlayer(player))
{
commandInfo.ReplyToCommand($"{MessagePrefix}You must be a valid player to use this command.");
return;
}

if (RetakesConfig.IsLoaded(_retakesConfig) && !_retakesConfig!.RetakesConfigData!.EnableBombsiteAnnouncementVoices)
{
commandInfo.ReplyToCommand($"{MessagePrefix}Bombsite voice announcements are permanently disabled on this server.");
return;
}

var didMute = false;
if (!_hasMutedVoices.Contains(player!))
{
didMute = true;
_hasMutedVoices.Add(player!);
}
else
{
_hasMutedVoices.Remove(player!);
}

commandInfo.ReplyToCommand($"{MessagePrefix}{_translator["retakes.voices.toggle", didMute ? $"{ChatColors.Red}disabled{ChatColors.White}" : $"{ChatColors.Green}enabled{ChatColors.White}"]}");
}
#endregion

#region Listeners
Expand Down Expand Up @@ -831,6 +865,7 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo
}

_gameManager.QueueManager.RemovePlayerFromQueues(player);
_hasMutedVoices.Remove(player);

return HookResult.Continue;
}
Expand Down Expand Up @@ -868,7 +903,10 @@ private void AnnounceBombsite(Bombsite bombsite, bool onlyCenter = false)
// Don't use Server.PrintToChat as it'll add another loop through the players.
player.PrintToChat($"{MessagePrefix}{announcementMessage}");

if (!isRetakesConfigLoaded || _retakesConfig!.RetakesConfigData!.EnableBombsiteAnnouncementVoices)
if (
(!isRetakesConfigLoaded || _retakesConfig!.RetakesConfigData!.EnableBombsiteAnnouncementVoices)
&& !_hasMutedVoices.Contains(player)
)
{
// Do this here so every player hears a random announcer each round.
var bombsiteAnnouncer = bombsiteAnnouncers[Helpers.Random.Next(bombsiteAnnouncers.Length)];
Expand Down
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"retakes.queue.vip_took_place": "You have taken [GREEN]{0}[NORMAL]'s place in the game.",

"retakes.bombsite.announcement": "Retake [GREEN]{0}[NORMAL]: [LIGHT_RED]{1} Ts[NORMAL] vs [PURPLE]{2} CTs",
"retakes.voices.toggle": "You have {0} voice announcements!",

"retakes.teams.scramble": "The terrorists won [GREEN]{0}[NORMAL] rounds in a row. [PURPLE]Teams are being scrambled!",
"retakes.teams.almost_scramble": "The terrorists have won [GREEN]{0}[NORMAL] rounds in a row - if they win [GREEN]{1} more, [PURPLE]teams will be scrambled.",
Expand Down

0 comments on commit c6e97a5

Please sign in to comment.