1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#define PLUGIN_NAME "Stop Map Music"
#define PLUGIN_VERSION "1.0.0"
#define MAX_EDICTS 2048
new Float:g_fCmdTime[MAXPLAYERS+1];
new g_iSoundEnts[MAX_EDICTS];
new g_iNumSounds;
public Plugin:myinfo =
{
name = PLUGIN_NAME,
author = "GoD-Tony",
description = "Allows clients to stop ambient sounds played by the map",
version = PLUGIN_VERSION,
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
CreateConVar("sm_stopmusic_version", PLUGIN_VERSION, "Stop Map Music", FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_DONTRECORD);
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
RegConsoleCmd("sm_stopmusic", Command_StopMusic, "Stops map music");
}
public OnClientDisconnect_Post(client)
{
g_fCmdTime[client] = 0.0;
}
public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
// Ents are recreated every round.
g_iNumSounds = 0;
// Find all ambient sounds played by the map.
decl String:sSound[PLATFORM_MAX_PATH];
new entity = INVALID_ENT_REFERENCE;
while ((entity = FindEntityByClassname(entity, "ambient_generic")) != INVALID_ENT_REFERENCE)
{
GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
new len = strlen(sSound);
if (len > 4 && (StrEqual(sSound[len-3], "mp3") || StrEqual(sSound[len-3], "wav")))
{
g_iSoundEnts[g_iNumSounds++] = EntIndexToEntRef(entity);
}
}
}
public Action:Command_StopMusic(client, args)
{
// Prevent this command from being spammed.
if (!client || g_fCmdTime[client] > GetGameTime())
return Plugin_Handled;
g_fCmdTime[client] = GetGameTime() + 5.0;
PrintToChat(client, "[SM] Stopping map music...");
// Run StopSound on all ambient sounds in the map.
decl String:sSound[PLATFORM_MAX_PATH], entity;
for (new i = 0; i < g_iNumSounds; i++)
{
entity = EntRefToEntIndex(g_iSoundEnts[i]);
if (entity != INVALID_ENT_REFERENCE)
{
GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
Client_StopSound(client, entity, SNDCHAN_STATIC, sSound);
}
}
return Plugin_Handled;
}
/**
* Stops a sound for one client.
*
* @param client Client index.
* @param entity Entity index.
* @param channel Channel number.
* @param name Sound file name relative to the "sounds" folder.
* @noreturn
*/
stock Client_StopSound(client, entity, channel, const String:name[])
{
EmitSoundToClient(client, name, entity, channel, SNDLEVEL_NONE, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
}
|