From cca6275c559912da2191e04c159e6541cc68f3f6 Mon Sep 17 00:00:00 2001 From: Dogan Date: Wed, 16 Jan 2019 15:02:45 +0100 Subject: [PATCH] SelfMuteRadio: clean up + add to sm_settings --- SelfMute/scripting/SelfMuteRadio.sp | 112 +++++++++++++++++++++------- 1 file changed, 83 insertions(+), 29 deletions(-) diff --git a/SelfMute/scripting/SelfMuteRadio.sp b/SelfMute/scripting/SelfMuteRadio.sp index 35da84a0..3248b407 100644 --- a/SelfMute/scripting/SelfMuteRadio.sp +++ b/SelfMute/scripting/SelfMuteRadio.sp @@ -4,13 +4,14 @@ #include #include #include +#include #define MESSAGE_RADIOTEXT 1 #define MESSAGE_SENDAUDIO 2 bool g_bStopRadioSounds[MAXPLAYERS+1] = { false, ... }; -bool g_bStopRadioSoundsHooked = false; bool g_bStopNadeSounds[MAXPLAYERS+1] = { false, ...}; +bool g_bStopRadioSoundsHooked = false; Handle g_hCookieStopRadio = null; Handle g_hCookieStopNade = null; @@ -36,13 +37,15 @@ public void OnPluginStart() if (SendAudio == INVALID_MESSAGE_ID) SetFailState("This game does not support the \"SendAudio\" UserMessage."); - RegConsoleCmd("sm_smradio", ToggleSelfMuteRadio, "Toggle Radio Self Mute"); - //RegConsoleCmd("sm_radio", ToggleSelfMuteRadio, "Toggle Radio Self Mute"); //GFL only - RegConsoleCmd("sm_smradio_nades", ToggleSelfMuteNade, "Toggle only Radio 'Fire in the hole' Self Mute"); + RegConsoleCmd("sm_smradio", OnToggleSelfMuteRadio, "Toggle Radio Self Mute"); + //RegConsoleCmd("sm_radio", OnToggleSelfMuteRadio, "Toggle Radio Self Mute"); //GFL only + RegConsoleCmd("sm_smradio_nades", OnToggleSelfMuteNade, "Toggle only Radio 'Fire in the hole' Self Mute"); g_hCookieStopRadio = RegClientCookie("radio_blocked", "is the radio blocked", CookieAccess_Protected); g_hCookieStopNade = RegClientCookie("nades_blocked", "is the 'fire in the hole' radio blocked", CookieAccess_Protected); + SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Radio Self Mute"); + HookUserMessage(RadioText, Hook_RadioText, true); HookUserMessage(SendAudio, Hook_SendAudio, true); } @@ -234,41 +237,34 @@ public void OnSendAudio(DataPack pack) EndMessage(); } -public Action ToggleSelfMuteRadio(int client, int args) +public Action OnToggleSelfMuteRadio(int client, int args) +{ + ToggleSelfMuteRadio(client); + return Plugin_Handled; +} + +public Action OnToggleSelfMuteNade(int client, int args) +{ + ToggleSelfMuteNade(client); + return Plugin_Handled; +} + +public Action ToggleSelfMuteRadio(int client) { g_bStopRadioSounds[client] = !g_bStopRadioSounds[client]; CheckHooks(); - if(g_bStopRadioSounds[client]) - { - ReplyToCommand(client, "You blocked all Radio Messages and Sound"); - SetClientCookie(client, g_hCookieStopRadio, "1"); - } - else - { - ReplyToCommand(client, "You unblocked all Radio Messages and Sound"); - SetClientCookie(client, g_hCookieStopRadio, ""); - g_bStopNadeSounds[client] = false; - } - return Plugin_Handled; + SetClientCookie(client, g_hCookieStopRadio, g_bStopRadioSounds[client] ? "1" : ""); + CPrintToChat(client, "{cyan}[SelfMuteRadio] {white}%s", g_bStopRadioSounds[client] ? "You self-muted all Radio Messages and Sounds." : "You self-unmuted all Radio Messages and Sounds."); } -public Action ToggleSelfMuteNade(int client, int args) +public Action ToggleSelfMuteNade(int client) { g_bStopNadeSounds[client] = !g_bStopNadeSounds[client]; CheckHooks(); - if(g_bStopNadeSounds[client]) - { - ReplyToCommand(client, "You blocked 'Fire in the Hole' Radio Messages and Sound"); - SetClientCookie(client, g_hCookieStopNade, "1"); - } - else - { - ReplyToCommand(client, "You unblocked 'Fire in the Hole' Radio Messages and Sound"); - SetClientCookie(client, g_hCookieStopNade, ""); - } - return Plugin_Handled; + SetClientCookie(client, g_hCookieStopNade, g_bStopNadeSounds[client] ? "1" : ""); + CPrintToChat(client, "{cyan}[SelfMuteRadio] {white}%s", g_bStopNadeSounds[client] ? "You self-muted 'Fire in the Hole' Radio Messages and Sounds." : "You self-unmuted 'Fire in the Hole' Radio Messages and Sounds."); } public void OnClientCookiesCached(int client) @@ -322,3 +318,61 @@ public void CheckHooks() g_bStopRadioSoundsHooked = bShouldHook; } + +public void ShowSettingsMenu(int client) +{ + Menu menu = new Menu(MenuHandler_MainMenu); + + menu.SetTitle("SelfMuteRadio Settings", client); + + char sBuffer[128]; + Format(sBuffer, sizeof(sBuffer), "Self-Muting all Radio: %s", g_bStopRadioSounds[client] ? "Enabled" : "Disabled"); + menu.AddItem("0", sBuffer); + + Format(sBuffer, sizeof(sBuffer), "Self-Muting Nades Radio only: %s", g_bStopNadeSounds[client] ? "Enabled" : "Disabled"); + menu.AddItem("1", sBuffer); + + menu.ExitBackButton = true; + + menu.Display(client, MENU_TIME_FOREVER); +} + +public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info, char[] buffer, int maxlen) +{ + switch(action) + { + case(CookieMenuAction_DisplayOption): + { + Format(buffer, maxlen, "SelfMuteRadio", client); + } + case(CookieMenuAction_SelectOption): + { + ShowSettingsMenu(client); + } + } +} + +public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int selection) +{ + switch(action) + { + case(MenuAction_Select): + { + switch(selection) + { + case(0): ToggleSelfMuteRadio(client); + case(1): ToggleSelfMuteNade(client); + } + + ShowSettingsMenu(client); + } + case(MenuAction_Cancel): + { + ShowCookieMenu(client); + } + case(MenuAction_End): + { + delete menu; + } + } +} \ No newline at end of file