-
Notifications
You must be signed in to change notification settings - Fork 2
/
strafe_trainer_kids_thing_with_stocks_included.sp
314 lines (254 loc) · 7.76 KB
/
strafe_trainer_kids_thing_with_stocks_included.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
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <clientprefs>
#pragma newdecls required
EngineVersion g_Game;
float gF_LastAngle[MAXPLAYERS + 1][3];
int gI_ClientTickCount[MAXPLAYERS + 1];
float gF_ClientPercentages[MAXPLAYERS + 1][129];
Handle gH_StrafeTrainerCookie;
Handle gH_StrafeTrainerCookieTicks;
bool gB_StrafeTrainer[MAXPLAYERS + 1] = {false, ...};
int gI_StrafeTrainerTicks[MAXPLAYERS + 1] = {10, ...};
float gF_FrameTime;
ConVar sv_air_max_wishspeed = null;
public Plugin myinfo =
{
name = "BHOP Strafe Trainer",
author = "PaxPlay",
description = "Bhop Strafe Trainer, stuff by kid fearless",
version = "0.2",
url = "https://github.com/PaxPlay/bhop-strafe-trainer"
};
public void OnPluginStart()
{
sv_air_max_wishspeed = FindConVar("sv_air_max_wishspeed");
sv_air_max_wishspeed.Flags &= ~(FCVAR_REPLICATED);
g_Game = GetEngineVersion();
if(g_Game != Engine_CSGO && g_Game != Engine_CSS)
{
SetFailState("This plugin is for CSGO/CSS only.");
}
RegConsoleCmd("sm_strafetrainer", Command_StrafeTrainer, "Toggles the Strafe trainer.");
gH_StrafeTrainerCookie = RegClientCookie("strafetrainer_enabled", "strafetrainer_enabled", CookieAccess_Protected);
gH_StrafeTrainerCookieTicks = RegClientCookie("strafetrainer_ticks", "strafetrainer_ticks", CookieAccess_Protected);
// Late loading
for(int i = 1; i <= MaxClients; i++)
{
if(AreClientCookiesCached(i))
{
OnClientCookiesCached(i);
}
}
gF_FrameTime = GetTickInterval();
}
public void OnClientDisconnect(int client)
{
gB_StrafeTrainer[client] = false;
}
public void OnClientCookiesCached(int client)
{
if(GetClientCookieInt(client, gH_StrafeTrainerCookieTicks) == 0)
{
SetClientCookieInt(client, gH_StrafeTrainerCookieTicks, 10);
}
gB_StrafeTrainer[client] = GetClientCookieBool(client, gH_StrafeTrainerCookie);
gI_StrafeTrainerTicks[client] = GetClientCookieInt(client, gH_StrafeTrainerCookieTicks);
}
public Action Command_StrafeTrainer(int client, int args)
{
if (args < 1)
{
gB_StrafeTrainer[client] = !gB_StrafeTrainer[client];
SetClientCookieBool(client, gH_StrafeTrainerCookie, gB_StrafeTrainer[client]);
ReplyToCommand(client, "[SM] Strafe Trainer %s!", gB_StrafeTrainer[client] ? "enabled" : "disabled");
return Plugin_Handled;
}
char arg[64];
GetCmdArg(1, arg, sizeof(arg));
int ticks = StringToInt(arg);
if(ticks > 128 || ticks < 1)
{
ReplyToCommand(client, "[SM] Please enter a value between 1 and 128");
return Plugin_Handled;
}
else
{
gB_StrafeTrainer[client] = true;
SetClientCookieBool(client, gH_StrafeTrainerCookie, gB_StrafeTrainer[client]);
gI_StrafeTrainerTicks[client] = ticks;
SetClientCookieInt(client, gH_StrafeTrainerCookieTicks, ticks);
ReplyToCommand(client, "[SM] Strafe Trainer set to %i", ticks);
return Plugin_Handled;
}
}
float NormalizeAngle(float angle)
{
float newAngle = angle;
while (newAngle <= -180.0) newAngle += 360.0;
while (newAngle > 180.0) newAngle -= 360.0;
return newAngle;
}
float GetClientVelocity(int client)
{
float vVel[3];
vVel[0] = GetEntPropFloat(client, Prop_Send, "m_vecVelocity[0]");
vVel[1] = GetEntPropFloat(client, Prop_Send, "m_vecVelocity[1]");
return GetVectorLength(vVel);
}
float PerfStrafeAngle(float speed)
{
return RadToDeg(ArcTangent(sv_air_max_wishspeed.FloatValue / speed));
}
void VisualisationString(char[] buffer, int maxlength, float percentage)
{
if (0.5 <= percentage <= 1.5)
{
int Spaces = RoundFloat((percentage - 0.5) / 0.05);
for (int i = 0; i <= Spaces + 1; i++)
{
FormatEx(buffer, maxlength, "%s ", buffer);
}
FormatEx(buffer, maxlength, "%s|", buffer);
for (int i = 0; i <= (21 - Spaces); i++)
{
FormatEx(buffer, maxlength, "%s ", buffer);
}
}
else
Format(buffer, maxlength, "%s", percentage < 1.0 ? "| " : " |");
}
void GetPercentageColor(float percentage, int &r, int &g, int &b)
{
int percent = RoundFloat(percentage * 100);
if((percent > 80) && (percent < 120))
{
r = 0;
g = 255;
b = 0;
}
else if((percent >= 120) && (percent <= 150))
{
r = 128;
g = 255;
b = 0;
}
else if((percent >= 150) && (percent <= 180))
{
r = 255;
g = 128;
b = 0;
}
else if(percent >= 180)
{
r = 255;
g = 0;
b = 0;
}
else if((percent >= 50) && (percent <= 80))
{
r = 0;
g = 255;
b = 128;
}
else if((percent >= 25) && (percent <= 50))
{
r = 0;
g = 128;
b = 255;
}
else if(percent <= 25)
{
r = 0;
g = 0;
b = 255;
}
}
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 (!gB_StrafeTrainer[client])
{
return Plugin_Continue; // dont run when disabled.
}
if ((GetEntityFlags( client ) & FL_ONGROUND) && (buttons & IN_JUMP) == 0)
{
return Plugin_Continue;
}
// calculate differences
float AngDiff;
AngDiff = NormalizeAngle(gF_LastAngle[client][1] - angles[1]);
//PrintToConsole(client, "%f", sv_air_max_wishspeed.FloatValue);
// get the perfect angle
float PerfAngle = PerfStrafeAngle(GetClientVelocity(client));
// get the absolute value of AngDiff
AngDiff = FloatAbs(AngDiff);
// calculate the current percentage
float Percentage = AngDiff / PerfAngle;
if (gI_ClientTickCount[client] >= gI_StrafeTrainerTicks[client]) // only every 10th tick, not really usable otherwise
{
float AveragePercentage = 0.0;
int strafetrainerticks = gI_StrafeTrainerTicks[client];
for (int i = 0; i < strafetrainerticks; i++) // calculate average from the last ticks
{
AveragePercentage += gF_ClientPercentages[client][i];
gF_ClientPercentages[client][i] = 0.0;
}
AveragePercentage /= strafetrainerticks;
char sVisualisation[32]; // get the visualisation string
VisualisationString(sVisualisation, sizeof(sVisualisation), AveragePercentage);
// format the message
char sMessage[256];
Format(sMessage, sizeof(sMessage), "%d\%", RoundFloat(AveragePercentage * 100));
Format(sMessage, sizeof(sMessage), "%s\n══════^══════", sMessage);
Format(sMessage, sizeof(sMessage), "%s\n %s ", sMessage, sVisualisation);
Format(sMessage, sizeof(sMessage), "%s\n══════^══════", sMessage);
// get the text color
int r, g, b;
GetPercentageColor(AveragePercentage, r, g, b);
// print the text
Handle hText = CreateHudSynchronizer();
if(hText != INVALID_HANDLE)
{
SetHudTextParams(-1.0, 0.2, (gF_FrameTime*strafetrainerticks), r, g, b, 255, 0, 0.0, 0.0, 0.1);
//SetHudTextParams(float x, float y, float holdTime, int r, int g, int b, int a, int effect, float fxTime, float fadeIn, float fadeOut)
ShowSyncHudText(client, hText, sMessage);
CloseHandle(hText);
}
gI_ClientTickCount[client] = 0;
}
else
{
// save the percentage to an array to calculate the average later
gF_ClientPercentages[client][gI_ClientTickCount[client]] = Percentage;
gI_ClientTickCount[client]++;
}
// save the angles to a variable used in the next tick
gF_LastAngle[client] = angles;
return Plugin_Continue;
}
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);
}
stock int GetClientCookieInt(int iClient, Handle hCookie)
{
char sCookieVal[65];
GetClientCookie(iClient, hCookie, sCookieVal, sizeof(sCookieVal));
return StringToInt(sCookieVal);
}
stock void SetClientCookieInt(int iClient, Handle hCookie, int iIn=0)
{
char sCookieVal[65];
IntToString(iIn, sCookieVal, sizeof(sCookieVal));
SetClientCookie(iClient, hCookie, sCookieVal);
}