- renamed Connect_MuteAmbient -> ConnectMuteAmbientTimer

- added generic MuteAmbientForClient for ambient blocking
- renamed Timer_MuteAmbient -> MuteAmbientTimer
- refactored ambient related functions
This commit is contained in:
not-log 2021-05-18 13:19:00 +03:00
parent c3ac10d709
commit 6c37c63d44

View File

@ -143,7 +143,7 @@ public void OnClientCookiesCached(int client)
if(gI_Settings[client] & Mute_AmbientSounds) if(gI_Settings[client] & Mute_AmbientSounds)
{ {
CreateTimer(1.0, Connect_MuteAmbient, GetClientSerial(client)); CreateTimer(1.0, ConnectMuteAmbientTimer, GetClientSerial(client));
} }
} }
//------------------------------------------------------------- //-------------------------------------------------------------
@ -429,13 +429,14 @@ public Action CSS_Hook_ShotgunShot(const char[] te_name, const int[] Players, in
return Plugin_Stop; return Plugin_Stop;
} }
public Action Connect_MuteAmbient(Handle hTimer, any data) public Action ConnectMuteAmbientTimer(Handle hTimer, any data)
{ {
int client = GetClientFromSerial(data); int client = GetClientFromSerial(data);
if(IsValidClient(client)) if(!IsValidClient(client))
{ {
char sSound[128]; return;
}
for(int i = 0; i < gA_PlayEverywhereAmbients.Length; i++) for(int i = 0; i < gA_PlayEverywhereAmbients.Length; i++)
{ {
@ -443,7 +444,20 @@ public Action Connect_MuteAmbient(Handle hTimer, any data)
if(entity != INVALID_ENT_REFERENCE) if(entity != INVALID_ENT_REFERENCE)
{ {
GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound)); MuteAmbientForClient(client, entity);
}
}
}
void MuteAmbientForClient(int client, int entity)
{
if(!IsValidEdict(entity) || entity == INVALID_ENT_REFERENCE)
{
return;
}
char sSound[PLATFORM_MAX_PATH];
GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, PLATFORM_MAX_PATH);
EmitSoundToClient(client, sSound, entity, SNDCHAN_STATIC, SNDLEVEL_NONE, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true); EmitSoundToClient(client, sSound, entity, SNDCHAN_STATIC, SNDLEVEL_NONE, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
if(gI_Settings[client] & Debug) if(gI_Settings[client] & Debug)
@ -451,33 +465,26 @@ public Action Connect_MuteAmbient(Handle hTimer, any data)
PrintToChat(client, "[Debug] Ambient Blocked (%s)", sSound); PrintToChat(client, "[Debug] Ambient Blocked (%s)", sSound);
} }
} }
}
}
}
public Action Timer_MuteAmbient(Handle hTimer, any data) public Action MuteAmbientTimer(Handle hTimer, any data)
{ {
int entity = EntRefToEntIndex(data); int entity = EntRefToEntIndex(data);
if(entity != INVALID_ENT_REFERENCE) if(!IsValidEdict(entity) || entity == INVALID_ENT_REFERENCE)
{ {
char sSound[128]; return;
}
for(int client = 1; client <= MaxClients; client++) for(int i = 1; i <= MaxClients; i++)
{ {
if(IsValidClient(client)) if(!IsValidClient(i))
{ {
if(gI_Settings[client] & Mute_AmbientSounds) continue;
{ }
GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
EmitSoundToClient(client, sSound, entity, SNDCHAN_STATIC, SNDLEVEL_NONE, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
if(gI_Settings[client] & Debug) if(gI_Settings[i] & Mute_AmbientSounds)
{ {
PrintToChat(client, "[Debug] Ambient Blocked (%s)", sSound); MuteAmbientForClient(i, entity);
}
}
}
} }
} }
} }
@ -489,7 +496,7 @@ public Action SoundHook_Ambient(char sample[PLATFORM_MAX_PATH], int &entity, flo
return Plugin_Continue; return Plugin_Continue;
} }
CreateTimer(0.1, Timer_MuteAmbient, EntIndexToEntRef(entity)); CreateTimer(0.1, MuteAmbientTimer, EntIndexToEntRef(entity));
return Plugin_Continue; return Plugin_Continue;
} }