-
Notifications
You must be signed in to change notification settings - Fork 1
/
jhud.sp
548 lines (460 loc) · 14.2 KB
/
jhud.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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
#pragma semicolon 1
#define PLUGIN_AUTHOR "Promises"
#define PLUGIN_VERSION "1.0"
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <sdkhooks>
#include <clientprefs>
#pragma newdecls required
EngineVersion g_Game;
#define BHOP_TIME 15
Handle g_hCookieEnabled;
Handle g_hCookieSpeed;
Handle g_hCookieGain;
Handle g_hCookieDisplayMode;
Handle g_hCookieDefault;
Handle g_hCookieDefaultColour;
Handle hText;
int g_iJump[MAXPLAYERS +1];
int g_iTicksOnGround[MAXPLAYERS +1];
int g_strafeTick[MAXPLAYERS +1];
int g_iDisplayMode[MAXPLAYERS + 1];
bool g_bEnabled[MAXPLAYERS +1];
bool g_bTouchesWall[MAXPLAYERS +1];
bool g_bSpeedColour[MAXPLAYERS + 1] = false;
bool g_bGainColour[MAXPLAYERS + 1] = false;
bool g_bDefaultColour[MAXPLAYERS + 1] = true;
float g_flRawGain[MAXPLAYERS +1];
public Plugin myinfo =
{
name = "Jhud",
author = PLUGIN_AUTHOR,
description = "SSJ in Hud",
version = PLUGIN_VERSION,
url = "https://steamcommunity.com/profiles/76561198075677363/"
};
public void OnAllPluginsLoaded()
{
HookEvent("player_jump", OnPlayerJump);
}
public void OnPluginStart()
{
g_Game = GetEngineVersion();
if(g_Game != Engine_CSGO && g_Game != Engine_CSS)
{
SetFailState("This plugin is for CSGO/CSS only.");
}
RegConsoleCmd("sm_jhud", SM_JHUD, "opens Jhud");
g_hCookieEnabled = RegClientCookie("jhud_enabled", "jhud_enabled", CookieAccess_Public);
g_hCookieSpeed = RegClientCookie("speed_enabled", "speed_enabled", CookieAccess_Public);
g_hCookieGain = RegClientCookie("gain_enabled", "gain_enabled", CookieAccess_Public);
g_hCookieDisplayMode = RegClientCookie("usagemode", "usagemode", CookieAccess_Public);
g_hCookieDefault = RegClientCookie("jhud_default", "jhud_default", CookieAccess_Public);
g_hCookieDefaultColour = RegClientCookie("colour_default", "colour_default", CookieAccess_Public);
for(int i = 1; i < MaxClients; i++)
{
if(IsClientInGame(i))
{
OnClientPutInServer(i);
OnClientCookiesCached(i);
}
}
hText = CreateHudSynchronizer();
}
public void OnClientCookiesCached(int client)
{
char sCookie[4];
GetClientCookie(client, g_hCookieDefault, sCookie, sizeof(sCookie));
if(StringToInt(sCookie) == 0)
{
SetCookie(client, g_hCookieEnabled, false);
SetCookie(client, g_hCookieSpeed, false);
SetCookie(client, g_hCookieGain, false);
SetCookie(client, g_hCookieDisplayMode, 0);
SetCookie(client, g_hCookieDefaultColour, true);
SetCookie(client, g_hCookieDefault, true);
}
g_bEnabled[client] = GetCookie(client, g_hCookieEnabled);
g_bSpeedColour[client] = GetCookie(client, g_hCookieSpeed);
g_bGainColour[client] = GetCookie(client, g_hCookieGain);
g_bDefaultColour[client] = GetCookie(client, g_hCookieDefaultColour);
GetClientCookie(client, g_hCookieDisplayMode, sCookie, sizeof(sCookie));
g_iDisplayMode[client] = StringToInt(sCookie);
}
public void OnClientPutInServer(int client)
{
g_iJump[client] = 0;
g_strafeTick[client] = 0;
g_flRawGain[client] = 0.0;
g_iTicksOnGround[client] = 0;
SDKHook(client, SDKHook_Touch, onTouch);
}
public void OnClientDisconnect(int client)
{
g_bEnabled[client] = false;
g_bSpeedColour[client] = false;
g_bGainColour[client] = false;
}
public Action SM_JHUD(int client, int args)
{
if(client == 0)
{
ReplyToCommand(client, "[SM] This command can only used ingame");
return Plugin_Handled;
}
else if(IsValidClient(client))
{
JhudMenu(client);
}
else
{
return Plugin_Handled;
}
return Plugin_Handled;
}
void JhudMenu(int client)
{
char sBuffer[128];
Panel panel = CreatePanel(); // panel cuz menu has no drawtext, and preview with numbers? hell na
panel.SetTitle("Jhud Menu");
panel.DrawText(" ");
FormatEx(sBuffer, sizeof(sBuffer), "Jhud - [%s]", (g_bEnabled[client]) ? "x" : " ");
panel.DrawItem(sBuffer);
panel.DrawText(" ");
//Display Mode preview
if(g_iDisplayMode[client] == 0)
{
FormatEx(sBuffer, sizeof(sBuffer), "----------------------------\n jump: ssj\n----------------------------");
}
else if (g_iDisplayMode[client] == 1)
{
FormatEx(sBuffer, sizeof(sBuffer), "----------------------------\n jump: gain %\n----------------------------");
}
else if (g_iDisplayMode[client] == 2)
{
FormatEx(sBuffer, sizeof(sBuffer), "----------------------------\n jump: ssj - gain %\n----------------------------");
}
panel.DrawText(sBuffer);
FormatEx(sBuffer, sizeof(sBuffer), "%s", g_iDisplayMode[client] == 0 ? "Mode: default" : (g_iDisplayMode[client] == 1 ? "Mode: gain" : "Mode: vel-gain"));
panel.DrawItem(sBuffer);
panel.DrawText(" ");
FormatEx(sBuffer, sizeof(sBuffer), "Default Colour - [%s]", (g_bDefaultColour[client]) ? "x" : " ");
panel.DrawItem(sBuffer);
FormatEx(sBuffer, sizeof(sBuffer), "Velo Colour - [%s]", (g_bSpeedColour[client]) ? "x" : " ");
panel.DrawItem(sBuffer);
FormatEx(sBuffer, sizeof(sBuffer), "Gain Colour - [%s]", (g_bGainColour[client]) ? "x" : " ");
panel.DrawItem(sBuffer);
panel.DrawItem("", ITEMDRAW_SPACER);
panel.CurrentKey = 10;
//resize menu with " "
panel.DrawItem("Exit ", ITEMDRAW_CONTROL);
panel.Send(client, menu_Jhud, 0);
CloseHandle(panel);
}
public int menu_Jhud(Handle menu, MenuAction action, int client, int item)
{
switch (action)
{
case MenuAction_Select:
{
switch (item)
{
case 1: //Jhud on/off
{
g_bEnabled[client] = !g_bEnabled[client];
SetCookie(client, g_hCookieEnabled, g_bEnabled[client]);
JhudMenu(client);
}
case 2: //switch modes
{
g_iDisplayMode[client] = (g_iDisplayMode[client] + 1) % 3;
SetCookie(client, g_hCookieDisplayMode, g_iDisplayMode[client]);
JhudMenu(client);
}
case 3:
{
if (g_bGainColour[client] || g_bSpeedColour[client])
{
g_bGainColour[client] = false;
g_bSpeedColour[client] = false;
SetCookie(client, g_hCookieSpeed, g_bSpeedColour[client]);
SetCookie(client, g_hCookieGain, g_bGainColour[client]);
g_bDefaultColour[client] = !g_bDefaultColour[client];
SetCookie(client, g_hCookieDefaultColour, g_bDefaultColour[client]);
}
JhudMenu(client);
}
case 4:
{
if (g_bGainColour[client] || g_bDefaultColour[client])
{
g_bGainColour[client] = false;
g_bDefaultColour[client] = false;
SetCookie(client, g_hCookieGain, g_bGainColour[client]);
SetCookie(client, g_hCookieDefaultColour, g_bDefaultColour[client]);
g_bSpeedColour[client] = !g_bSpeedColour[client];
SetCookie(client, g_hCookieSpeed, g_bSpeedColour[client]);
}
JhudMenu(client);
}
case 5:
{
if (g_bSpeedColour[client] || g_bDefaultColour[client])
{
g_bSpeedColour[client] = false;
g_bDefaultColour[client] = false;
SetCookie(client, g_hCookieSpeed, g_bSpeedColour[client]);
SetCookie(client, g_hCookieDefaultColour, g_bDefaultColour[client]);
g_bGainColour[client] = !g_bGainColour[client];
SetCookie(client, g_hCookieGain, g_bGainColour[client]);
}
JhudMenu(client);
}
}
}
}
}
public Action onTouch(int client, int entity)
{
if(!(GetEntProp(entity, Prop_Data, "m_usSolidFlags") & 28))
g_bTouchesWall[client] = true;
}
public Action OnPlayerJump(Handle event, const char[] name, bool dontBroadcast)
{
int userid = GetEventInt(event, "userid");
int client = GetClientOfUserId(userid);
if (IsFakeClient(client))
return;
if (g_iJump[client] && g_strafeTick[client] <= 0)
return;
g_iJump[client]++;
for (int i = 1; i < MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i) && ((!IsPlayerAlive(i) && GetEntPropEnt(i, Prop_Data, "m_hObserverTarget") == client && GetEntProp(i, Prop_Data, "m_iObserverMode") != 7 && g_bEnabled[i]) || (i == client && g_bEnabled[i] )))
{
JHUD_Print(i, client);
}
}
g_flRawGain[client] = 0.0;
g_strafeTick[client] = 0;
}
void JHUD_Get(int client, float vel[3], float angles[3])
{
float velocity[3];
GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", velocity);
float gaincoeff;
g_strafeTick[client]++;
float fore[3], side[3], wishvel[3], wishdir[3];
float wishspeed, wishspd, currentgain;
GetAngleVectors(angles, fore, side, NULL_VECTOR);
fore[2] = 0.0;
side[2] = 0.0;
NormalizeVector(fore, fore);
NormalizeVector(side, side);
for (int i = 0; i < 2; i++)
wishvel[i] = fore[i] * vel[0] + side[i] * vel[1];
wishspeed = NormalizeVector(wishvel, wishdir);
if (wishspeed > GetEntPropFloat(client, Prop_Send, "m_flMaxspeed") && GetEntPropFloat(client, Prop_Send, "m_flMaxspeed") != 0.0)
wishspeed = GetEntPropFloat(client, Prop_Send, "m_flMaxspeed");
if (wishspeed)
{
wishspd = (wishspeed > 30.0) ? 30.0 : wishspeed;
currentgain = GetVectorDotProduct(velocity, wishdir);
if(currentgain < 30.0)
{
gaincoeff = (wishspd - FloatAbs(currentgain)) / wishspd;
}
if(g_bTouchesWall[client] && gaincoeff > 0.5)
{
gaincoeff -= 1;
gaincoeff = FloatAbs(gaincoeff);
}
g_flRawGain[client] += gaincoeff;
}
}
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon)
{
if (IsFakeClient(client))
return Plugin_Continue;
if (GetEntityFlags(client) & FL_ONGROUND)
{
if (g_iTicksOnGround[client] & BHOP_TIME)
{
g_iJump[client] = 0;
g_strafeTick[client] = 0;
g_flRawGain[client] = 0.0;
}
g_iTicksOnGround[client]++;
if(buttons & IN_JUMP && g_iTicksOnGround[client] == 1)
{
JHUD_Get(client, vel, angles);
g_iTicksOnGround[client] = 0;
}
}
else
{
if(GetEntityMoveType(client) != MOVETYPE_NONE && GetEntityMoveType(client) != MOVETYPE_NOCLIP && GetEntityMoveType(client) != MOVETYPE_LADDER && GetEntProp(client, Prop_Data, "m_nWaterLevel") < 2)
{
JHUD_Get(client, vel, angles);
}
g_iTicksOnGround[client] = 0;
}
g_bTouchesWall[client] = false;
return Plugin_Continue;
}
void JHUD_Print(int client, int target)
{
float velocity[3], origin[3];
GetEntPropVector(target, Prop_Data, "m_vecAbsVelocity", velocity);
GetClientAbsOrigin(target, origin);
velocity[2] = 0.0;
float coeffsum = g_flRawGain[target];
coeffsum /= g_strafeTick[target];
coeffsum *= 100.0;
coeffsum = RoundToFloor(coeffsum * 100.0 + 0.5) / 100.0;
char JHUDText[255];
//jump # - speed
if(g_iDisplayMode[client] == 0)
{
if((g_iJump[target] <= 6 ) || g_iJump[target] == 16 )
{
FormatEx(JHUDText, sizeof(JHUDText), "%i: %i", g_iJump[target], RoundToFloor(GetVectorLength(velocity)));
}
else
{
FormatEx(JHUDText, sizeof(JHUDText), "%.0f%", coeffsum);
}
}
//jump# - gain %
else if(g_iDisplayMode[client] == 1)
{
if((g_iJump[target] == 1 ) || g_iJump[target] == 16 )
{
FormatEx(JHUDText, sizeof(JHUDText), "%i: %i", g_iJump[target], RoundToFloor(GetVectorLength(velocity)));
}
else
{
FormatEx(JHUDText, sizeof(JHUDText), "%i: %.0f%", g_iJump[target], coeffsum);
}
}
//jump # - ssj - gain %
else if(g_iDisplayMode[client] == 2)
{
if(g_iJump[target] == 1 )
{
FormatEx(JHUDText, sizeof(JHUDText), "%i: %i", g_iJump[target], RoundToFloor(GetVectorLength(velocity)));
}
else
{
FormatEx(JHUDText, sizeof(JHUDText), "%i: %i - %0.f%", g_iJump[target], RoundToFloor(GetVectorLength(velocity)), coeffsum);
}
}
int newvelocity = RoundToFloor(GetVectorLength(velocity));
// get the text color
int r, g, b;
if(g_bDefaultColour[client])
{
if(g_iJump[target] <= 6 || g_iJump[target] == 16)
{
GetSpeedColour(g_iJump[target], newvelocity, r, g, b);
}
else
{
GetGainColour(coeffsum, r, g, b);
}
}
else if(g_bSpeedColour[client])
{
//Use speed as colour
GetSpeedColour(g_iJump[target], newvelocity, r, g, b);
}
else if(g_bGainColour[client])
{
//Use gain as colour
if(g_iJump[target] == 1)
{
GetSpeedColour(g_iJump[target], newvelocity, r, g, b);
}
else
{
GetGainColour(coeffsum, r, g, b);
}
}
// print the text
if(hText != INVALID_HANDLE)
{
SetHudTextParams(-1.0, -1.0, 1.0, r, g, b, 255);
ShowSyncHudText(client, hText, JHUDText);
}
}
void GetGainColour(float gain, int &r, int &g, int &b)
{
if (gain < 60.00)
{
r = 255;
g = 0; //red
b = 0;
}
else if (60.00 <= gain < 70.00)
{
r = 255;
g = 126; //orange
b = 0;
}
else if (70.00 <= gain < 80.00)
{
r = 0;
g = 255; //green
b = 0;
}
else
{
r = 0;
g = 255; //blue
b = 255;
}
}
void GetSpeedColour(int jump, int speed, int &r, int &g, int &b)
{
if ((jump == 1 && 280 <= speed < 282) || (jump == 2 && 366 <= speed < 370) || (jump == 3 && 438 <= speed < 442) || (jump == 4 && 500 <= speed < 505) || (jump == 5 && 555 <= speed < 560) || (jump == 6 && 605 <= speed < 610) || (jump == 16 && 965 <= speed < 980))
{
r = 255;
g = 126; //orange
b = 0;
}
else if ((jump == 1 && 282 <= speed < 287) || (jump == 2 && 370 <= speed < 375) || (jump == 3 && 442 <= speed < 450) || (jump == 4 && 505 <= speed < 515) || (jump == 5 && 560 <= speed < 570) || (jump == 6 && 610 <= speed < 620) || (jump == 16 && 980 <= speed < 1000))
{
r = 0;
g = 255; //green
b = 0;
}
else if ((jump == 1 && speed >= 287) || (jump == 2 && speed >= 375 ) || (jump == 3 && speed >= 450) || (jump == 4 && speed >= 515) || (jump == 5 && speed >= 570) || (jump == 6 && speed >= 620) || (jump == 16 && speed >= 1000))
{
r = 0;
g = 255; //blue
b = 255;
}
else
{
r = 255;
g = 0; //red
b = 0;
}
}
stock bool GetCookie(int client, Handle cookie)
{
char sValue[8];
GetClientCookie(client, cookie, sValue, sizeof(sValue));
return (sValue[0] != '\0' && StringToInt(sValue));
}
stock void SetCookie(int client, Handle hCookie, int n)
{
char strCookie[64];
IntToString(n, strCookie, sizeof(strCookie));
SetClientCookie(client, hCookie, strCookie);
}
stock bool IsValidClient(int client, bool bAlive = false)
{
return (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsClientSourceTV(client) && (!bAlive || IsPlayerAlive(client)));
}