[StopSounds] Add !stopambient, stops all ambient_generic sounds.
This commit is contained in:
parent
d2bb72bb88
commit
a0c0f7e92d
@ -13,14 +13,17 @@ float g_fMusicVolume[MAXPLAYERS+1] = { 1.0, ... };
|
||||
|
||||
bool g_bStopWeaponSounds[MAXPLAYERS+1] = { false, ... };
|
||||
bool g_bStopMapMusic[MAXPLAYERS+1] = { false, ... };
|
||||
bool g_bStopMapAmbient[MAXPLAYERS+1] = { false, ... };
|
||||
|
||||
bool g_bStopWeaponSoundsHooked = false;
|
||||
bool g_bStopMapMusicHooked = false;
|
||||
|
||||
StringMap g_MapMusic;
|
||||
StringMap g_MapAmbient;
|
||||
|
||||
Handle g_hCookieStopSound = null;
|
||||
Handle g_hCookieStopMapMusic = null;
|
||||
Handle g_hCookieStopMapAmbient = null;
|
||||
Handle g_hCookieMusicVolume = null;
|
||||
|
||||
public Plugin myinfo =
|
||||
@ -50,6 +53,7 @@ public void OnPluginStart()
|
||||
LoadTranslations("common.phrases"); // For On/Off buttons in Cookies Menu
|
||||
|
||||
g_MapMusic = new StringMap();
|
||||
g_MapAmbient = new StringMap();
|
||||
|
||||
// Detect game and hook appropriate tempent.
|
||||
AddTempEntHook("Shotgun Shot", Hook_ShotgunShot);
|
||||
@ -66,11 +70,14 @@ public void OnPluginStart()
|
||||
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");
|
||||
RegConsoleCmd("sm_stopambient", Command_StopAmbient, "Toggle hearing map ambients");
|
||||
RegConsoleCmd("sm_ambient", Command_StopAmbient, "Toggle hearing map ambients");
|
||||
RegConsoleCmd("sm_volume", Command_Volume, "Change music volume");
|
||||
|
||||
// Cookies
|
||||
g_hCookieStopSound = RegClientCookie("weaponsound_blocked", "Are weapon sounds enabled", CookieAccess_Protected);
|
||||
g_hCookieStopMapMusic = RegClientCookie("mapmusic_blocked", "Are map music enabled", CookieAccess_Protected);
|
||||
g_hCookieStopMapAmbient = RegClientCookie("mapmusic_blocked_ambient", "Are map ambients enabled", CookieAccess_Protected);
|
||||
g_hCookieMusicVolume = RegClientCookie("mapmusic_volume", "The volume for map music", CookieAccess_Protected);
|
||||
|
||||
SetCookieMenuItem(CookieMenuHandler_StopSounds, 0, "Stop sounds");
|
||||
@ -149,11 +156,13 @@ public void OnPluginEnd()
|
||||
public void OnMapStart()
|
||||
{
|
||||
g_MapMusic.Clear();
|
||||
g_MapAmbient.Clear();
|
||||
}
|
||||
|
||||
public void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
|
||||
{
|
||||
g_MapMusic.Clear();
|
||||
g_MapAmbient.Clear();
|
||||
}
|
||||
|
||||
public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
|
||||
@ -168,6 +177,9 @@ public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast
|
||||
|
||||
if(g_bStopMapMusic[client])
|
||||
CPrintToChat(client, "%t %t", "Chat Prefix", "Map music disabled");
|
||||
|
||||
if(g_bStopMapAmbient[client])
|
||||
CPrintToChat(client, "%t %t", "Chat Prefix", "Map ambient disabled");
|
||||
}
|
||||
|
||||
public Action Command_StopSound(int client, int args)
|
||||
@ -221,6 +233,32 @@ public Action Command_StopMusic(int client, int args)
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action Command_StopAmbient(int client, int args)
|
||||
{
|
||||
if(client == 0)
|
||||
{
|
||||
ReplyToCommand(client, "[SM] Cannot use command from server console.");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
g_bStopMapAmbient[client] = !g_bStopMapAmbient[client];
|
||||
CheckMapMusicHooks();
|
||||
|
||||
if(g_bStopMapAmbient[client])
|
||||
{
|
||||
SetClientCookie(client, g_hCookieStopMapAmbient, "1");
|
||||
CReplyToCommand(client, "%t %t", "Chat Prefix", "Map ambient disabled");
|
||||
StopMapAmbient(client);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetClientCookie(client, g_hCookieStopMapAmbient, "");
|
||||
CReplyToCommand(client, "%t %t", "Chat Prefix", "Map ambient enabled");
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action Command_Volume(int client, int args)
|
||||
{
|
||||
if(client == 0)
|
||||
@ -259,6 +297,17 @@ public void OnClientCookiesCached(int client)
|
||||
else
|
||||
g_bStopMapMusic[client] = false;
|
||||
|
||||
// Map Ambient cookie
|
||||
GetClientCookie(client, g_hCookieStopMapAmbient, sBuffer, sizeof(sBuffer));
|
||||
|
||||
if(sBuffer[0] != '\0')
|
||||
{
|
||||
g_bStopMapAmbient[client] = true;
|
||||
g_bStopMapMusicHooked = true;
|
||||
}
|
||||
else
|
||||
g_bStopMapAmbient[client] = false;
|
||||
|
||||
// Music Volume cookie
|
||||
GetClientCookie(client, g_hCookieMusicVolume, sBuffer, sizeof(sBuffer));
|
||||
|
||||
@ -275,6 +324,8 @@ public void OnClientDisconnect(int client)
|
||||
{
|
||||
g_bStopWeaponSounds[client] = false;
|
||||
g_bStopMapMusic[client] = false;
|
||||
g_bStopMapAmbient[client] = false;
|
||||
g_fMusicVolume[client] = 1.0;
|
||||
|
||||
CheckWeaponSoundsHooks();
|
||||
CheckMapMusicHooks();
|
||||
@ -303,7 +354,7 @@ void CheckMapMusicHooks()
|
||||
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if(g_bStopMapMusic[i] || g_fMusicVolume[i] != 1.0)
|
||||
if(g_bStopMapMusic[i] || g_bStopMapAmbient[i] || g_fMusicVolume[i] != 1.0)
|
||||
{
|
||||
bShouldHook = true;
|
||||
break;
|
||||
@ -339,6 +390,31 @@ void StopMapMusic(int client)
|
||||
delete MapMusicSnap;
|
||||
}
|
||||
|
||||
void StopMapAmbient(int client)
|
||||
{
|
||||
int entity = INVALID_ENT_REFERENCE;
|
||||
|
||||
char sEntity[16];
|
||||
char sSample[PLATFORM_MAX_PATH];
|
||||
|
||||
StringMapSnapshot MapAmbientSnap = g_MapAmbient.Snapshot();
|
||||
for(int i = 0; i < MapAmbientSnap.Length; i++)
|
||||
{
|
||||
MapAmbientSnap.GetKey(i, sEntity, sizeof(sEntity));
|
||||
|
||||
if((entity = EntRefToEntIndex(StringToInt(sEntity))) == INVALID_ENT_REFERENCE)
|
||||
{
|
||||
g_MapAmbient.Remove(sEntity);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_MapAmbient.GetString(sEntity, sSample, sizeof(sSample));
|
||||
|
||||
EmitSoundToClient(client, sSample, entity, SNDCHAN_STATIC, SNDLEVEL_NONE, SND_STOPLOOPING, SNDVOL_NORMAL, SNDPITCH_NORMAL);
|
||||
}
|
||||
delete MapAmbientSnap;
|
||||
}
|
||||
|
||||
public void CookieMenuHandler_StopSounds(int client, CookieMenuAction action, any info, char[] buffer, int maxlen)
|
||||
{
|
||||
if(action == CookieMenuAction_DisplayOption)
|
||||
@ -362,7 +438,10 @@ void ShowStopSoundsSettingsMenu(int client)
|
||||
Format(sBuffer, sizeof(sBuffer), "%T%T", "Weapon Sounds", client, g_bStopWeaponSounds[client] ? "Disabled" : "Enabled", client);
|
||||
menu.AddItem("0", sBuffer);
|
||||
|
||||
Format(sBuffer, sizeof(sBuffer), "%T%T", "Map Sounds", client, g_bStopMapMusic[client] ? "Disabled" : "Enabled", client);
|
||||
Format(sBuffer, sizeof(sBuffer), "%T%T", "Map Music", client, g_bStopMapMusic[client] ? "Disabled" : "Enabled", client);
|
||||
menu.AddItem("1", sBuffer);
|
||||
|
||||
Format(sBuffer, sizeof(sBuffer), "%T%T", "Map Ambient", client, g_bStopMapAmbient[client] ? "Disabled" : "Enabled", client);
|
||||
menu.AddItem("1", sBuffer);
|
||||
|
||||
menu.ExitBackButton = true;
|
||||
@ -411,6 +490,23 @@ public int MenuHandler_StopSoundsSettings(Menu menu, MenuAction action, int clie
|
||||
CPrintToChat(client, "%t %t", "Chat Prefix", "Map music enabled");
|
||||
}
|
||||
}
|
||||
else if(selection == 2)
|
||||
{
|
||||
g_bStopMapAmbient[client] = !g_bStopMapAmbient[client];
|
||||
CheckMapMusicHooks();
|
||||
|
||||
if(g_bStopMapAmbient[client])
|
||||
{
|
||||
SetClientCookie(client, g_hCookieStopMapAmbient, "1");
|
||||
CPrintToChat(client, "%t %t", "Chat Prefix", "Map ambient disabled");
|
||||
StopMapAmbient(client);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetClientCookie(client, g_hCookieStopMapAmbient, "");
|
||||
CPrintToChat(client, "%t %t", "Chat Prefix", "Map ambient enabled");
|
||||
}
|
||||
}
|
||||
|
||||
ShowStopSoundsSettingsMenu(client);
|
||||
}
|
||||
@ -769,14 +865,18 @@ 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)
|
||||
{
|
||||
// Are we playing music?
|
||||
if(strncmp(sample, "music", 5, false) != 0 && strncmp(sample, "#", 1, false) != 0)
|
||||
return Plugin_Continue;
|
||||
|
||||
char sEntity[16];
|
||||
IntToString(EntIndexToEntRef(entity), sEntity, sizeof(sEntity));
|
||||
|
||||
g_MapMusic.SetString(sEntity, sample, true);
|
||||
// Are we playing music?
|
||||
bool bIsMusic = false;
|
||||
if(strncmp(sample, "#", 1, false) == 0 || strncmp(sample, "music", 5, false) == 0)
|
||||
{
|
||||
g_MapMusic.SetString(sEntity, sample, true);
|
||||
bIsMusic = true;
|
||||
}
|
||||
|
||||
g_MapAmbient.SetString(sEntity, sample, true);
|
||||
|
||||
if(!g_bStopMapMusicHooked)
|
||||
return Plugin_Continue;
|
||||
@ -788,7 +888,7 @@ public Action Hook_AmbientSound(char sample[PLATFORM_MAX_PATH], int &entity, flo
|
||||
// Starting sound..
|
||||
for(int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if (!IsClientInGame(client) || g_bStopMapMusic[client])
|
||||
if (!IsClientInGame(client) || (bIsMusic && g_bStopMapMusic[client]) || g_bStopMapAmbient[client])
|
||||
continue;
|
||||
|
||||
// Stop the old sound..
|
||||
@ -803,7 +903,7 @@ public Action Hook_AmbientSound(char sample[PLATFORM_MAX_PATH], int &entity, flo
|
||||
// Nothing special going on.. Pass it through..
|
||||
for(int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if (!IsClientInGame(client) || g_bStopMapMusic[client])
|
||||
if (!IsClientInGame(client) || (bIsMusic && g_bStopMapMusic[client]) || g_bStopMapAmbient[client])
|
||||
continue;
|
||||
|
||||
EmitSoundToClient(client, sample, entity, SNDCHAN_STATIC, level, flags, volume * g_fMusicVolume[client], pitch);
|
||||
|
@ -30,6 +30,16 @@
|
||||
"ru" "Музыка на картах {darkred}отключена{default}!"
|
||||
}
|
||||
|
||||
"Map ambient enabled"
|
||||
{
|
||||
"en" "Map ambient {green}enabled{default}!"
|
||||
}
|
||||
|
||||
"Map ambient disabled"
|
||||
{
|
||||
"en" "Map ambient {darkred}disabled{default}!"
|
||||
}
|
||||
|
||||
"Cookie Menu Stop Sounds"
|
||||
{
|
||||
"en" "Stop Sounds"
|
||||
@ -48,12 +58,17 @@
|
||||
"ru" "Звуки стрельбы"
|
||||
}
|
||||
|
||||
"Map Sounds"
|
||||
"Map Music"
|
||||
{
|
||||
"en" "Map music"
|
||||
"ru" "Музыка на картах"
|
||||
}
|
||||
|
||||
"Map Ambient"
|
||||
{
|
||||
"en" "Map ambient"
|
||||
}
|
||||
|
||||
"Disabled"
|
||||
{
|
||||
"en" ": Disabled"
|
||||
|
Loading…
Reference in New Issue
Block a user