From 0efe3239aa8faa480bab7a65df62b08b6c6c42f7 Mon Sep 17 00:00:00 2001 From: BotoX Date: Mon, 20 Mar 2017 11:52:00 +0100 Subject: [PATCH] Reworked StopSound --- StopSound/scripting/StopSound.sp | 380 +++++++++++-------------------- 1 file changed, 135 insertions(+), 245 deletions(-) diff --git a/StopSound/scripting/StopSound.sp b/StopSound/scripting/StopSound.sp index 36527b56..4b3df971 100644 --- a/StopSound/scripting/StopSound.sp +++ b/StopSound/scripting/StopSound.sp @@ -1,33 +1,23 @@ #pragma semicolon 1 +#pragma newdecls required #include #include #include #include #include - #include -#pragma newdecls required - +#define PLUGIN_VERSION "2.1.0" #define MAX_MAPMUSIC_ENTITIES 2048 -#define PLUGIN_VERSION "2.0.4" - -int MAX_ENTITIES = 0; -bool g_bLateLoad = false; - bool g_bStopWeaponSounds[MAXPLAYERS+1] = { false, ... }; bool g_bStopMapMusic[MAXPLAYERS+1] = { false, ... }; bool g_bStopWeaponSoundsHooked = false; bool g_bStopMapMusicHooked = false; -int g_iMapMusicEntities[MAX_MAPMUSIC_ENTITIES]; -int g_iNumSounds = 0; - -static char g_sKVPATH[PLATFORM_MAX_PATH]; -KeyValues g_hWepSounds; +StringMap g_MapMusic; Handle g_hCookieStopSound = null; Handle g_hCookieStopMapMusic = null; @@ -43,14 +33,12 @@ public Plugin myinfo = public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) { - if (GetEngineVersion() != Engine_CSGO && GetEngineVersion() != Engine_CSS) + if(GetEngineVersion() != Engine_CSGO && GetEngineVersion() != Engine_CSS) { strcopy(error, err_max, "This plugin supports only CS:GO and CS:S!"); return APLRes_Failure; } - g_bLateLoad = late; - return APLRes_Success; } @@ -60,6 +48,8 @@ public void OnPluginStart() LoadTranslations("plugin.stopsound.phrases"); LoadTranslations("common.phrases"); // For On/Off buttons in Cookies Menu + g_MapMusic = new StringMap(); + // Detect game and hook appropriate tempent. AddTempEntHook("Shotgun Shot", CSS_Hook_ShotgunShot); @@ -75,11 +65,6 @@ public void OnPluginStart() RegConsoleCmd("sm_stopmusic", Command_StopMusic, "Toggle hearing map music"); RegConsoleCmd("sm_music", Command_StopMusic, "Toggle hearing map music"); - // Create KeyValues - g_hWepSounds = new KeyValues("WeaponSounds"); - BuildPath(Path_SM, g_sKVPATH, sizeof(g_sKVPATH), "data/playerprefs.WepSounds.txt"); - g_hWepSounds.ImportFromFile(g_sKVPATH); - // Cookies g_hCookieStopSound = RegClientCookie("weaponsound_blocked", "Are weapon sounds enabled", CookieAccess_Protected); g_hCookieStopMapMusic = RegClientCookie("mapmusic_blocked", "Are map music enabled", CookieAccess_Protected); @@ -90,60 +75,44 @@ public void OnPluginStart() UserMsg ReloadEffect = GetUserMessageId("ReloadEffect"); // Game-specific setup - if (GetEngineVersion() == Engine_CSGO) + if(GetEngineVersion() == Engine_CSGO) { - MAX_ENTITIES = 4096; - // Weapon sounds will be caught here. AddNormalSoundHook(Hook_NormalSound_CSGO); - if (ReloadEffect != INVALID_MESSAGE_ID) + if(ReloadEffect != INVALID_MESSAGE_ID) { HookUserMessage(ReloadEffect, Hook_ReloadEffect_CSGO, true); } } - else + else // CS:S { - // CS:S - MAX_ENTITIES = 2048; - // Weapon sounds will be caught here. AddNormalSoundHook(Hook_NormalSound_CSS); - if (ReloadEffect != INVALID_MESSAGE_ID) + if(ReloadEffect != INVALID_MESSAGE_ID) { HookUserMessage(ReloadEffect, Hook_ReloadEffect_CSS, true); } } // Late load - if (g_bLateLoad) + for(int client = 1; client <= MaxClients; client++) { - int entity = -1; - while ((entity = FindEntityByClassname(entity, "ambient_generic*")) != -1) + if(IsClientInGame(client) && AreClientCookiesCached(client)) { - OnEntitySpawned(entity); + OnClientCookiesCached(client); } - - for (int client = 1; client <= MaxClients; client++) - { - if (IsClientInGame(client) && AreClientCookiesCached(client)) - { - OnClientCookiesCached(client); - } - } - - g_bLateLoad = false; } } public void OnPluginEnd() { - for (int client = 1; client <= MaxClients; client++) + for(int client = 1; client <= MaxClients; client++) { - if (IsClientInGame(client)) + if(IsClientInGame(client)) { - OnClientDisconnect_Post(client); + OnClientDisconnect(client); } } @@ -157,109 +126,62 @@ public void OnPluginEnd() UserMsg ReloadEffect = GetUserMessageId("ReloadEffect"); // Remove game-specific staff - if (GetEngineVersion() == Engine_CSGO) + if(GetEngineVersion() == Engine_CSGO) { RemoveNormalSoundHook(Hook_NormalSound_CSGO); - if (ReloadEffect != INVALID_MESSAGE_ID) - { + if(ReloadEffect != INVALID_MESSAGE_ID) UnhookUserMessage(ReloadEffect, Hook_ReloadEffect_CSGO, true); - } } else { RemoveNormalSoundHook(Hook_NormalSound_CSS); - if (ReloadEffect != INVALID_MESSAGE_ID) - { + if(ReloadEffect != INVALID_MESSAGE_ID) UnhookUserMessage(ReloadEffect, Hook_ReloadEffect_CSS, true); - } } - - // Delete KeyValues - delete g_hWepSounds; } public void OnMapStart() { - g_iNumSounds = 0; -} - -public void OnEntityCreated(int entity, const char[] classname) -{ - if (!StrEqual(classname, "ambient_generic", false)) - { - return; - } - - SDKHook(entity, SDKHook_Spawn, OnEntitySpawned); -} - -public void OnEntitySpawned(int entity) -{ - if (entity < 0 || entity > MAX_ENTITIES || !IsValidEntity(entity)) - { - return; - } - - if (g_iNumSounds >= MAX_MAPMUSIC_ENTITIES) - { - // Something went wrong... - return; - } - char sSoundPath[PLATFORM_MAX_PATH]; - GetEntPropString(entity, Prop_Data, "m_iszSound", sSoundPath, sizeof(sSoundPath)); - - int iLen = strlen(sSoundPath); - - if (iLen > 4 && (StrEqual(sSoundPath[iLen - 4], ".mp3", false) || StrEqual(sSoundPath[iLen - 4], ".wav", false))) - { - g_iMapMusicEntities[g_iNumSounds++] = EntIndexToEntRef(entity); - } + g_MapMusic.Clear(); } public void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast) { - g_iNumSounds = 0; + g_MapMusic.Clear(); } public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast) { int client = GetClientOfUserId(event.GetInt("userid")); - if (!IsClientInGame(client) || GetClientTeam(client) <= CS_TEAM_SPECTATOR) - { + if(!IsClientInGame(client) || GetClientTeam(client) <= CS_TEAM_SPECTATOR) return; - } - if (g_bStopWeaponSounds[client]) - { + if(g_bStopWeaponSounds[client]) CPrintToChat(client, "%t %t", "Chat Prefix", "Weapon sounds disabled"); - } - if (g_bStopMapMusic[client]) - { + if(g_bStopMapMusic[client]) CPrintToChat(client, "%t %t", "Chat Prefix", "Map music disabled"); - } } -public Action Timer_DelayedStopForEntity(Handle timer, any data) +public void DelayedStopForEntity(DataPack pack) { - DataPack datapack = view_as(data); - datapack.Reset(); + pack.Reset(); char sSample[PLATFORM_MAX_PATH]; - datapack.ReadString(sSample, sizeof(sSample)); - int entity = datapack.ReadCell(); + pack.ReadString(sSample, sizeof(sSample)); + int entity = pack.ReadCell(); + + CloseHandle(pack); StopSoundFromEntity(sSample, entity); - - return Plugin_Stop; } public Action Command_StopSound(int client, int args) { - if (client == 0) + if(client == 0) { ReplyToCommand(client, "[SM] Cannot use command from server console."); return Plugin_Handled; @@ -268,14 +190,14 @@ public Action Command_StopSound(int client, int args) g_bStopWeaponSounds[client] = !g_bStopWeaponSounds[client]; CheckWeaponSoundsHooks(); - if (g_bStopWeaponSounds[client]) + if(g_bStopWeaponSounds[client]) { SetClientCookie(client, g_hCookieStopSound, "1"); CReplyToCommand(client, "%t %t", "Chat Prefix", "Weapon sounds disabled"); } else { - SetClientCookie(client, g_hCookieStopSound, "0"); + SetClientCookie(client, g_hCookieStopSound, ""); CReplyToCommand(client, "%t %t", "Chat Prefix", "Weapon sounds enabled"); } @@ -284,7 +206,7 @@ public Action Command_StopSound(int client, int args) public Action Command_StopMusic(int client, int args) { - if (client == 0) + if(client == 0) { ReplyToCommand(client, "[SM] Cannot use command from server console."); return Plugin_Handled; @@ -293,7 +215,7 @@ public Action Command_StopMusic(int client, int args) g_bStopMapMusic[client] = !g_bStopMapMusic[client]; CheckMapMusicHooks(); - if (g_bStopMapMusic[client]) + if(g_bStopMapMusic[client]) { SetClientCookie(client, g_hCookieStopMapMusic, "1"); CReplyToCommand(client, "%t %t", "Chat Prefix", "Map music disabled"); @@ -301,7 +223,7 @@ public Action Command_StopMusic(int client, int args) } else { - SetClientCookie(client, g_hCookieStopMapMusic, "0"); + SetClientCookie(client, g_hCookieStopMapMusic, ""); CReplyToCommand(client, "%t %t", "Chat Prefix", "Map music enabled"); } @@ -311,68 +233,31 @@ public Action Command_StopMusic(int client, int args) public void OnClientCookiesCached(int client) { char sBuffer[2]; - int iValue = 0; // Weapon Sounds cookie GetClientCookie(client, g_hCookieStopSound, sBuffer, sizeof(sBuffer)); - iValue = StringToInt(sBuffer); - if (iValue == 1) + if(sBuffer[0] != '\0') { g_bStopWeaponSounds[client] = true; g_bStopWeaponSoundsHooked = true; } else - { - g_bStopWeaponSounds[client] = BackwardCapabilityCheck(client); - - if (iValue != 0) - { - SetClientCookie(client, g_hCookieStopSound, "0"); - } - } + g_bStopWeaponSounds[client] = false; // Map Music cookie GetClientCookie(client, g_hCookieStopMapMusic, sBuffer, sizeof(sBuffer)); - iValue = StringToInt(sBuffer); - if (iValue == 1) + if(sBuffer[0] != '\0') { g_bStopMapMusic[client] = true; g_bStopMapMusicHooked = true; } else - { g_bStopMapMusic[client] = false; - - if (iValue != 0) - { - SetClientCookie(client, g_hCookieStopMapMusic, "0"); - } - } } -// Because we have some players, whose settings are saved to KV file. We want to save this data. -bool BackwardCapabilityCheck(int client) -{ - char sSteamId[32]; - GetClientAuthId(client, AuthId_Steam2, sSteamId, sizeof(sSteamId)); - - g_hWepSounds.Rewind(); - - if (!g_hWepSounds.JumpToKey(sSteamId, false)) - { - return false; - } - - int disabled = g_hWepSounds.GetNum("disabled", 0); - g_hWepSounds.DeleteThis(); - g_hWepSounds.Rewind(); - - return (disabled == 1); -} - -public void OnClientDisconnect_Post(int client) +public void OnClientDisconnect(int client) { g_bStopWeaponSounds[client] = false; g_bStopMapMusic[client] = false; @@ -385,9 +270,9 @@ void CheckWeaponSoundsHooks() { bool bShouldHook = false; - for (int i = 1; i <= MaxClients; i++) + for(int i = 1; i <= MaxClients; i++) { - if (g_bStopWeaponSounds[i]) + if(g_bStopWeaponSounds[i]) { bShouldHook = true; break; @@ -402,9 +287,9 @@ void CheckMapMusicHooks() { bool bShouldHook = false; - for (int i = 1; i <= MaxClients; i++) + for(int i = 1; i <= MaxClients; i++) { - if (g_bStopMapMusic[i]) + if(g_bStopMapMusic[i]) { bShouldHook = true; break; @@ -418,45 +303,39 @@ void CheckMapMusicHooks() void StopMapMusic() { char sSound[PLATFORM_MAX_PATH]; + char sEntity[16]; int entity = INVALID_ENT_REFERENCE; - for (int i = 0; i < g_iNumSounds; i++) + StringMapSnapshot MapMusicSnap = g_MapMusic.Snapshot(); + for(int i = 0; i < MapMusicSnap.Length; i++) { - entity = EntRefToEntIndex(g_iMapMusicEntities[i]); + MapMusicSnap.GetKey(i, sEntity, sizeof(sEntity)); + entity = EntRefToEntIndex(StringToInt(sEntity)); - if (entity != INVALID_ENT_REFERENCE) + if(entity == INVALID_ENT_REFERENCE) { - GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound)); - - StopSoundFromEntity(sSound, entity); + g_MapMusic.Remove(sEntity); + continue; } + + g_MapMusic.GetString(sEntity, sSound, sizeof(sSound)); + + StopSoundFromEntity(sSound, entity); } + delete MapMusicSnap; } void StopSoundFromEntity(const char[] sSample, int entity) { - for (int i = 1; i <= MaxClients; i++) + for(int i = 1; i <= MaxClients; i++) { - if (g_bStopMapMusic[i] && IsClientInGame(i)) + if(g_bStopMapMusic[i] && IsClientInGame(i)) { Client_StopSound(i, entity, SNDCHAN_STATIC, sSample); } } } -bool IsEntityInMapMusicEntities(int entity) -{ - for (int i = 0; i < g_iNumSounds; i++) - { - if (entity == EntRefToEntIndex(g_iMapMusicEntities[i])) - { - return true; - } - } - - return false; -} - // I guess this is from SMLib void Client_StopSound(int client, int entity, int channel, const char[] name) { @@ -465,11 +344,11 @@ void Client_StopSound(int client, int entity, int channel, const char[] name) public void CookieMenuHandler_StopSounds(int client, CookieMenuAction action, any info, char[] buffer, int maxlen) { - if (action == CookieMenuAction_DisplayOption) + if(action == CookieMenuAction_DisplayOption) { Format(buffer, maxlen, "%T", "Cookie Menu Stop Sounds", client); } - else if (action == CookieMenuAction_SelectOption) + else if(action == CookieMenuAction_SelectOption) { ShowStopSoundsSettingsMenu(client); } @@ -495,35 +374,35 @@ void ShowStopSoundsSettingsMenu(int client) public int MenuHandler_StopSoundsSettings(Menu menu, MenuAction action, int client, int selection) { - if (action == MenuAction_Cancel) + if(action == MenuAction_Cancel) { ShowCookieMenu(client); } - else if (action == MenuAction_Select) + else if(action == MenuAction_Select) { - if (selection == 0) + if(selection == 0) { g_bStopWeaponSounds[client] = !g_bStopWeaponSounds[client]; CheckWeaponSoundsHooks(); - if (g_bStopWeaponSounds[client]) + if(g_bStopWeaponSounds[client]) { SetClientCookie(client, g_hCookieStopSound, "1"); CPrintToChat(client, "%t %t", "Chat Prefix", "Weapon sounds disabled"); } else { - SetClientCookie(client, g_hCookieStopSound, "0"); + SetClientCookie(client, g_hCookieStopSound, ""); CPrintToChat(client, "%t %t", "Chat Prefix", "Weapon sounds enabled"); } } - else if (selection == 1) + else if(selection == 1) { g_bStopMapMusic[client] = !g_bStopMapMusic[client]; CheckMapMusicHooks(); - if (g_bStopMapMusic[client]) + if(g_bStopMapMusic[client]) { SetClientCookie(client, g_hCookieStopMapMusic, "1"); CPrintToChat(client, "%t %t", "Chat Prefix", "Map music disabled"); @@ -531,14 +410,14 @@ public int MenuHandler_StopSoundsSettings(Menu menu, MenuAction action, int clie } else { - SetClientCookie(client, g_hCookieStopMapMusic, "0"); + SetClientCookie(client, g_hCookieStopMapMusic, ""); CPrintToChat(client, "%t %t", "Chat Prefix", "Map music enabled"); } } ShowStopSoundsSettingsMenu(client); } - else if (action == MenuAction_End) + else if(action == MenuAction_End) { delete menu; } @@ -548,27 +427,31 @@ public Action Hook_NormalSound_CSS(int clients[MAXPLAYERS], int &numClients, cha int &entity, int &channel, float &volume, int &level, int &pitch, int &flags, char soundEntry[PLATFORM_MAX_PATH], int &seed) { + if(!g_bStopWeaponSoundsHooked) + return Plugin_Continue; + // Ignore non-weapon sounds. - if (!g_bStopWeaponSoundsHooked || channel != SNDCHAN_WEAPON) + if(channel != SNDCHAN_WEAPON && + !(channel == SNDCHAN_AUTO && strncmp(sample, "physics/flesh", 13) == 0) && + !(channel == SNDCHAN_VOICE && StrContains(sample, "player/headshot", true) != -1)) { return Plugin_Continue; } - for (int i = 0; i < numClients; i++) + int j = 0; + for(int i = 0; i < numClients; i++) { int client = clients[i]; - if (g_bStopWeaponSounds[client]) + if(!g_bStopWeaponSounds[client] && IsClientInGame(client)) { - // Remove the client from the array. - for (int j = i; j < numClients - 1; j++) { - clients[j] = clients[j + 1]; - } - - numClients--; - i--; + // Keep client. + clients[j] = clients[i]; + j++; } } + numClients = j; + return (numClients > 0) ? Plugin_Changed : Plugin_Stop; } @@ -576,55 +459,57 @@ public Action Hook_NormalSound_CSGO(int clients[MAXPLAYERS], int &numClients, ch int &entity, int &channel, float &volume, int &level, int &pitch, int &flags, char soundEntry[PLATFORM_MAX_PATH], int &seed) { + if(!g_bStopWeaponSoundsHooked) + return Plugin_Continue; + // Ignore non-weapon sounds. - if (!g_bStopWeaponSoundsHooked || (channel != SNDCHAN_WEAPON && !(channel == SNDCHAN_AUTO && strncmp(sample, "physics/flesh", 13) == 0) && !(channel == SNDCHAN_STATIC && StrContains(sample, "player/headshot", true) != -1))) + if(channel != SNDCHAN_WEAPON && + !(channel == SNDCHAN_AUTO && strncmp(sample, "physics/flesh", 13) == 0) && + !(channel == SNDCHAN_STATIC && StrContains(sample, "player/headshot", true) != -1)) { return Plugin_Continue; } - for (int i = 0; i < numClients; i++) + int j = 0; + for(int i = 0; i < numClients; i++) { int client = clients[i]; - if (g_bStopWeaponSounds[client] || !IsClientConnected(client)) + if(!g_bStopWeaponSounds[client] && IsClientInGame(client)) { - // Remove the client from the array. - for (int j = i; j < numClients - 1; j++) { - clients[j] = clients[j + 1]; - } - - numClients--; - i--; + // Keep client. + clients[j] = clients[i]; + j++; } } + numClients = j; + return (numClients > 0) ? Plugin_Changed : Plugin_Stop; } public Action CSS_Hook_ShotgunShot(const char[] te_name, const int[] Players, int numClients, float delay) { - if (!g_bStopWeaponSoundsHooked) - { + if(!g_bStopWeaponSoundsHooked) return Plugin_Continue; - } // Check which clients need to be excluded. int[] newClients = new int[numClients]; int newTotal = 0; - for (int i = 0; i < numClients; i++) + for(int i = 0; i < numClients; i++) { - if (!g_bStopWeaponSounds[Players[i]]) + if(!g_bStopWeaponSounds[Players[i]]) { newClients[newTotal++] = Players[i]; } } - // No clients were excluded. - if (newTotal == numClients) + if(newTotal == numClients) { + // No clients were excluded. return Plugin_Continue; } - else if (newTotal == 0) + else if(newTotal == 0) { // All clients were excluded and there is no need to broadcast. return Plugin_Stop; @@ -650,10 +535,8 @@ public Action CSS_Hook_ShotgunShot(const char[] te_name, const int[] Players, in public Action Hook_ReloadEffect_CSS(UserMsg msg_id, BfRead msg, const int[] players, int playersNum, bool reliable, bool init) { - if (!g_bStopWeaponSoundsHooked) - { + if(!g_bStopWeaponSoundsHooked) return Plugin_Continue; - } int client = msg.ReadShort(); @@ -661,21 +544,21 @@ public Action Hook_ReloadEffect_CSS(UserMsg msg_id, BfRead msg, const int[] play int[] newClients = new int[playersNum]; int newTotal = 0; - for (int i = 0; i < playersNum; i++) + for(int i = 0; i < playersNum; i++) { int client_ = players[i]; - if (IsClientInGame(client_) && !g_bStopWeaponSounds[client_]) + if(IsClientInGame(client_) && !g_bStopWeaponSounds[client_]) { newClients[newTotal++] = client_; } } - if (newTotal == playersNum) + if(newTotal == playersNum) { // No clients were excluded. return Plugin_Continue; } - else if (newTotal == 0) + else if(newTotal == 0) { // All clients were excluded and there is no need to broadcast. return Plugin_Handled; @@ -685,7 +568,7 @@ public Action Hook_ReloadEffect_CSS(UserMsg msg_id, BfRead msg, const int[] play pack.WriteCell(client); pack.WriteCell(newTotal); - for (int i = 0; i < newTotal; i++) + for(int i = 0; i < newTotal; i++) { pack.WriteCell(newClients[i]); } @@ -697,10 +580,8 @@ public Action Hook_ReloadEffect_CSS(UserMsg msg_id, BfRead msg, const int[] play public Action Hook_ReloadEffect_CSGO(UserMsg msg_id, Protobuf msg, const int[] players, int playersNum, bool reliable, bool init) { - if (!g_bStopWeaponSoundsHooked) - { + if(!g_bStopWeaponSoundsHooked) return Plugin_Continue; - } int client = PbReadInt(msg, "entidx"); @@ -708,21 +589,21 @@ public Action Hook_ReloadEffect_CSGO(UserMsg msg_id, Protobuf msg, const int[] p int[] newClients = new int[playersNum]; int newTotal = 0; - for (int i = 0; i < playersNum; i++) + for(int i = 0; i < playersNum; i++) { int client_ = players[i]; - if (IsClientInGame(client_) && !g_bStopWeaponSounds[client_]) + if(IsClientInGame(client_) && !g_bStopWeaponSounds[client_]) { newClients[newTotal++] = client_; } } - if (newTotal == playersNum) + if(newTotal == playersNum) { // No clients were excluded. return Plugin_Continue; } - else if (newTotal == 0) + else if(newTotal == 0) { // All clients were excluded and there is no need to broadcast. return Plugin_Handled; @@ -732,7 +613,7 @@ public Action Hook_ReloadEffect_CSGO(UserMsg msg_id, Protobuf msg, const int[] p pack.WriteCell(client); pack.WriteCell(newTotal); - for (int i = 0; i < newTotal; i++) + for(int i = 0; i < newTotal; i++) { pack.WriteCell(newClients[i]); } @@ -751,10 +632,10 @@ public void OnReloadEffect(DataPack pack) int[] players = new int[newTotal]; int playersNum = 0; - for (int i = 0; i < newTotal; i++) + for(int i = 0; i < newTotal; i++) { int client_ = pack.ReadCell(); - if (IsClientInGame(client_)) + if(IsClientInGame(client_)) { players[playersNum++] = client_; } @@ -763,7 +644,7 @@ public void OnReloadEffect(DataPack pack) CloseHandle(pack); Handle ReloadEffect = StartMessage("ReloadEffect", players, playersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS); - if (GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf) + if(GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf) { PbSetInt(ReloadEffect, "entidx", client); } @@ -777,14 +658,23 @@ public void OnReloadEffect(DataPack pack) public Action Hook_AmbientSound(char sample[PLATFORM_MAX_PATH], int &entity, float &volume, int &level, int &pitch, float pos[3], int &flags, float &delay) { - if (g_bStopMapMusicHooked && IsEntityInMapMusicEntities(entity)) - { - DataPack datapack; - CreateDataTimer(0.0, Timer_DelayedStopForEntity, datapack, TIMER_FLAG_NO_MAPCHANGE); + if(!g_bStopMapMusicHooked) + return Plugin_Continue; - datapack.WriteString(sample); - datapack.WriteCell(entity); - } + // Music + if(sample[0] != '#') + return Plugin_Continue; + + char sEntity[16]; + IntToString(EntIndexToEntRef(entity), sEntity, sizeof(sEntity)); + + g_MapMusic.SetString(sEntity, sample, true); + + DataPack pack = new DataPack(); + pack.WriteString(sample); + pack.WriteCell(entity); + + RequestFrame(DelayedStopForEntity, pack); return Plugin_Continue; }