-
Notifications
You must be signed in to change notification settings - Fork 16
/
l4d_boss_percent.sp
183 lines (158 loc) · 4.52 KB
/
l4d_boss_percent.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#pragma semicolon 1
#include <sourcemod>
#include <l4d2_direct>
#define L4D2UTIL_STOCKS_ONLY
#include <l4d2util>
#undef REQUIRE_PLUGIN
#include <readyup>
public Plugin:myinfo =
{
name = "L4D2 Boss Flow Announce (Back to roots edition)",
author = "ProdigySim, Jahze, Stabby, CircleSquared, CanadaRox",
version = "1.6-btr",
description = "Announce boss flow percents!"
};
new iWitchPercent = 0;
new iTankPercent = 0;
new Handle:g_hVsBossBuffer;
new Handle:hCvarPrintToEveryone;
new Handle:hCvarTankPercent;
new Handle:hCvarWitchPercent;
new bool:readyUpIsAvailable;
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
MarkNativeAsOptional("AddStringToReadyFooter");
return APLRes_Success;
}
public OnPluginStart()
{
g_hVsBossBuffer = FindConVar("versus_boss_buffer");
hCvarPrintToEveryone = CreateConVar("l4d_global_percent", "1", "Display boss percentages to entire team when using commands", FCVAR_PLUGIN);
hCvarTankPercent = CreateConVar("l4d_tank_percent", "1", "Display Tank flow percentage in chat", FCVAR_PLUGIN);
hCvarWitchPercent = CreateConVar("l4d_witch_percent", "1", "Display Witch flow percentage in chat", FCVAR_PLUGIN);
RegConsoleCmd("sm_boss", BossCmd);
RegConsoleCmd("sm_tank", BossCmd);
RegConsoleCmd("sm_witch", BossCmd);
HookEvent("player_left_start_area", LeftStartAreaEvent, EventHookMode_PostNoCopy);
HookEvent("round_start", RoundStartEvent, EventHookMode_PostNoCopy);
}
public OnAllPluginsLoaded()
{
readyUpIsAvailable = LibraryExists("readyup");
}
public OnLibraryRemoved(const String:name[])
{
if (StrEqual(name, "readyup")) readyUpIsAvailable = false;
}
public OnLibraryAdded(const String:name[])
{
if (StrEqual(name, "readyup")) readyUpIsAvailable = true;
}
public LeftStartAreaEvent(Handle:event, const String:name[], bool:dontBroadcast)
{
if (!readyUpIsAvailable)
for (new client = 1; client <= MaxClients; client++)
if (IsClientConnected(client) && IsClientInGame(client))
PrintBossPercents(client);
}
public OnRoundIsLive()
{
for (new client = 1; client <= MaxClients; client++)
if (IsClientConnected(client) && IsClientInGame(client))
PrintBossPercents(client);
}
public RoundStartEvent(Handle:event, const String:name[], bool:dontBroadcast)
{
CreateTimer(5.0, SaveBossFlows);
}
public Action:SaveBossFlows(Handle:timer)
{
if (!InSecondHalfOfRound())
{
iWitchPercent = 0;
iTankPercent = 0;
if (L4D2Direct_GetVSWitchToSpawnThisRound(0))
{
iWitchPercent = RoundToNearest(GetWitchFlow(0)*100.0);
}
if (L4D2Direct_GetVSTankToSpawnThisRound(0))
{
iTankPercent = RoundToNearest(GetTankFlow(0)*100.0);
}
}
else
{
if (iWitchPercent != 0)
{
iWitchPercent = RoundToNearest(GetWitchFlow(1)*100.0);
}
if (iTankPercent != 0)
{
iTankPercent = RoundToNearest(GetTankFlow(1)*100.0);
}
}
if (readyUpIsAvailable)
{
decl String:readyString[65];
if (iWitchPercent && iTankPercent)
Format(readyString, sizeof(readyString), "Tank: %d%%, Witch: %d%%", iTankPercent, iWitchPercent);
else if (iTankPercent)
Format(readyString, sizeof(readyString), "Tank: %d%%, Witch: None", iTankPercent);
else if (iWitchPercent)
Format(readyString, sizeof(readyString), "Tank: None, Witch: %d%%", iWitchPercent);
else
Format(readyString, sizeof(readyString), "Tank: None, Witch: None");
AddStringToReadyFooter(readyString);
}
}
stock PrintBossPercents(client)
{
if(GetConVarBool(hCvarTankPercent))
{
if (iTankPercent)
PrintToChat(client, "\x01Tank spawn: [\x04%d%%\x01]", iTankPercent);
else
PrintToChat(client, "\x01Tank spawn: [\x04None\x01]");
}
if(GetConVarBool(hCvarWitchPercent))
{
if (iWitchPercent)
PrintToChat(client, "\x01Witch spawn: [\x04%d%%\x01]", iWitchPercent);
else
PrintToChat(client, "\x01Witch spawn: [\x04None\x01]");
}
}
public Action:BossCmd(client, args)
{
new L4D2_Team:iTeam = L4D2_Team:GetClientTeam(client);
if (iTeam == L4D2Team_Spectator)
{
PrintBossPercents(client);
return Plugin_Handled;
}
if (GetConVarBool(hCvarPrintToEveryone))
{
for (new i = 1; i <= MaxClients; i++)
{
if (IsClientConnected(i) && IsClientInGame(i) && L4D2_Team:GetClientTeam(i) == iTeam)
{
PrintBossPercents(i);
}
}
}
else
{
PrintBossPercents(client);
}
return Plugin_Handled;
}
stock Float:GetTankFlow(round)
{
return L4D2Direct_GetVSTankFlowPercent(round) -
( Float:GetConVarInt(g_hVsBossBuffer) / L4D2Direct_GetMapMaxFlowDistance() );
}
stock Float:GetWitchFlow(round)
{
return L4D2Direct_GetVSWitchFlowPercent(round) -
( Float:GetConVarInt(g_hVsBossBuffer) / L4D2Direct_GetMapMaxFlowDistance() );
}