-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexd_KeyPad.sp
More file actions
417 lines (340 loc) · 13.1 KB
/
exd_KeyPad.sp
File metadata and controls
417 lines (340 loc) · 13.1 KB
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
// Based on JHUD and Sikarii-movementhud
#include <sdktools>
#include <sourcemod>
#include <clientprefs>
#include <DynamicChannels>
#include <entity_prop_stocks>
#define PLUGIN_VERSION "1.02"
#define PLUGIN_URL "https://github.com/exd02/HUDInfo"
#define GROUND_TICK_TIME 15
public Plugin myinfo =
{
name = "HUDInfo",
author = "exd",
description = "Prints Target key on screen and the Speed/gain",
version = PLUGIN_VERSION,
url = PLUGIN_URL
};
// Global
int gI_HopCount[MAXPLAYERS + 1];
int gI_TicksOnGround[MAXPLAYERS + 1];
int gI_StrafeTick[MAXPLAYERS + 1];
int gI_SyncedTick[MAXPLAYERS + 1];
int gI_TextRGB[MAXPLAYERS + 1][3];
Handle gH_KeyHUDCookie;
Handle gH_HUDSpeed;
float gF_OldAngle[MAXPLAYERS + 1];
float gF_RawGain[MAXPLAYERS + 1];
float gF_Trajectory[MAXPLAYERS + 1];
float gF_TraveledDistance[MAXPLAYERS + 1][3];
bool gB_HUDKey[MAXPLAYERS + 1];
bool gB_HUDSpeed[MAXPLAYERS + 1];
char gS_SpeedText[MAXPLAYERS + 1][32];
public void OnPluginStart()
{
gH_KeyHUDCookie = RegClientCookie("bKeyHUDCookie", "bKeyHUDCookie", CookieAccess_Protected);
gH_HUDSpeed = RegClientCookie("bGainHUDCookie", "bGainHUDCookie", CookieAccess_Protected);
RegConsoleCmd("sm_hudkeypad", Command_HUDKeyPad, "Toggles ON KeyPad");
RegConsoleCmd("sm_keypad", Command_HUDKeyPad, "Toggles ON KeyPad");
RegConsoleCmd("sm_keys", Command_HUDKeyPad, "Toggles ON KeyPad");
RegConsoleCmd("sm_jhud", Command_HUDSpeed, "Toggles ON SSJHUD");
RegConsoleCmd("sm_jumphud", Command_HUDSpeed, "Toggles ON SSJHUD");
RegConsoleCmd("sm_ssjhud", Command_HUDSpeed, "Toggles ON SSJHUD");
HookEvent("player_jump", Event_PlayerJump);
}
public Action Command_HUDKeyPad(int client, any args)
{
if (client != 0)
{
gB_HUDKey[client] = !gB_HUDKey[client];
SetClientCookieBool(client, gH_KeyHUDCookie, gB_HUDKey[client]);
}
return Plugin_Handled;
}
public Action Command_HUDSpeed(int client, any args)
{
if (client != 0)
{
gB_HUDSpeed[client] = !gB_HUDSpeed[client];
SetClientCookieBool(client, gH_HUDSpeed, gB_HUDSpeed[client]);
}
return Plugin_Handled;
}
public void OnClientCookiesCached(int client)
{
gB_HUDKey[client] = GetClientCookieBool(client, gH_KeyHUDCookie);
gB_HUDSpeed[client] = GetClientCookieBool(client, gH_HUDSpeed);
}
public void OnClientPostAdminCheck(int client)
{
gI_HopCount[client] = 0;
gI_StrafeTick[client] = 0;
gI_SyncedTick[client] = 0;
gF_RawGain[client] = 0.0;
gF_Trajectory[client] = 0.0;
gF_TraveledDistance[client] = NULL_VECTOR;
gI_TicksOnGround[client] = 0;
}
public Action Event_PlayerJump(Event event, const char[] name, bool dontBroadcast)
{
// Get the client from the event
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if((gI_HopCount[client] && gI_StrafeTick[client] <= 0) || (IsFakeClient(client))) return;
gI_HopCount[client] ++;
int target = client;
// Here we print to the player that is jumping
if (IsPlayerAlive(client) && gB_HUDSpeed[client]) GetPlayerSpeed(client, target);
// Here we print to the player that is spectating the client
for(int i=1; i<MaxClients; i++)
{
if(IsClientInGame(i) && !IsPlayerAlive(i) && gB_HUDSpeed[i] && GetEntProp(i, Prop_Data, "m_iObserverMode") != 7)
{
target = GetEntPropEnt(i, Prop_Data, "m_hObserverTarget");
GetPlayerSpeed(client, target);
}
}
gF_RawGain[client] = 0.0;
gI_StrafeTick[client] = 0;
gI_SyncedTick[client] = 0;
gF_Trajectory[client] = 0.0;
gF_TraveledDistance[client] = NULL_VECTOR;
}
/* The client is the player that we gonna print the HUD
The target is the player that's jumping */
public void GetPlayerSpeed(int client, int target)
{
// ========================================== Get and convert the Speed ========================================== //
float fVelocity[3];
GetEntPropVector(target, Prop_Data, "m_vecVelocity", fVelocity);
int iPlayerSpeed = RoundToFloor(GetVectorLength(fVelocity));
// =============================================================================================================== //
// ================================== Calculate the RGB based in GAIN% OR SSJ ==================================== //
int r = 0; int rPercentage;
int g = 0; int gPercentage;
int b = 0; int bPercentage;
char sTargetSpeed[16];
int JumpNumber = gI_HopCount[target] - 1;
if (gI_HopCount[target] <= 6)
{
int SSJ[6][3];
// SSJ [J][C] J Represents the Jump index and C the color.
SSJ[0][0] = 280;
SSJ[1][0] = 360;
SSJ[2][0] = 440;
SSJ[3][0] = 520;
SSJ[4][0] = 580;
SSJ[5][0] = 600;
//
SSJ[0][1] = 281;
SSJ[1][1] = 380;
SSJ[2][1] = 460;
SSJ[3][1] = 530;
SSJ[4][1] = 600;
SSJ[5][1] = 660;
//
SSJ[0][2] = 286;
SSJ[1][2] = 390;
SSJ[2][2] = 480;
SSJ[3][2] = 560;
SSJ[4][2] = 620;
SSJ[5][2] = 680;
for (int i=0; i<6; i++)
{
if (iPlayerSpeed <= SSJ[JumpNumber][0])
{
rPercentage = 100; gPercentage = 0; bPercentage = 0;
}
else if (iPlayerSpeed <= SSJ[JumpNumber][1])
{
rPercentage = 90; gPercentage = 65; bPercentage = 0;
}
else if (iPlayerSpeed <= SSJ[JumpNumber][2])
{
rPercentage = 0; gPercentage = 90; bPercentage = 15;
}
else
{
rPercentage = 0; gPercentage = 90; bPercentage = 90;
}
}
Format(sTargetSpeed, sizeof(sTargetSpeed), "[%i] - %i", gI_HopCount[target], iPlayerSpeed);
}
else
{
float coeffsum = gF_RawGain[target];
coeffsum /= gI_StrafeTick[target];
coeffsum *= 100.0;
coeffsum = RoundToFloor(coeffsum * 100.0 + 0.5) / 100.0;
int percentage = RoundToFloor(coeffsum);
if (percentage < 0) percentage = 0;
else if (percentage > 100) percentage = 100;
rPercentage = 100 - percentage;
gPercentage = percentage;
if (percentage > 80)
{
rPercentage = 0;
bPercentage = (percentage-80)*5;
if (bPercentage<50) bPercentage = 50;
}
Format(sTargetSpeed, sizeof(sTargetSpeed), "%.02f%%", coeffsum);
}
r = RoundToFloor(2.55*rPercentage);
g = RoundToFloor(2.55*gPercentage);
b = RoundToFloor(2.55*bPercentage);
// ================================================================================================================ //
// ============================================== Print SSJ or %Gain ============================================== //
gI_TextRGB [client] [0] = r;
gI_TextRGB [client] [1] = g;
gI_TextRGB [client] [2] = b;
gS_SpeedText [client] = sTargetSpeed;
// =============================================================================================================== //
}
public void PrintTheText(float x, float y, int client, int r, int g, int b, char[] sMsg, int group)
{
SetHudTextParams(x, y, 0.5, r, g, b, 255, 0, 0.0, 0.0, 0.0);
ShowHudText(client, GetDynamicChannel(group), "%s", sMsg);
}
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2])
{
if(IsFakeClient(client)) return Plugin_Continue;
if(GetEntityFlags(client) & FL_ONGROUND)
{
if(gI_TicksOnGround[client] > GROUND_TICK_TIME)
{
gI_HopCount[client] = 0;
gI_StrafeTick[client] = 0;
gI_SyncedTick[client] = 0;
gF_RawGain[client] = 0.0;
gF_Trajectory[client] = 0.0;
gF_TraveledDistance[client] = NULL_VECTOR;
}
gI_TicksOnGround[client]++;
}
else
{
if(GetEntityMoveType(client) != MOVETYPE_NONE && GetEntityMoveType(client) != MOVETYPE_NOCLIP && GetEntityMoveType(client) != MOVETYPE_LADDER && GetEntProp(client, Prop_Data, "m_nWaterLevel") < 2)
{
GetStats(client, vel, angles);
}
gI_TicksOnGround[client] = 0;
if (gB_HUDSpeed[client]) PrintTheText(-1.0, -0.65, client, gI_TextRGB[client][0], gI_TextRGB[client][1], gI_TextRGB[client][2], gS_SpeedText[client],0);
}
// We need to run the function, because the client target can be a player that he is watching
// Only draw huds to real players
if (gB_HUDKey[client] && !IsFakeClient(client)) DisplayKeyPad(client);
return Plugin_Continue;
}
void GetStats(int client, float vel[3], float angles[3])
{
float velocity[3];
GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", velocity);
float gaincoeff;
gI_StrafeTick[client]++;
gF_TraveledDistance[client][0] += velocity[0] * GetTickInterval() * GetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue");
gF_TraveledDistance[client][1] += velocity[1] * GetTickInterval() * GetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue");
velocity[2] = 0.0;
gF_Trajectory[client] += GetVectorLength(velocity) * GetTickInterval() * GetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue");
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)
{
gI_SyncedTick[client]++;
gaincoeff = (wishspd - FloatAbs(currentgain)) / wishspd;
}
gF_RawGain[client] += gaincoeff;
}
}
public void DisplayKeyPad(int client)
{
// ================================== Select the Target player to track the keys ================================= //
int target;
if(IsPlayerAlive(client))
target = client;
else
{
int obTarget = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
int obMode = GetEntProp(client, Prop_Send, "m_iObserverMode");
if ((0 < obTarget <= MaxClients) && obMode != 7)
{
target = obTarget;
}
else return;
}
// Get Buttons
int buttons = GetClientButtons(target);
// Get Angles
float Angle[3];
GetClientEyeAngles(target, Angle);
// Get the Angle Difference btw ActualAngle - OldAngle
float AngleDiff = Angle[1] - gF_OldAngle[target];
if (Angle[1] - gF_OldAngle[target] > 180)
AngleDiff -= 360;
else if (Angle[1] - gF_OldAngle[target] < -180)
AngleDiff += 360;
gF_OldAngle[target] = Angle[1];
// =============================================================================================================== //
// ==================================================== Chars ==================================================== //
char sKeys[32]; // The Key HUD
char sCharacters[8][5] = {"←", "W", "→", "A", "S", "D", "DUCK", "JUMP"}; // The Characters
char sNotPressingButton[2] = "_"; // Not pressing the Buton Character
// =============================================================================================================== //
// =================================================== KeyBool =================================================== //
bool IsPressingTheKey[8] = { false, ...};
IsPressingTheKey[0] = (AngleDiff > 0); // ←
IsPressingTheKey[1] = (buttons & IN_FORWARD == IN_FORWARD); // W
IsPressingTheKey[2] = (AngleDiff < 0); // →
IsPressingTheKey[3] = (buttons & IN_MOVELEFT == IN_MOVELEFT); // A
IsPressingTheKey[4] = (buttons & IN_BACK == IN_BACK); // S
IsPressingTheKey[5] = (buttons & IN_MOVERIGHT == IN_MOVERIGHT); // D
IsPressingTheKey[6] = (buttons & IN_DUCK == IN_DUCK); // DUCK
IsPressingTheKey[7] = (buttons & IN_JUMP == IN_JUMP); // JUMP
// =============================================================================================================== //
// ========================================== Loop to format the sKeys =========================================== //
for (int i=0; i<8; i++)
{
if (IsPressingTheKey[i])
{
Format(sKeys, sizeof(sKeys), "%s %s", sKeys, sCharacters[i]);
}
else
{
if (i!=6 && i!=7)
Format(sKeys, sizeof(sKeys), "%s %s", sKeys, sNotPressingButton);
}
if (i == 2 || i == 5 || i == 6)
Format(sKeys, sizeof(sKeys), "%s\n", sKeys);
}
// =============================================================================================================== //
// ========================================== Print the sKeys to the HUD ========================================= //
if ((IsPressingTheKey[1] && IsPressingTheKey[4]) || (IsPressingTheKey[5] && IsPressingTheKey[3]))
PrintTheText(-1.0, 0.2, client, 255, 100, 100, sKeys, 1);
else
PrintTheText(-1.0, 0.2, client, 255, 255, 255, sKeys, 1);
// =============================================================================================================== //
}
stock bool GetClientCookieBool(int client, Handle cookie)
{
char sValue[8];
GetClientCookie(client, cookie, sValue, sizeof(sValue));
return (sValue[0] != '\0' && StringToInt(sValue));
}
stock void SetClientCookieBool(int client, Handle cookie, bool value)
{
char sValue[8];
IntToString(value, sValue, sizeof(sValue));
SetClientCookie(client, cookie, sValue);
}