From 77c983d2652bb7a3e33a757a3dd1b49646305ab5 Mon Sep 17 00:00:00 2001 From: BotoX Date: Wed, 19 Apr 2017 19:55:18 +0200 Subject: [PATCH] StopSound: final fix for !stopmusic ? --- StopSound/scripting/StopSound.sp | 37 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/StopSound/scripting/StopSound.sp b/StopSound/scripting/StopSound.sp index 4b3df971..0e0f6776 100644 --- a/StopSound/scripting/StopSound.sp +++ b/StopSound/scripting/StopSound.sp @@ -166,19 +166,6 @@ public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast CPrintToChat(client, "%t %t", "Chat Prefix", "Map music disabled"); } -public void DelayedStopForEntity(DataPack pack) -{ - pack.Reset(); - - char sSample[PLATFORM_MAX_PATH]; - pack.ReadString(sSample, sizeof(sSample)); - int entity = pack.ReadCell(); - - CloseHandle(pack); - - StopSoundFromEntity(sSample, entity); -} - public Action Command_StopSound(int client, int args) { if(client == 0) @@ -670,11 +657,27 @@ public Action Hook_AmbientSound(char sample[PLATFORM_MAX_PATH], int &entity, flo g_MapMusic.SetString(sEntity, sample, true); - DataPack pack = new DataPack(); - pack.WriteString(sample); - pack.WriteCell(entity); + // Check which clients need to be excluded. + int[] newClients = new int[MaxClients]; + int newTotal = 0; + bool bEmitNew = false; - RequestFrame(DelayedStopForEntity, pack); + for(int i = 1; i <= MaxClients; i++) + { + if(!IsClientInGame(i)) + continue; + + if(!g_bStopMapMusic[i]) + newClients[newTotal++] = i; + else + bEmitNew = true; + } + + if(bEmitNew && newTotal) + { + EmitSound(newClients, newTotal, sample, entity, SNDCHAN_STATIC, level, flags, volume, pitch); + return Plugin_Handled; + } return Plugin_Continue; }