From e9ce02f2d4b9f6595a3bcc182bdb6611113c07c0 Mon Sep 17 00:00:00 2001 From: zaCade Date: Thu, 23 Nov 2017 20:05:01 +0100 Subject: [PATCH] StopSound: This seems to work so far.. I know the switch is somewhat 'useless' it just looks cleaner this way. :table: --- StopSound/scripting/StopSound.sp | 76 ++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/StopSound/scripting/StopSound.sp b/StopSound/scripting/StopSound.sp index d3e2ffa2..54b24736 100644 --- a/StopSound/scripting/StopSound.sp +++ b/StopSound/scripting/StopSound.sp @@ -3,14 +3,11 @@ #include #include -#include #include #include #include -#include -#define PLUGIN_VERSION "3.0" -#define MAX_MAPMUSIC_ENTITIES 2048 +#define PLUGIN_VERSION "3.1.0" bool g_bStopWeaponSounds[MAXPLAYERS+1] = { false, ... }; bool g_bStopMapMusic[MAXPLAYERS+1] = { false, ... }; @@ -54,6 +51,9 @@ 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); @@ -118,6 +118,9 @@ 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"); @@ -285,35 +288,29 @@ void CheckMapMusicHooks() void StopMapMusic(int client) { - char sSound[PLATFORM_MAX_PATH]; - char sEntity[16]; int entity = INVALID_ENT_REFERENCE; + char sEntity[16]; + char sSample[PLATFORM_MAX_PATH]; + StringMapSnapshot MapMusicSnap = g_MapMusic.Snapshot(); for(int i = 0; i < MapMusicSnap.Length; i++) { MapMusicSnap.GetKey(i, sEntity, sizeof(sEntity)); - entity = EntRefToEntIndex(StringToInt(sEntity)); - if(entity == INVALID_ENT_REFERENCE) + if((entity = EntRefToEntIndex(StringToInt(sEntity))) == INVALID_ENT_REFERENCE) { g_MapMusic.Remove(sEntity); continue; } - g_MapMusic.GetString(sEntity, sSound, sizeof(sSound)); + g_MapMusic.GetString(sEntity, sSample, sizeof(sSample)); - Client_StopSound(client, entity, SNDCHAN_STATIC, sSound); + EmitSoundToClient(client, sSample, entity, SNDCHAN_STATIC, SNDLEVEL_NONE, SND_STOPLOOPING, SNDVOL_NORMAL, SNDPITCH_NORMAL); } delete MapMusicSnap; } -// I guess this is from SMLib -void Client_StopSound(int client, int entity, int channel, const char[] name) -{ - EmitSoundToClient(client, name, entity, channel, SNDLEVEL_NONE, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true); -} - public void CookieMenuHandler_StopSounds(int client, CookieMenuAction action, any info, char[] buffer, int maxlen) { if(action == CookieMenuAction_DisplayOption) @@ -628,9 +625,9 @@ public void OnReloadEffect(DataPack pack) EndMessage(); } -public Action OnBroadcastSound(int entity, char sample[PLATFORM_MAX_PATH], int clients[MAXPLAYERS], int &numClients) +public Action Hook_AmbientSound(char sample[PLATFORM_MAX_PATH], int &entity, float &volume, int &level, int &pitch, float pos[3], int &flags, float &delay) { - // Music + // Are we playing music? if(sample[0] != '#') return Plugin_Continue; @@ -642,23 +639,36 @@ public Action OnBroadcastSound(int entity, char sample[PLATFORM_MAX_PATH], int c if(!g_bStopMapMusicHooked) return Plugin_Continue; - // Check which clients need to be excluded. - int newClients = 0; - for(int i = 0; i < numClients; i++) + switch(flags) { - int client = clients[i]; - if(!g_bStopMapMusic[client]) + case(SND_NOFLAGS): { - clients[newClients] = clients[i]; - newClients++; + // Starting sound.. + for(int client = 1; client <= MaxClients; client++) + { + if (!IsClientInGame(client) || g_bStopMapMusic[client]) + continue; + + // Stop the old sound.. + EmitSoundToClient(client, sample, entity, SNDCHAN_STATIC, SNDLEVEL_NONE, SND_STOPLOOPING, SNDVOL_NORMAL, SNDPITCH_NORMAL); + + // Pass through the new sound.. + EmitSoundToClient(client, sample, entity, SNDCHAN_STATIC, level, flags, volume, pitch); + } + } + default: + { + // Nothing special going on.. Pass it through.. + for(int client = 1; client <= MaxClients; client++) + { + if (!IsClientInGame(client) || g_bStopMapMusic[client]) + continue; + + EmitSoundToClient(client, sample, entity, SNDCHAN_STATIC, level, flags, volume, pitch); + } } } - if(newClients != numClients) - { - numClients = newClients; - return Plugin_Changed; - } - - return Plugin_Continue; -} + // Block the default sound.. + return Plugin_Handled; +} \ No newline at end of file