-
Notifications
You must be signed in to change notification settings - Fork 5
/
bhud2.sp
354 lines (290 loc) · 10.3 KB
/
bhud2.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <clientprefs>
#define PLUGIN_VERSION "2.2"
#pragma newdecls required
Handle BossHud_Cookie = INVALID_HANDLE, HudSync = INVALID_HANDLE;
bool g_bStatus[MAXPLAYERS+1] = {false, ...};
int entityID[MAXPLAYERS+1] = -1;
ConVar g_cVHudPosition, g_cVHudColor, g_cVHudSymbols, g_cVUpdateTime, g_cVDisplayType, g_cVAdminOnly;
float HudPos[2];
int HudColor[3];
int UpdateTime;
int DisplayType;
int g_iTimer[MAXPLAYERS+1];
bool HudSymbols;
bool AdminOnly;
public Plugin myinfo = {
name = "BossHud",
author = "AntiTeal",
description = "",
version = PLUGIN_VERSION,
url = "antiteal.com"
};
public void OnPluginStart()
{
CreateConVar("sm_bhud_version", PLUGIN_VERSION, "BHud Version", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
BossHud_Cookie = RegClientCookie("bhud_cookie", "Status of BHud", CookieAccess_Private);
for(int i = 1; i <= MaxClients; i++)
{
if (!AreClientCookiesCached(i))
continue;
OnClientCookiesCached(i);
}
RegConsoleCmd("sm_bhud", Command_BHud, "Toggle BHud");
HookEntityOutput("func_physbox", "OnHealthChanged", OnDamage);
HookEntityOutput("func_physbox_multiplayer", "OnHealthChanged", OnDamage);
HookEntityOutput("func_breakable", "OnHealthChanged", OnDamage);
HookEntityOutput("math_counter", "OutValue", OnDamageCounter);
RegAdminCmd("sm_currenthp", Command_CHP, ADMFLAG_GENERIC, "See Current HP");
RegAdminCmd("sm_subtracthp", Command_SHP, ADMFLAG_GENERIC, "Subtract Current HP");
g_cVHudPosition = CreateConVar("sm_bhud_position", "-1.0 0.09", "The X and Y position for the hud.");
g_cVHudColor = CreateConVar("sm_bhud_color", "255 0 0", "RGB color value for the hud.");
g_cVHudSymbols = CreateConVar("sm_bhud_symbols", "1", "Determines whether >> and << are wrapped around the text.");
g_cVUpdateTime = CreateConVar("sm_bhud_updatetime", "3", "How long to update the client's hud with current health for.");
g_cVDisplayType = CreateConVar("sm_bhud_displaytype", "0", "Display type of HUD. (0 = game_text, 1 = center text)");
g_cVAdminOnly = CreateConVar("sm_bhud_adminonly", "0", "Determines whether BHUD is public or admin only. (0 = public, 1 = admins)");
g_cVHudPosition.AddChangeHook(ConVarChange);
g_cVHudColor.AddChangeHook(ConVarChange);
g_cVHudSymbols.AddChangeHook(ConVarChange);
g_cVUpdateTime.AddChangeHook(ConVarChange);
g_cVDisplayType.AddChangeHook(ConVarChange);
g_cVAdminOnly.AddChangeHook(ConVarChange);
AutoExecConfig(true);
GetConVars();
CreateTimer(0.25, UpdateHUD, _, TIMER_REPEAT);
}
public void OnClientConnected(int client)
{
g_iTimer[client] = 0;
}
public void ColorStringToArray(const char[] sColorString, int aColor[3])
{
char asColors[4][4];
ExplodeString(sColorString, " ", asColors, sizeof(asColors), sizeof(asColors[]));
aColor[0] = StringToInt(asColors[0]);
aColor[1] = StringToInt(asColors[1]);
aColor[2] = StringToInt(asColors[2]);
}
public void GetConVars()
{
char StringPos[2][8];
char PosValue[16];
g_cVHudPosition.GetString(PosValue, sizeof(PosValue));
ExplodeString(PosValue, " ", StringPos, sizeof(StringPos), sizeof(StringPos[]));
HudPos[0] = StringToFloat(StringPos[0]);
HudPos[1] = StringToFloat(StringPos[1]);
char ColorValue[64];
g_cVHudColor.GetString(ColorValue, sizeof(ColorValue));
ColorStringToArray(ColorValue, HudColor);
HudSymbols = g_cVHudSymbols.BoolValue;
AdminOnly = g_cVAdminOnly.BoolValue;
UpdateTime = g_cVUpdateTime.IntValue;
DisplayType = g_cVDisplayType.IntValue;
}
public void ConVarChange(ConVar convar, char[] oldValue, char[] newValue)
{
GetConVars();
}
public void OnMapStart()
{
HudSync = CreateHudSynchronizer();
}
public void OnMapEnd()
{
if(HudSync != INVALID_HANDLE)
{
CloseHandle(HudSync);
HudSync = INVALID_HANDLE;
}
}
public void OnClientCookiesCached(int client)
{
char sValue[8];
GetClientCookie(client, BossHud_Cookie, sValue, sizeof(sValue));
g_bStatus[client] = (sValue[0] != '\0' && StringToInt(sValue));
}
public Action Command_BHud(int client, int argc)
{
if(IsPlayerGenericAdmin(client) || !AdminOnly)
{
char sValue[8];
g_bStatus[client] = !g_bStatus[client];
PrintToChat(client, "[SM] BHud has been %s.", g_bStatus[client] ? "enabled" : "disabled");
Format(sValue, sizeof(sValue), "%i", g_bStatus[client]);
SetClientCookie(client, BossHud_Cookie, sValue);
}
else
PrintToChat(client, "[SM] You do not have access to this command.");
return Plugin_Handled;
}
bool IsValidClient(int client, bool nobots = true)
{
if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)))
{
return false;
}
return IsClientInGame(client);
}
public void SendHudMsg(int client, char[] szMessage)
{
if(!IsPlayerGenericAdmin(client) && AdminOnly)
return;
if(DisplayType == 0)
{
SetHudTextParams(HudPos[0], HudPos[1], 3.0, HudColor[0], HudColor[1], HudColor[2], 255, 0, 0.0, 0.0, 0.0);
ClearSyncHud(client, HudSync);
ShowSyncHudText(client, HudSync, szMessage);
}
else
{
int rgb;
rgb |= ((HudColor[0] & 0xFF) << 16);
rgb |= ((HudColor[1] & 0xFF) << 8 );
rgb |= ((HudColor[2] & 0xFF) << 0 );
PrintCenterText(client, "<font color='#%06X'>%s</font>", rgb, szMessage);
}
}
public void OnDamage(const char[] output, int caller, int activator, float delay)
{
if(IsValidClient(activator) && g_bStatus[activator] && (IsPlayerGenericAdmin(activator) || !AdminOnly))
{
char szName[64], szString[96];
GetEntPropString(caller, Prop_Data, "m_iName", szName, sizeof(szName));
if(strlen(szName) == 0)
Format(szName, sizeof(szName), "Health");
int health = GetEntProp(caller, Prop_Data, "m_iHealth");
if(health > 0 && health <= 900000)
{
if(HudSymbols)
Format(szString, sizeof(szString), ">> %s: %i HP <<", szName, health);
else
Format(szString, sizeof(szString), "%s: %i HP", szName, health);
SendHudMsg(activator, szString);
entityID[activator] = caller;
g_iTimer[activator] = GetTime();
}
}
}
public void OnDamageCounter(const char[] output, int caller, int activator, float delay)
{
if(IsValidClient(activator) && g_bStatus[activator] && (IsPlayerGenericAdmin(activator) || !AdminOnly))
{
char szName[64], szString[96];
GetEntPropString(caller, Prop_Data, "m_iName", szName, sizeof(szName));
if(strlen(szName) == 0)
Format(szName, sizeof(szName), "Health");
static int offset = -1;
if (offset == -1)
offset = FindDataMapInfo(caller, "m_OutValue");
int health = RoundFloat(GetEntDataFloat(caller, offset));
if(HudSymbols)
Format(szString, sizeof(szString), ">> %s: %i HP <<", szName, health);
else
Format(szString, sizeof(szString), "%s: %i HP", szName, health);
SendHudMsg(activator, szString);
entityID[activator] = caller;
g_iTimer[activator] = GetTime();
}
}
public Action Command_CHP(int client, int argc)
{
if(!IsValidEntity(entityID[client]))
{
PrintToChat(client, "[SM] Current entity is invalid (id %i)", entityID[client]);
return Plugin_Handled;
}
char szName[64], szType[64];
int health;
GetEntityClassname(entityID[client], szType, sizeof(szType));
GetEntPropString(entityID[client], Prop_Data, "m_iName", szName, sizeof(szName));
if(StrEqual(szType, "math_counter", false))
{
static int offset = -1;
if (offset == -1)
offset = FindDataMapInfo(entityID[client], "m_OutValue");
health = RoundFloat(GetEntDataFloat(entityID[client], offset));
}
else
{
health = GetEntProp(entityID[client], Prop_Data, "m_iHealth");
}
PrintToChat(client, "[SM] Entity %s %i (%s): %i HP", szName, entityID[client], szType, health);
return Plugin_Handled;
}
public Action Command_SHP(int client, int argc)
{
if(!IsValidEntity(entityID[client]))
{
PrintToChat(client, "[SM] Current entity is invalid (id %i)", entityID[client]);
return Plugin_Handled;
}
if (argc < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_subtracthp <health>");
return Plugin_Handled;
}
char szName[64], szType[64], arg[8];
int health;
GetEntityClassname(entityID[client], szType, sizeof(szType));
GetEntPropString(entityID[client], Prop_Data, "m_iName", szName, sizeof(szName));
GetCmdArg(1, arg, sizeof(arg));
SetVariantInt(StringToInt(arg));
if(StrEqual(szType, "math_counter", false))
{
static int offset = -1;
if (offset == -1)
offset = FindDataMapInfo(entityID[client], "m_OutValue");
health = RoundFloat(GetEntDataFloat(entityID[client], offset));
AcceptEntityInput(entityID[client], "Subtract", client, client);
PrintToChat(client, "[SM] %i health subtracted. (%i HP to %i HP)", StringToInt(arg), health, health - StringToInt(arg));
}
else
{
health = GetEntProp(entityID[client], Prop_Data, "m_iHealth");
AcceptEntityInput(entityID[client], "RemoveHealth", client, client);
PrintToChat(client, "[SM] %i health subtracted. (%i HP to %i HP)", StringToInt(arg), health, health - StringToInt(arg));
}
return Plugin_Handled;
}
public Action UpdateHUD(Handle timer, any client)
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i) && g_bStatus[i] && IsValidEntity(entityID[i]) && (IsPlayerGenericAdmin(i) || !AdminOnly))
{
int time = GetTime() - g_iTimer[i];
if (time > UpdateTime)
continue;
char szName[64], szType[64], szString[96];
int health;
GetEntityClassname(entityID[i], szType, sizeof(szType));
GetEntPropString(entityID[i], Prop_Data, "m_iName", szName, sizeof(szName));
if(strlen(szName) == 0)
Format(szName, sizeof(szName), "Health");
if(StrEqual(szType, "math_counter", false))
{
static int offset = -1;
if (offset == -1)
offset = FindDataMapInfo(entityID[i], "m_OutValue");
health = RoundFloat(GetEntDataFloat(entityID[i], offset));
}
else
{
health = GetEntProp(entityID[i], Prop_Data, "m_iHealth");
}
if(health <= 0 || health > 900000)
continue;
if(HudSymbols)
Format(szString, sizeof(szString), ">> %s: %i HP <<", szName, health);
else
Format(szString, sizeof(szString), "%s: %i HP", szName, health);
SendHudMsg(i, szString);
}
}
}
public bool IsPlayerGenericAdmin(int client)
{
return CheckCommandAccess(client, "generic_admin", ADMFLAG_GENERIC, false);
}