forked from zonde306/l4d2sc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathl4d2_bgm.sp
149 lines (122 loc) · 3.21 KB
/
l4d2_bgm.sp
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <left4dhooks>
public Plugin myinfo =
{
name = "背景音乐",
author = "zonde306",
description = "",
version = "0.1",
url = ""
};
bool g_bLateLoad = false;
ArrayList g_TankBGM, g_WitchBGM;
char g_szBGMPlaying[PLATFORM_MAX_PATH];
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
g_bLateLoad = late;
return APLRes_Success;
}
public void OnPluginStart()
{
g_TankBGM = CreateArray(PLATFORM_MAX_PATH);
g_WitchBGM = CreateArray(PLATFORM_MAX_PATH);
HookEvent("tank_spawn", Event_TankSpawn);
HookEvent("tank_killed", Event_TankKilled);
HookEvent("zombie_ignited", Event_ZombieIgnited);
// HookEvent("witch_spawn", Event_WitchSpawn);
HookEvent("witch_killed", Event_WitchKilled);
HookEvent("witch_harasser_set", Event_WitchAngry);
if(g_bLateLoad && IsServerProcessing())
{
}
}
void LoadPreset()
{
char buffer[PLATFORM_MAX_PATH];
BuildPath(Path_SM, buffer, sizeof(buffer), "data/tank_bgm.txt");
if(FileExists(buffer))
{
File file = OpenFile(buffer, "rt");
g_TankBGM.Clear();
while(!file.EndOfFile())
{
file.ReadLine(buffer, sizeof(buffer));
g_TankBGM.PushString(buffer);
}
delete file;
}
BuildPath(Path_SM, buffer, sizeof(buffer), "data/witch_bgm.txt");
if(FileExists(buffer))
{
File file = OpenFile(buffer, "rt");
g_WitchBGM.Clear();
while(!file.EndOfFile())
{
file.ReadLine(buffer, sizeof(buffer));
g_WitchBGM.PushString(buffer);
}
delete file;
}
}
public void OnMapStart()
{
LoadPreset();
char buffer[PLATFORM_MAX_PATH];
for(int i = 0; i < g_TankBGM.Length; ++i)
{
g_TankBGM.GetString(i, buffer, sizeof(buffer));
AddFileToDownloadsTable(buffer);
}
for(int i = 0; i < g_WitchBGM.Length; ++i)
{
g_WitchBGM.GetString(i, buffer, sizeof(buffer));
AddFileToDownloadsTable(buffer);
}
}
public void Event_TankSpawn(Event event, const char[] eventName, bool dontBoardcast)
{
if(g_TankBGM.Length <= 0)
return;
char sound[PLATFORM_MAX_PATH];
g_TankBGM.GetString(GetRandomInt(0, g_TankBGM.Length - 1), sound, sizeof(sound));
for(int i = 1; i <= MaxClients; ++i)
{
if(!IsClientInGame(i) || IsFakeClient(i) || GetClientTeam(i) != 2)
continue;
L4D_StopMusic(i, "Event.Tank");
L4D_StopMusic(i, "Event.TankMidpoint");
L4D_StopMusic(i, "Event.TankBrothers");
L4D_StopMusic(i, "C2M5.RidinTank1");
L4D_StopMusic(i, "C2M5.RidinTank2");
L4D_StopMusic(i, "C2M5.BadManTank1");
L4D_StopMusic(i, "C2M5.BadManTank2");
}
}
public void Event_WitchAngry(Event event, const char[] eventName, bool dontBoardcast)
{
if(g_WitchBGM.Length <= 0)
return;
for(int i = 1; i <= MaxClients; ++i)
{
if(!IsClientInGame(i) || IsFakeClient(i) || GetClientTeam(i) != 2)
continue;
L4D_StopMusic(i, "Event.WitchAttack");
}
}
public void Event_ZombieIgnited(Event event, const char[] eventName, bool dontBoardcast)
{
if(g_WitchBGM.Length <= 0)
return;
char victimname[16];
event.GetString("victimname", victimname, sizeof(victimname));
if(strcmp(victimname, "Witch", false))
return;
for(int i = 1; i <= MaxClients; ++i)
{
if(!IsClientInGame(i) || IsFakeClient(i) || GetClientTeam(i) != 2)
continue;
L4D_StopMusic(i, "Event.WitchBurning");
}
}