StopSound: Use new OnBroadcastSound forward from CSSFixes

This commit is contained in:
BotoX 2017-08-04 09:31:00 +02:00
parent c993d05129
commit e1bab3c5b8
2 changed files with 22 additions and 29 deletions

View File

@ -7,8 +7,9 @@
#include <cstrike>
#include <clientprefs>
#include <multicolors>
#include <CSSFixes>
#define PLUGIN_VERSION "2.1.0"
#define PLUGIN_VERSION "3.0"
#define MAX_MAPMUSIC_ENTITIES 2048
bool g_bStopWeaponSounds[MAXPLAYERS+1] = { false, ... };
@ -53,17 +54,15 @@ public void OnPluginStart()
// Detect game and hook appropriate tempent.
AddTempEntHook("Shotgun Shot", CSS_Hook_ShotgunShot);
// Ambient sounds
//AddAmbientSoundHook(Hook_AmbientSound);
// Map music will be caught here
HookEvent("round_end", Event_RoundEnd);
HookEvent("player_spawn", Event_PlayerSpawn);
CreateConVar("sm_stopsound_version", PLUGIN_VERSION, "Toggle Weapon Sounds", FCVAR_NOTIFY|FCVAR_DONTRECORD|FCVAR_REPLICATED);
RegConsoleCmd("sm_stopsound", Command_StopSound, "Toggle hearing weapon sounds");
//RegConsoleCmd("sm_stopmusic", Command_StopMusic, "Toggle hearing map music");
//RegConsoleCmd("sm_music", Command_StopMusic, "Toggle hearing map music");
RegConsoleCmd("sm_sound", Command_StopSound, "Toggle hearing weapon sounds");
RegConsoleCmd("sm_stopmusic", Command_StopMusic, "Toggle hearing map music");
RegConsoleCmd("sm_music", Command_StopMusic, "Toggle hearing map music");
// Cookies
g_hCookieStopSound = RegClientCookie("weaponsound_blocked", "Are weapon sounds enabled", CookieAccess_Protected);
@ -119,9 +118,6 @@ public void OnPluginEnd()
// Remove tempent hook
RemoveTempEntHook("Shotgun Shot", CSS_Hook_ShotgunShot);
// Remove ambient sound hook
//RemoveAmbientSoundHook(Hook_AmbientSound);
// Find ReloadEffect
UserMsg ReloadEffect = GetUserMessageId("ReloadEffect");
@ -235,7 +231,7 @@ public void OnClientCookiesCached(int client)
// Map Music cookie
GetClientCookie(client, g_hCookieStopMapMusic, sBuffer, sizeof(sBuffer));
if(sBuffer[0] != '\0' && false)
if(sBuffer[0] != '\0')
{
g_bStopMapMusic[client] = true;
g_bStopMapMusicHooked = true;
@ -643,11 +639,8 @@ public void OnReloadEffect(DataPack pack)
EndMessage();
}
public Action Hook_AmbientSound(char sample[PLATFORM_MAX_PATH], int &entity, float &volume, int &level, int &pitch, float pos[3], int &flags, float &delay)
public Action OnBroadcastSound(int entity, char sample[PLATFORM_MAX_PATH], int clients[MAXPLAYERS], int &numClients)
{
if(!g_bStopMapMusicHooked)
return Plugin_Continue;
// Music
if(sample[0] != '#')
return Plugin_Continue;
@ -657,26 +650,25 @@ public Action Hook_AmbientSound(char sample[PLATFORM_MAX_PATH], int &entity, flo
g_MapMusic.SetString(sEntity, sample, true);
if(!g_bStopMapMusicHooked)
return Plugin_Continue;
// Check which clients need to be excluded.
int[] newClients = new int[MaxClients];
int newTotal = 0;
bool bEmitNew = false;
for(int i = 1; i <= MaxClients; i++)
int newClients = 0;
for(int i = 0; i < numClients; i++)
{
if(!IsClientInGame(i))
continue;
if(!g_bStopMapMusic[i])
newClients[newTotal++] = i;
else
bEmitNew = true;
int client = clients[i];
if(!g_bStopMapMusic[client])
{
clients[numClients] = clients[i];
newClients++;
}
}
if(bEmitNew && newTotal)
if(newClients != numClients)
{
EmitSound(newClients, newTotal, sample, entity, SNDCHAN_STATIC, level, flags, volume, pitch);
return Plugin_Handled;
numClients = newClients;
return Plugin_Changed;
}
return Plugin_Continue;

View File

@ -5,6 +5,7 @@
forward void OnRunThinkFunctions(bool simulating);
forward void OnRunThinkFunctionsPost(bool simulating);
forward Action OnBroadcastSound(int entity, char sample[PLATFORM_MAX_PATH], int clients[MAXPLAYERS], int &numClients);
public Extension __ext_CSSFixes =
{