StopSound: This seems to work so far..

I know the switch is somewhat 'useless' it just looks cleaner this way.
:table:
This commit is contained in:
zaCade 2017-11-23 20:05:01 +01:00
parent b06ee55b63
commit e9ce02f2d4

View File

@ -3,14 +3,11 @@
#include <sourcemod> #include <sourcemod>
#include <sdktools> #include <sdktools>
#include <sdkhooks>
#include <cstrike> #include <cstrike>
#include <clientprefs> #include <clientprefs>
#include <multicolors> #include <multicolors>
#include <CSSFixes>
#define PLUGIN_VERSION "3.0" #define PLUGIN_VERSION "3.1.0"
#define MAX_MAPMUSIC_ENTITIES 2048
bool g_bStopWeaponSounds[MAXPLAYERS+1] = { false, ... }; bool g_bStopWeaponSounds[MAXPLAYERS+1] = { false, ... };
bool g_bStopMapMusic[MAXPLAYERS+1] = { false, ... }; bool g_bStopMapMusic[MAXPLAYERS+1] = { false, ... };
@ -54,6 +51,9 @@ public void OnPluginStart()
// Detect game and hook appropriate tempent. // Detect game and hook appropriate tempent.
AddTempEntHook("Shotgun Shot", CSS_Hook_ShotgunShot); AddTempEntHook("Shotgun Shot", CSS_Hook_ShotgunShot);
// Ambient sounds
AddAmbientSoundHook(Hook_AmbientSound);
// Map music will be caught here // Map music will be caught here
HookEvent("round_end", Event_RoundEnd); HookEvent("round_end", Event_RoundEnd);
HookEvent("player_spawn", Event_PlayerSpawn); HookEvent("player_spawn", Event_PlayerSpawn);
@ -118,6 +118,9 @@ public void OnPluginEnd()
// Remove tempent hook // Remove tempent hook
RemoveTempEntHook("Shotgun Shot", CSS_Hook_ShotgunShot); RemoveTempEntHook("Shotgun Shot", CSS_Hook_ShotgunShot);
// Remove ambient sound hook
RemoveAmbientSoundHook(Hook_AmbientSound);
// Find ReloadEffect // Find ReloadEffect
UserMsg ReloadEffect = GetUserMessageId("ReloadEffect"); UserMsg ReloadEffect = GetUserMessageId("ReloadEffect");
@ -285,35 +288,29 @@ void CheckMapMusicHooks()
void StopMapMusic(int client) void StopMapMusic(int client)
{ {
char sSound[PLATFORM_MAX_PATH];
char sEntity[16];
int entity = INVALID_ENT_REFERENCE; int entity = INVALID_ENT_REFERENCE;
char sEntity[16];
char sSample[PLATFORM_MAX_PATH];
StringMapSnapshot MapMusicSnap = g_MapMusic.Snapshot(); StringMapSnapshot MapMusicSnap = g_MapMusic.Snapshot();
for(int i = 0; i < MapMusicSnap.Length; i++) for(int i = 0; i < MapMusicSnap.Length; i++)
{ {
MapMusicSnap.GetKey(i, sEntity, sizeof(sEntity)); 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); g_MapMusic.Remove(sEntity);
continue; 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; 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) public void CookieMenuHandler_StopSounds(int client, CookieMenuAction action, any info, char[] buffer, int maxlen)
{ {
if(action == CookieMenuAction_DisplayOption) if(action == CookieMenuAction_DisplayOption)
@ -628,9 +625,9 @@ public void OnReloadEffect(DataPack pack)
EndMessage(); 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] != '#') if(sample[0] != '#')
return Plugin_Continue; return Plugin_Continue;
@ -642,23 +639,36 @@ public Action OnBroadcastSound(int entity, char sample[PLATFORM_MAX_PATH], int c
if(!g_bStopMapMusicHooked) if(!g_bStopMapMusicHooked)
return Plugin_Continue; return Plugin_Continue;
// Check which clients need to be excluded. switch(flags)
int newClients = 0;
for(int i = 0; i < numClients; i++)
{ {
int client = clients[i]; case(SND_NOFLAGS):
if(!g_bStopMapMusic[client])
{ {
clients[newClients] = clients[i]; // Starting sound..
newClients++; 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) // Block the default sound..
{ return Plugin_Handled;
numClients = newClients; }
return Plugin_Changed;
}
return Plugin_Continue;
}