Raised This Month: $32 Target: $400
 8% 

[CSGO] Silence weapon automaticaly


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sHoC
Senior Member
Join Date: Nov 2015
Location: Italy
Old 09-16-2017 , 18:08   [CSGO] Silence weapon automaticaly
Reply With Quote #1

Hello guys, I have this plugin that when you write !stopsound you can turn off the weapons sound from your team mates and you can hear only your weapon shoting, all I want its to set automaticaly the cvar for 1 (enemy cant hear the weapons sound), and after if the players want to hear the weapons sounds they have to write !stopsound and turn it ON.

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
//#undef REQUIRE_PLUGIN
#include <csgo_colors>
#include <clientprefs>

#define PLUGIN_NAME     "Toggle Weapon Sounds clientprefs"
#define PLUGIN_VERSION     "1.0.3 fix m_iWeaponID + new syntax"

//#define UPDATE_URL    "http://godtony.mooo.com/stopsound/stopsound.txt"

bool g_bStopSound[MAXPLAYERS+1]; bool g_bHooked;

Handle g_hClientCookie INVALID_HANDLE;

public 
Plugin myinfo =
{
    
name PLUGIN_NAME,
    
author "GoD-Tony",
    
description "Allows clients to stop hearing weapon sounds",
    
version PLUGIN_VERSION,
    
url "http://www.sourcemod.net/"
};

public 
OnPluginStart()
{
    
LoadTranslations("common.phrases");

    
g_hClientCookie RegClientCookie("sm_stopsound""Toggle hearing weapon sounds"CookieAccess_Private);
    
//SetCookiePrefabMenu(g_hClientCookie, CookieMenu_OnOff_Int, "Toggle Weapon Sounds", StopSoundCookieHandler);
    
SetCookieMenuItem(StopSoundCookieHandlerg_hClientCookie"Toggle Weapon Sounds");

    
// Detect game and hook appropriate tempent.
    
char sGame[32];
    
GetGameFolderName(sGamesizeof(sGame));

    if (
StrEqual(sGame"cstrike") || StrEqual(sGame"csgo"))
        
AddTempEntHook("Shotgun Shot"CSS_Hook_ShotgunShot);
    else if (
StrEqual(sGame"dod"))
        
AddTempEntHook("FireBullets"DODS_Hook_FireBullets);
    
    
// TF2/HL2:DM and misc weapon sounds will be caught here.
    
AddNormalSoundHook(Hook_NormalSound);
    
    
CreateConVar("sm_stopsound_version"PLUGIN_VERSION"Toggle Weapon Sounds"FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
RegConsoleCmd("sm_stopsound"Command_StopSound"Toggle hearing weapon sounds");
    
    
// Updater.
    //if (LibraryExists("updater"))
    //{
    //    Updater_AddPlugin(UPDATE_URL);
    //}

    
for (new 1<= MaxClients; ++i)
    {
        if (!
AreClientCookiesCached(i))
        {
            continue;
        }
        
        
OnClientCookiesCached(i);
    }
}

/*
public OnLibraryAdded(const String:name[])
{
    if (StrEqual(name, "updater"))
    {
        Updater_AddPlugin(UPDATE_URL);
    }
}
*/

public StopSoundCookieHandler(clientCookieMenuAction:actionany:infochar []buffermaxlen)
{
    switch (
action)
    {
        case 
CookieMenuAction_DisplayOption:
        {
        }
        
        case 
CookieMenuAction_SelectOption:
        {
            if(
CheckCommandAccess(client"sm_stopsound"0))
            {
                
PrepareMenu(client);
            }
            else
            {
                
ReplyToCommand(client"[SM] You have no access!");
            }
        }
    }
}

PrepareMenu(client)
{
    
Handle menu CreateMenu(YesNoMenuMENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem|MenuAction_Display);
    
SetMenuTitle(menu"Weapon Sounds -> ");
    
AddMenuItem(menu"0""On");
    
AddMenuItem(menu"1""Off");
    
SetMenuExitButton(menutrue);
    
DisplayMenu(menuclient20);
}

public 
YesNoMenu(Handle menuMenuAction:actionparam1param2)
{
    switch(
action)
    {
        case 
MenuAction_DrawItem:
        {
            
//PrintToServer("MenuAction_DrawItem");
            
if(_:g_bStopSound[param1] == param2)
            {
                
//return ITEMDRAW_DISABLED;
                
return ITEMDRAW_SPACER;
            }
        }
        case 
MenuAction_DisplayItem:
        {
            
//PrintToServer("MenuAction_DisplayItem");
            // Translate
            
char dispBuf[50];
            
GetMenuItem(menuparam2""0_dispBufsizeof(dispBuf));
            
Format(dispBufsizeof(dispBuf), "%T"dispBufparam1);
            return 
RedrawMenuItem(dispBuf);
        }
        case 
MenuAction_Display:
        {
            
//PrintToServer("MenuAction_Display");
            
char buffer[100];
            
GetMenuTitle(menubuffersizeof(buffer));
            
Format(buffersizeof(buffer), "%s : %T"bufferg_bStopSound[param1] ? "Off":"On"param1);
            
SetMenuTitle(menubuffer);
        }
        case 
MenuAction_Select:
        {
            
// Can still choose menu option using console cmd "menuselect" "1", lets recheck
            // Or cvar change in this moment before player choose option

            //PrintToServer("MenuAction_Select");
            
char info[50];
            if( 
GetMenuItem(menuparam2infosizeof(info)) )
            {
                
SetClientCookie(param1g_hClientCookieinfo);
                
g_bStopSound[param1] = StringToInt(info) != 0;
                
CPrintToChat(param1"{GREEN}[{BLUE}Weapons{GREEN}] {OLIVE}Sound from other players guns is now {RED}%s."g_bStopSound[param1] ? "Off" "On");
                
CheckHooks();
                
PrepareMenu(param1);
            }
        }
        case 
MenuAction_Cancel:
        {
            
//PrintToServer("MenuAction_Cancel");
            
if( param2 == MenuCancel_Exit // Exit go back !settings
            
{
                
ShowCookieMenu(param1);
            }
        }
        case 
MenuAction_End:
        {
            
//PrintToServer("MenuAction_End");
            
CloseHandle(menu);
        }
    }

    return 
0;
}

public 
OnClientCookiesCached(client)
{
    
char sValue[8];
    
GetClientCookie(clientg_hClientCookiesValuesizeof(sValue));
    
    
g_bStopSound[client] = (sValue[0] != '\0' && StringToInt(sValue));
    
CheckHooks();
}

public 
Action Command_StopSound(clientargs)
{
    if(
AreClientCookiesCached(client))
    {
        
PrepareMenu(client);
    }
    else
    {
        
ReplyToCommand(client"[SM] Your Cookies are not yet cached. Please try again later...");
    }
    
//g_bStopSound[client] = !g_bStopSound[client];
    //ReplyToCommand(client, "[SM] Weapon sounds %s.", g_bStopSound[client] ? "disabled" : "enabled");
    //CheckHooks();
    
    
return Plugin_Handled;
}

public 
OnClientDisconnect_Post(client)
{
    
g_bStopSound[client] = false;
    
CheckHooks();
}

CheckHooks()
{
    
bool bShouldHook false;
    
    for (new 
1<= MaxClientsi++)
    {
        if (
g_bStopSound[i])
        {
            
bShouldHook true;
            break;
        }
    }
    
    
// Fake (un)hook because toggling actual hooks will cause server instability.
    
g_bHooked bShouldHook;
}

public 
Action Hook_NormalSound(clients[64], &numClientschar sample[PLATFORM_MAX_PATH], &entity, &channel, &Float:volume, &level, &pitch, &flags)
{
    
// Ignore non-weapon sounds.
    
if (!g_bHooked || !(strncmp(sample"weapons"7) == || strncmp(sample[1], "weapons"7) == 0))
        return 
Plugin_Continue;
    
    
int ij;
    
    for (
0numClientsi++)
    {
        if (
g_bStopSound[clients[i]])
        {
            
// Remove the client from the array.
            
for (inumClients-1j++)
            {
                
clients[j] = clients[j+1];
            }
            
            
numClients--;
            
i--;
        }
    }
    
    return (
numClients 0) ? Plugin_Changed Plugin_Stop;
}

public 
Action CSS_Hook_ShotgunShot(const char []te_name, const Players[], numClientsfloat delay)
{
    if (!
g_bHooked)
        return 
Plugin_Continue;
    
    
// Check which clients need to be excluded.
    
decl newClients[MaxClients], clienti;
    
int newTotal 0;
    
    for (
0numClientsi++)
    {
        
client Players[i];
        
        if (!
g_bStopSound[client])
        {
            
newClients[newTotal++] = client;
        }
    }
    
    
// No clients were excluded.
    
if (newTotal == numClients)
        return 
Plugin_Continue;
    
    
// All clients were excluded and there is no need to broadcast.
    
else if (newTotal == 0)
        return 
Plugin_Stop;
    
    
// Re-broadcast to clients that still need it.
    
float vTemp[3];
    
TE_Start("Shotgun Shot");
    
TE_ReadVector("m_vecOrigin"vTemp);
    
TE_WriteVector("m_vecOrigin"vTemp);
    
TE_WriteFloat("m_vecAngles[0]"TE_ReadFloat("m_vecAngles[0]"));
    
TE_WriteFloat("m_vecAngles[1]"TE_ReadFloat("m_vecAngles[1]"));
    
TE_WriteNum("m_weapon"TE_ReadNum("m_weapon"));
    
TE_WriteNum("m_iMode"TE_ReadNum("m_iMode"));
    
TE_WriteNum("m_iSeed"TE_ReadNum("m_iSeed"));
    
TE_WriteNum("m_iPlayer"TE_ReadNum("m_iPlayer"));
    
TE_WriteFloat("m_fInaccuracy"TE_ReadFloat("m_fInaccuracy"));
    
TE_WriteFloat("m_fSpread"TE_ReadFloat("m_fSpread"));
    
TE_Send(newClientsnewTotaldelay);
    
    return 
Plugin_Stop;
}

public 
Action DODS_Hook_FireBullets(const char []te_name, const Players[], numClientsfloat delay)
{
    if (!
g_bHooked)
        return 
Plugin_Continue;
    
    
// Check which clients need to be excluded.
    
decl newClients[MaxClients], clienti;
    
int newTotal 0;
    
    for (
0numClientsi++)
    {
        
client Players[i];
        
        if (!
g_bStopSound[client])
        {
            
newClients[newTotal++] = client;
        }
    }
    
    
// No clients were excluded.
    
if (newTotal == numClients)
        return 
Plugin_Continue;
    
    
// All clients were excluded and there is no need to broadcast.
    
else if (newTotal == 0)
        return 
Plugin_Stop;
    
    
// Re-broadcast to clients that still need it.
    
float vTemp[3];
    
TE_Start("FireBullets");
    
TE_ReadVector("m_vecOrigin"vTemp);
    
TE_WriteVector("m_vecOrigin"vTemp);
    
TE_WriteFloat("m_vecAngles[0]"TE_ReadFloat("m_vecAngles[0]"));
    
TE_WriteFloat("m_vecAngles[1]"TE_ReadFloat("m_vecAngles[1]"));
    
TE_WriteNum("m_weapon"TE_ReadNum("m_weapon"));
    
TE_WriteNum("m_iMode"TE_ReadNum("m_iMode"));
    
TE_WriteNum("m_iSeed"TE_ReadNum("m_iSeed"));
    
TE_WriteNum("m_iPlayer"TE_ReadNum("m_iPlayer"));
    
TE_WriteFloat("m_flSpread"TE_ReadFloat("m_flSpread"));
    
TE_Send(newClientsnewTotaldelay);
    
    return 
Plugin_Stop;

__________________
sHoC is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 09-20-2017 , 04:18   Re: [CSGO] Silence weapon automaticaly
Reply With Quote #2

Haven't tested but try this
EDIT: forgot to change when cookies get loaded, did what Papero suggested
Attached Files
File Type: sp Get Plugin or Get Source (silence.sp - 735 views - 5.8 KB)

Last edited by hmmmmm; 09-20-2017 at 05:29.
hmmmmm is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 09-20-2017 , 05:09   Re: [CSGO] Silence weapon automaticaly
Reply With Quote #3

I think you can just change this
PHP Code:
public OnClientCookiesCached(client

    
char sValue[8]; 
    
GetClientCookie(clientg_hClientCookiesValuesizeof(sValue)); 
     
    
g_bStopSound[client] = (sValue[0] != '\0' && StringToInt(sValue)); 
    
CheckHooks(); 

To
Code:
public OnClientCookiesCached(client) 
{ 
    char sValue[8]; 
    GetClientCookie(client, g_hClientCookie, sValue, sizeof(sValue)); 
     
    g_bStopSound = (!(sValue[0] != '\0' && StringToInt(sValue))); 
    CheckHooks(); 
}
So when it is false(default) will be true.
Also:
PHP Code:
PrepareMenu(client

    
Handle menu CreateMenu(YesNoMenuMENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem|MenuAction_Display); 
    
SetMenuTitle(menu"Weapon Sounds -> "); 
    
AddMenuItem(menu"0""On"); 
    
AddMenuItem(menu"1""Off"); 
    
SetMenuExitButton(menutrue); 
    
DisplayMenu(menuclient20); 

To
Code:
PrepareMenu(client) 
{ 
    Handle menu = CreateMenu(YesNoMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem|MenuAction_Display); 
    SetMenuTitle(menu, "Weapon Sounds -> "); 
    AddMenuItem(menu, "1", "On"); 
    AddMenuItem(menu, "0", "Off");
    SetMenuExitButton(menu, true); 
    DisplayMenu(menu, client, 20); 
}
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!

Last edited by Papero; 09-20-2017 at 06:26.
Papero is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode