/
stuck.sp
330 lines (263 loc) · 9.24 KB
/
stuck.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
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#define PLUGIN_NAME "stuck"
#define PLUGIN_AUTHOR "Erreur 500"
#define PLUGIN_DESCRIPTION "Fix stuck players"
#define PLUGIN_VERSION "1.3.1"
#define PLUGIN_CONTACT "erreur500@hotmail.fr"
new TimeLimit;
new Counter[MAXPLAYERS+1] = {0, ...};
new StuckCheck[MAXPLAYERS+1] = {0, ...};
new Countdown[MAXPLAYERS+1] = {0, ...};
new bool:isStuck[MAXPLAYERS+1];
new Float:Step;
new Float:RadiusSize;
new Float:Ground_Velocity[3] = {0.0, 0.0, -300.0};
new Handle:c_Limit = INVALID_HANDLE;
new Handle:c_Countdown = INVALID_HANDLE;
new Handle:c_Radius = INVALID_HANDLE;
new Handle:c_Step = INVALID_HANDLE;
public Plugin:myinfo =
{
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = PLUGIN_DESCRIPTION,
version = PLUGIN_VERSION,
url = PLUGIN_CONTACT
};
public OnPluginStart()
{
CreateConVar("stuck_version", PLUGIN_VERSION, "Stuck version", FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_DONTRECORD);
c_Limit = CreateConVar("stuck_limit", "7", "How many !stuck can a player use ? (0 = no limit)", FCVAR_PLUGIN, true, 0.0);
c_Countdown = CreateConVar("stuck_wait", "300", "Time to wait before earn new !stuck.", FCVAR_PLUGIN, true, 0.0);
c_Radius = CreateConVar("stuck_radius", "200", "Radius size to fix player position.", FCVAR_PLUGIN, true, 10.0);
c_Step = CreateConVar("stuck_step", "20", "Step between each position tested.", FCVAR_PLUGIN, true, 1.0);
AutoExecConfig(true, "stuck");
HookConVarChange(c_Countdown, CallBackCVarCountdown);
HookConVarChange(c_Radius, CallBackCVarRadius);
HookConVarChange(c_Step, CallBackCVarStep);
TimeLimit = GetConVarInt(c_Countdown);
if(TimeLimit < 0)
TimeLimit = -TimeLimit;
RadiusSize = GetConVarInt(c_Radius) * 1.0;
if(RadiusSize < 10.0)
RadiusSize = 10.0;
Step = GetConVarInt(c_Step) * 1.0;
if(Step < 1.0)
Step = 1.0;
RegConsoleCmd("stuck", StuckCmd, "Are you stuck ?");
RegConsoleCmd("unstuck", StuckCmd, "Are you stuck ?");
CreateTimer(1.0, Timer, INVALID_HANDLE, TIMER_REPEAT);
}
public OnMapStart()
{
for(new i=0; i<MaxClients; i++)
Counter[i] = 0;
}
public CallBackCVarCountdown(Handle:cvar, const String:oldVal[], const String:newVal[])
{
TimeLimit = StringToInt(newVal);
if(TimeLimit < 0)
TimeLimit = -TimeLimit;
LogMessage("stuck_wait = %i", TimeLimit);
}
public CallBackCVarRadius(Handle:cvar, const String:oldVal[], const String:newVal[])
{
RadiusSize = StringToInt(newVal) * 1.0;
if(RadiusSize < 10.0)
RadiusSize = 10.0;
LogMessage("stuck_radius = %f", RadiusSize);
}
public CallBackCVarStep(Handle:cvar, const String:oldVal[], const String:newVal[])
{
Step = StringToInt(newVal) * 1.0;
if(Step < 1.0)
Step = 1.0;
LogMessage("stuck_step = %f", Step);
}
stock bool:IsValidClient(iClient)
{
if (iClient <= 0) return false;
if (iClient > MaxClients) return false;
return IsClientInGame(iClient);
}
public Action:Timer(Handle:timer)
{
for(new i=0; i<MaxClients; i++)
{
if(Counter[i] > 0)
{
Countdown[i]++;
if(Countdown[i] >= TimeLimit)
{
Countdown[i] = 0;
Counter[i]--;
}
}
else if(Counter[i] == 0 && Countdown[i] != 0)
Countdown[i] = 0;
}
}
public Action:StuckCmd(iClient, Args)
{
if(iClient <= 0) return;
if(iClient > MaxClients) return;
if(!IsPlayerAlive(iClient))
{
PrintToChat(iClient, "[!stuck] How a death can be stuck !?");
return;
}
if(GetConVarInt(c_Limit) > 0 && Counter[iClient] >= GetConVarInt(c_Limit))
{
PrintToChat(iClient, "[!stuck] Sorry, you must wait %i seconds before use this command again.", TimeLimit - Countdown[iClient]);
return;
}
Counter[iClient]++;
StuckCheck[iClient] = 0;
StartStuckDetection(iClient);
}
StartStuckDetection(iClient)
{
StuckCheck[iClient]++;
isStuck[iClient] = false;
isStuck[iClient] = CheckIfPlayerIsStuck(iClient); // Check if player stuck in prop
CheckIfPlayerCanMove(iClient, 0, 500.0, 0.0, 0.0);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Stuck Detection
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
stock bool:CheckIfPlayerIsStuck(iClient)
{
decl Float:vecMin[3], Float:vecMax[3], Float:vecOrigin[3];
GetClientMins(iClient, vecMin);
GetClientMaxs(iClient, vecMax);
GetClientAbsOrigin(iClient, vecOrigin);
TR_TraceHullFilter(vecOrigin, vecOrigin, vecMin, vecMax, MASK_SOLID, TraceEntityFilterSolid);
return TR_DidHit(); // head in wall ?
}
public bool:TraceEntityFilterSolid(entity, contentsMask)
{
return entity > MaxClients;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// More Stuck Detection
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
stock CheckIfPlayerCanMove(iClient, testID, Float:X=0.0, Float:Y=0.0, Float:Z=0.0) // In few case there are issues with IsPlayerStuck() like clip
{
decl Float:vecVelo[3];
decl Float:vecOrigin[3];
GetClientAbsOrigin(iClient, vecOrigin);
vecVelo[0] = X;
vecVelo[1] = Y;
vecVelo[2] = Z;
SetEntPropVector(iClient, Prop_Data, "m_vecBaseVelocity", vecVelo);
new Handle:TimerDataPack;
CreateDataTimer(0.1, TimerWait, TimerDataPack);
WritePackCell(TimerDataPack, iClient);
WritePackCell(TimerDataPack, testID);
WritePackFloat(TimerDataPack, vecOrigin[0]);
WritePackFloat(TimerDataPack, vecOrigin[1]);
WritePackFloat(TimerDataPack, vecOrigin[2]);
}
public Action:TimerWait(Handle:timer, Handle:data)
{
decl Float:vecOrigin[3];
decl Float:vecOriginAfter[3];
ResetPack(data, false);
new iClient = ReadPackCell(data);
new testID = ReadPackCell(data);
vecOrigin[0] = ReadPackFloat(data);
vecOrigin[1] = ReadPackFloat(data);
vecOrigin[2] = ReadPackFloat(data);
GetClientAbsOrigin(iClient, vecOriginAfter);
if(GetVectorDistance(vecOrigin, vecOriginAfter, false) < 10.0) // Can't move
{
if(testID == 0)
CheckIfPlayerCanMove(iClient, 1, 0.0, 0.0, -500.0); // Jump
else if(testID == 1)
CheckIfPlayerCanMove(iClient, 2, -500.0, 0.0, 0.0);
else if(testID == 2)
CheckIfPlayerCanMove(iClient, 3, 0.0, 500.0, 0.0);
else if(testID == 3)
CheckIfPlayerCanMove(iClient, 4, 0.0, -500.0, 0.0);
else if(testID == 4)
CheckIfPlayerCanMove(iClient, 5, 0.0, 0.0, 300.0);
else
FixPlayerPosition(iClient);
}
else
{
if(StuckCheck[iClient] < 2)
PrintToChat(iClient, "[!stuck] Well Tried, but you are not stuck!");
else
PrintToChat(iClient, "[!stuck] Done!", StuckCheck[iClient]);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Fix Position
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FixPlayerPosition(iClient)
{
if(isStuck[iClient]) // UnStuck player stuck in prop
{
new Float:pos_Z = 0.1;
while(pos_Z <= RadiusSize && !TryFixPosition(iClient, 10.0, pos_Z))
{
pos_Z = -pos_Z;
if(pos_Z > 0.0)
pos_Z += Step;
}
if(!CheckIfPlayerIsStuck(iClient) && StuckCheck[iClient] < 7) // If client was stuck => new check
StartStuckDetection(iClient);
else
PrintToChat(iClient,"[!stuck] Sorry, I'm not able to fix your position.");
}
else // UnStuck player stuck in clip (invisible wall)
{
// if it is a clip on the sky, it will try to find the ground !
new Handle:trace = INVALID_HANDLE;
decl Float:vecOrigin[3];
decl Float:vecAngle[3];
GetClientAbsOrigin(iClient, vecOrigin);
vecAngle[0] = 90.0;
trace = TR_TraceRayFilterEx(vecOrigin, vecAngle, MASK_SOLID, RayType_Infinite, TraceEntityFilterSolid);
if(!TR_DidHit(trace))
{
CloseHandle(trace);
return;
}
TR_GetEndPosition(vecOrigin, trace);
CloseHandle(trace);
vecOrigin[2] += 10.0;
TeleportEntity(iClient, vecOrigin, NULL_VECTOR, Ground_Velocity);
if(StuckCheck[iClient] < 7) // If client was stuck in invisible wall => new check
StartStuckDetection(iClient);
else
PrintToChat(iClient,"[!stuck] Sorry, I'm not able to fix your position.");
}
}
bool:TryFixPosition(iClient, Float:Radius, Float:pos_Z)
{
decl Float:DegreeAngle;
decl Float:vecPosition[3];
decl Float:vecOrigin[3];
decl Float:vecAngle[3];
GetClientAbsOrigin(iClient, vecOrigin);
GetClientEyeAngles(iClient, vecAngle);
vecPosition[2] = vecOrigin[2] + pos_Z;
DegreeAngle = -180.0;
while(DegreeAngle < 180.0)
{
vecPosition[0] = vecOrigin[0] + Radius * Cosine(DegreeAngle * FLOAT_PI / 180); // convert angle in radian
vecPosition[1] = vecOrigin[1] + Radius * Sine(DegreeAngle * FLOAT_PI / 180);
TeleportEntity(iClient, vecPosition, vecAngle, Ground_Velocity);
if(!CheckIfPlayerIsStuck(iClient))
return true;
DegreeAngle += 10.0; // + 10°
}
TeleportEntity(iClient, vecOrigin, vecAngle, Ground_Velocity);
if(Radius <= RadiusSize)
return TryFixPosition(iClient, Radius + Step, pos_Z);
return false;
}