View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-14-2020 , 05:45   Re: [CSGO] Block grenade radio sound
Reply With Quote #6

I'm bit hurry to work


here something
PHP Code:
#include <sdktools>
#include <regex>

Regex regex_usermsg;
Regex regex_sound;

public 
void OnPluginStart()
{

    if(
GetUserMessageType() != UM_ProtobufSetFailState("Plugin work only UM_Protobuf UserMessages");

    
UserMsg msg GetUserMessageId("RadioText");
    if(
msg == INVALID_MESSAGE_IDSetFailState("Missing UserMessage RadioText");



    
regex_usermsg CompileRegex("^#SFUI_TitlesTXT_.+_in_the_hole$"PCRE_CASELESS|PCRE_MULTILINE);
    
    if(
regex_usermsg == nullSetFailState("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 == nullSetFailState("Regex_sound error");


    
HookUserMessage(msgmsg_hooktrue);

    
AddNormalSoundHook(soundhook);
}

public 
Action msg_hook(UserMsg msg_idProtobuf msg, const int[] playersint playersNumbool reliablebool init)
{

    if(
msg.GetRepeatedFieldCount("params") < 4) return Plugin_Continue;

    
char buffer[40];

    
// Check translation #phrase (when map location missing = index 1);
    
msg.ReadString("params"buffersizeof(buffer), 1);


    if(
regex_usermsg.Match(buffer) > 0) return Plugin_Handled;

    
// Check translation #phrase (when map location included = index 2);
    
msg.ReadString("params"buffersizeof(buffer), 2);

    if(
regex_usermsg.Match(buffer) > 0) return Plugin_Handled;

    return 
Plugin_Continue;
}


public 
Action soundhook(int clients[MAXPLAYERS], int &numClientschar sample[PLATFORM_MAX_PATH],
      
int &entityint &channelfloat &volumeint &levelint &pitchint &flags,
      
char soundEntry[PLATFORM_MAX_PATH], int &seed)
{

    
    if(
regex_sound.Match(sample) > 0)
    {
        
PrintToServer(sample);
        return 
Plugin_Handled;
    }

    return 
Plugin_Continue;

__________________
Do not Private Message @me
Bacardi is offline