If all you want is to block the radio sound for the hegrenade without enabling sv_ignoregrenaderadio for the server, you can do this as well:
PHP Code:
#include <sdktools>
public void OnPluginStart()
{
AddNormalSoundHook(Event_NormalSound);
}
public Action Event_NormalSound(int clients[64], int &numClients, char sample[PLATFORM_MAX_PATH], int &client, int &channel, float &volume, int &level, int &pitch, int &flags)
{
if (StrContains(sample, "_grenade") != -1)
{
PrintToServer(sample);
return Plugin_Handled;
}
return Plugin_Continue;
}
If you want to allow it to be toggled -
PHP Code:
#include <sdktools>
bool g_bToggleEnabled[MAXPLAYERS+1] = {false, ...};
public void OnPluginStart()
{
RegConsoleCmd("sm_blockgrenade", Command_BlockGrenade);
AddNormalSoundHook(Event_NormalSound);
}
public Action Command_BlockGrenade(int client, int args)
{
if (!client || !IsClientInGame(client)) return Plugin_Handled;
if (!g_bToggleEnabled[client])
{
g_bToggleEnabled[client] = true;
PrintToChat(client, "Grenade Radio has been disabled.")
}
else
{
g_bToggleEnabled[client] = false;
PrintToChat(client, "Grenade Radio has been enabled.")
}
return Plugin_Handled;
}
public Action Event_NormalSound(int clients[64], int &numClients, char sample[PLATFORM_MAX_PATH], int &client, int &channel, float &volume, int &level, int &pitch, int &flags)
{
if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || IsFakeClient(client) || IsClientSourceTV(client) || IsClientReplay(client)) return Plugin_Continue;
if (g_bToggleEnabled[client] && StrContains(sample, "_grenade") != -1)
return Plugin_Handled;
return Plugin_Continue;
}
If you want all grenades to be filter from the radio, use
Bacardi's
method.
I've also modified
Bacardi's to be per client toggle if that interests you.
PHP Code:
#include <sdktools>
#include <regex>
#pragma newdecls required
Regex regex_usermsg;
Regex regex_sound;
bool g_bToggleEnabled[MAXPLAYERS+1] = {false, ...};
public void OnPluginStart()
{
if (GetUserMessageType() != UM_Protobuf) SetFailState("Plugin work only UM_Protobuf UserMessages");
UserMsg msg = GetUserMessageId("RadioText");
if (msg == INVALID_MESSAGE_ID) SetFailState("Missing UserMessage RadioText");
regex_usermsg = CompileRegex("^#SFUI_TitlesTXT_.+_in_the_hole$", PCRE_CASELESS|PCRE_MULTILINE);
if (regex_usermsg == null) SetFailState("Regex_usermsg error");
// I had bad time with back slashes \\, I replace them with hex value \x5c
regex_sound = CompileRegex("player\x5c\x5cvo\x5c\x5c.+\x5c\x5c.+(decoy|fire|flashbang|grenade|molotov|smoke).*\x5c.wav");
if (regex_sound == null) SetFailState("Regex_sound error");
HookUserMessage(msg, msg_hook, true);
AddNormalSoundHook(Event_NormalSound);
RegConsoleCmd("sm_blockgrenade", Command_BlockGrenade);
}
public Action Command_BlockGrenade(int client, int args)
{
if (!client || !IsClientInGame(client)) return Plugin_Handled;
if (!g_bToggleEnabled[client])
{
g_bToggleEnabled[client] = true;
PrintToChat(client, "Grenade Radio has been disabled.")
}
else
{
g_bToggleEnabled[client] = false;
PrintToChat(client, "Grenade Radio has been enabled.")
}
return Plugin_Handled;
}
public Action msg_hook(UserMsg msg_id, Protobuf msg, const int[] players, int playersNum, bool reliable, bool init)
{
if (msg.GetRepeatedFieldCount("params") < 4) return Plugin_Continue;
char buffer[40];
// Check translation #phrase (when map location missing = index 1);
msg.ReadString("params", buffer, sizeof(buffer), 1);
if (regex_usermsg.Match(buffer) > 0) return Plugin_Handled;
// Check translation #phrase (when map location included = index 2);
msg.ReadString("params", buffer, sizeof(buffer), 2);
if (regex_usermsg.Match(buffer) > 0) return Plugin_Handled;
return Plugin_Continue;
}
public Action Event_NormalSound(int clients[64], int &numClients, char sample[PLATFORM_MAX_PATH], int &client, int &channel, float &volume, int &level, int &pitch, int &flags)
{
if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || IsFakeClient(client) || IsClientSourceTV(client) || IsClientReplay(client)) return Plugin_Continue;
if (g_bToggleEnabled[client] && regex_sound.Match(sample) > 0) return Plugin_Handled;
return Plugin_Continue;
}