forked from Pelipoika/The-unfinished-and-abandoned
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LedgeDetectTest.sp
295 lines (247 loc) · 7.23 KB
/
LedgeDetectTest.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
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#pragma newdecls required;
static int g_iLaserMaterial, g_iHaloMaterial;
bool g_bHanging[MAXPLAYERS+1];
float g_vecClimbPos[MAXPLAYERS+1][3];
public void OnMapStart()
{
g_iLaserMaterial = PrecacheModel("materials/sprites/laserbeam.vmt");
g_iHaloMaterial = PrecacheModel("materials/sprites/halo01.vmt");
}
public void OnClientPutInServer(int client)
{
g_bHanging[client] = false;
g_vecClimbPos[client] = view_as<float>{0.0, 0.0, 0.0};
}
public Action OnPlayerRunCmd(int client, int &iButtons, int &iImpulse, float fVel[3], float fAng[3], int &iWeapon)
{
if (IsPlayerAlive(client) && GetEntPropEnt(client, Prop_Send, "m_hGroundEntity") < 0)
{
if(iButtons & IN_JUMP && g_bHanging[client] && !(iButtons & IN_DUCK))
{
PrintToChat(client, "Climbed up");
SetEntityMoveType(client, MOVETYPE_WALK);
g_vecClimbPos[client][2] += 5.0;
TeleportEntity(client, g_vecClimbPos[client], NULL_VECTOR, NULL_VECTOR);
g_bHanging[client] = false;
SetVariantString("");
AcceptEntityInput(client, "SetCustomModel");
SetVariantBool(true);
AcceptEntityInput(client, "SetCustomModelRotates");
}
else if(iButtons & IN_DUCK && g_bHanging[client])
{
SetEntityMoveType(client, MOVETYPE_WALK);
g_bHanging[client] = false;
SetVariantString("");
AcceptEntityInput(client, "SetCustomModel");
SetVariantBool(true);
AcceptEntityInput(client, "SetCustomModelRotates");
}
float flOrigin[3], flMins[3], flMaxs[3];
GetClientAbsOrigin(client, flOrigin);
GetClientMaxs(client, flMaxs);
GetClientMins(client, flMins);
flMaxs[0] += 2.5;
flMaxs[1] += 2.5;
flMins[0] -= 2.5;
flMins[1] -= 2.5;
Handle TraceRay = TR_TraceHullFilterEx(flOrigin, flOrigin, flMins, flMaxs, MASK_PLAYERSOLID, TraceFilterNotSelf, client);
bool bHit = TR_DidHit(TraceRay);
TE_SendBox(client, bHit, flOrigin, flMins, flMaxs);
delete TraceRay;
if(bHit)
{
float angles[3], forw[3];
GetClientEyeAngles(client, angles);
angles[0] = 0.0;
GetAngleVectors(angles, forw, NULL_VECTOR, NULL_VECTOR);
MapCircleToSquare(forw, forw);
flOrigin[0] += (forw[0] * 29);
flOrigin[1] += (forw[1] * 29);
flOrigin[2] += (forw[2] * 29) + flMaxs[2];
flOrigin[2] += 32.0;
float flHitPos[3];
TR_TraceRayFilter(flOrigin, view_as<float>{90.0, 0.0, 0.0}, MASK_PLAYERSOLID, RayType_Infinite, TraceFilterNotSelf, client);
if (TR_DidHit() && !g_bHanging[client])
{
TR_GetEndPosition(flHitPos);
TE_SetupBeamPoints(flHitPos, flOrigin, g_iLaserMaterial, g_iHaloMaterial, 0, 0, 0.1, 1.0, 1.0, 1, 0.0, {0, 255, 0, 100}, 0);
TE_SendToClient(client);
//Fat hull trace
GetClientMaxs(client, flMaxs);
GetClientMins(client, flMins);
TR_TraceHullFilter(flOrigin, flHitPos, flMins, flMaxs, MASK_SOLID, TraceEntityFilterSolid, client);
float fatty[3];
TR_GetEndPosition(fatty);
TE_SendBox(client, true, fatty, flMins, flMaxs);
TE_SetupBeamRingPoint(fatty, 10.0, 11.0, g_iLaserMaterial, g_iHaloMaterial, 0, 15, 0.1, 1.0, 1.0, {0, 255, 0, 100}, 5, 0);
TE_SendToClient(client);
GetClientEyePosition(client, flOrigin);
float flDistance = GetVectorDistance(flOrigin, fatty);
if(flDistance <= 40.0 && flDistance >= 22.0)
{
TR_TraceHullFilter(fatty, fatty, flMins, flMaxs, MASK_SOLID, TraceEntityFilterSolid, client); //Test if we can fit to the dest pos before teleporting
if(!TR_DidHit())
{
PrintToChat(client, "Attached to ledge at distance %f", flDistance);
g_vecClimbPos[client][0] = fatty[0];
g_vecClimbPos[client][1] = fatty[1];
g_vecClimbPos[client][2] = fatty[2];
fatty[0] = flOrigin[0];
fatty[1] = flOrigin[1];
fatty[2] = (fatty[2] -= flMaxs[2]);
TeleportEntity(client, fatty, NULL_VECTOR, view_as<float>{0.0, 0.0, 0.0});
SetEntityMoveType(client, MOVETYPE_NONE);
g_bHanging[client] = true;
char strModel[PLATFORM_MAX_PATH];
GetEntPropString(client, Prop_Data, "m_ModelName", strModel, PLATFORM_MAX_PATH);
SetVariantString(strModel);
AcceptEntityInput(client, "SetCustomModel");
SetVariantBool(false);
AcceptEntityInput(client, "SetCustomModelRotates");
SetEntProp(client, Prop_Send, "m_bUseClassAnimations", 0);
}
}
}
}
}
return Plugin_Continue;
}
public bool TraceFilterNotSelf(int entityhit, int mask, any entity)
{
if(entity == 0 && entityhit != entity)
return true;
return false;
}
public bool TraceEntityFilterSolid(int entityhit, int contentsMask, int entity)
{
if (entityhit > MaxClients && entityhit != entity)
{
return true;
}
return false;
}
stock void TE_SendBox(int client, bool bHit, float flOrigin[3], float flMins[3], float flMaxs[3])
{
float flMaxResult[3], flMinResult[3];
AddVectors(flOrigin, flMaxs, flMaxResult);
AddVectors(flOrigin, flMins, flMinResult);
float vPos1[3], vPos2[3], vPos3[3], vPos4[3], vPos5[3], vPos6[3];
vPos1 = flMaxResult;
vPos1[0] = flMinResult[0];
vPos2 = flMaxResult;
vPos2[1] = flMinResult[1];
vPos3 = flMaxResult;
vPos3[2] = flMinResult[2];
vPos4 = flMinResult;
vPos4[0] = flMaxResult[0];
vPos5 = flMinResult;
vPos5[1] = flMaxResult[1];
vPos6 = flMinResult;
vPos6[2] = flMaxResult[2];
TE_SendBeam(client, flMaxResult, vPos1, bHit);
TE_SendBeam(client, flMaxResult, vPos2, bHit);
TE_SendBeam(client, flMaxResult, vPos3, bHit);
TE_SendBeam(client, vPos6, vPos1, bHit);
TE_SendBeam(client, vPos6, vPos2, bHit);
TE_SendBeam(client, vPos6, flMinResult, bHit);
TE_SendBeam(client, vPos4, flMinResult, bHit);
TE_SendBeam(client, vPos5, flMinResult, bHit);
TE_SendBeam(client, vPos5, vPos1, bHit);
TE_SendBeam(client, vPos5, vPos3, bHit);
TE_SendBeam(client, vPos4, vPos3, bHit);
TE_SendBeam(client, vPos4, vPos2, bHit);
}
void TE_SendBeam(int client, float m_vecMins[3], float m_vecMaxs[3], bool bHit)
{
if(!bHit)
TE_SetupBeamPoints(m_vecMins, m_vecMaxs, g_iLaserMaterial, g_iHaloMaterial, 0, 0, 0.1, 1.0, 1.0, 1, 0.0, {255, 255, 255, 100}, 0);
else
TE_SetupBeamPoints(m_vecMins, m_vecMaxs, g_iLaserMaterial, g_iHaloMaterial, 0, 0, 0.1, 1.0, 1.0, 1, 0.0, {255, 0, 0, 100}, 0);
TE_SendToClient(client);
}
void MapCircleToSquare(float out[3], const float input[3])
{
float x = input[0], y = input[1];
float nx, ny;
if(x < 0.000002 && x > -0.000002)
{
nx = 0.0;
ny = y;
}
else if(y < 0.000002 && y > -0.000002)
{
nx = x;
ny = 0.0;
}
else if (y > 0.0)
{
if (x > 0.0)
{
if (x < y)
{
nx = x / y;
ny = 1.0;
}
else
{
nx = 1.0;
ny = y / x;
}
}
else
{
if (x < -y)
{
nx = -1.0;
ny = -(y / x);
}
else
{
nx = x / y;
ny = 1.0;
}
}
}
else
{
if (x > 0.0)
{
if (-x > y)
{
nx = -(x / y);
ny = -1.0;
}
else
{
nx = 1.0;
ny = (y / x);
}
}
else
{
if (x < y)
{
nx = -1.0;
ny = -(y / x);
}
else
{
nx = -(x / y);
ny = -1.0;
}
}
}
out[0] = nx;
out[1] = ny;
}
stock bool IsValidClient(int client)
{
if(client <= 0 ) return false;
if(client > MaxClients) return false;
if(!IsClientConnected(client)) return false;
return IsClientInGame(client);
}