-
Notifications
You must be signed in to change notification settings - Fork 0
/
surf.gsc
executable file
·307 lines (233 loc) · 6.96 KB
/
surf.gsc
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
/*
TODO
- player just jumps-off sometimes in some unexpected direction
- auto-bunny-hop on jumpButtonPressed
- airMovement feels perfect, but its just annoying that i cant use
left/right key to change position in air with normal movement
*/
surf()
{
//surf_old();
surf_new();
}
airMovement(isOnSurfRamp)
{
player = self;
forwardDir = anglesToForward((0, self getPlayerAngles()[1], 0));
forwardVel = vectorNormalize(self getVelocity());
dot = vectorDot(forwardDir, forwardVel);
dot += 0.01; // fix for only pressing left/right... want forward, but often its like -0.0004
//iprintlnbold(dot);
//wait 0.20;
forwardOrBackward = 1; // player is looking in same direction as his velocity
if (dot < 0)
forwardOrBackward = -1;
if (player isOnGround())
return;
if ( ! (player leftButtonPressed() || player rightButtonPressed()))
return;
vel = player getVelocity();
//dir = vectorNormalize(vel);
tmpVel = (vel[0], vel[1], 0);
len = length(tmpVel);
//if (len < 300) // dont annoy me with normal jumps
//if ( ! player.surfing)
// return;
//iprintlnbold(len);
newDir = anglesToForward((0, player getPlayerAngles()[1], 0));
newVel = std\math::vectorScale(newDir, len);
newVel = (newVel[0] * forwardOrBackward, newVel[1] * forwardOrBackward, vel[2]);
//iprintlnbold(newVel);
/*if (isOnSurfRamp)
{
len = length(newVel);
iprintlnbold(len);
std\math::vectorScale(vectorNormalize(newVel), len + (len / 1));
}*/
player setVelocity(newVel);
}
isOnSurfRamp()
{
player = self;
traceDir = anglestoright(self getplayerangles());
traceTo = std\math::vectorScale(traceDir, 25);
dist = physicstrace(self.origin, self.origin + traceTo);
isRight = distanceSquared(dist, self.origin) < 24*24; // -1 then original surfDistance
if (isRight)
return true;
traceTo = std\math::vectorScale(traceDir, -25);
dist = physicstrace(self.origin, self.origin + traceTo);
isLeft = distanceSquared(dist, self.origin) < 24*24; // -1 then original surfDistance
if (isLeft)
return true;
player.surfing = false;
return false;
}
canSurf()
{
player = self;
//wait 0.20;
button = player rightButtonPressed() - player leftButtonPressed();
if (button == 0)
return undefined;
traceDir = anglestoright(self getplayerangles());
traceTo = std\math::vectorScale(traceDir, 25 * button);
trace = bullettrace(self.origin+(0,0,20), self.origin+(0,0,20) + traceTo, false, undefined);
dist = physicstrace(self.origin, self.origin + traceTo);
isBug = distanceSquared(dist, self.origin) < 24*24; // -1 then original surfDistance
if (player isOnGround())
{
//player iprintlnbold("isOnGround");
player.surfing = false;
return undefined;
}
if (isBug)
{
//player iprintlnbold("surfing on bugged slope normal=", trace["normal"], "f=", trace["fraction"] ," ", trace["normal"][2] == 0);
return trace;
}
if (trace["fraction"] == 1)
{
//player iprintlnbold("nothing to surf on");
return undefined;
}
if(trace["normal"][2] > 0.7)
{
self iprintlnbold("ignoring ground trace[normal][2]=" + trace["normal"][2]);
player.surfing = false;
return undefined;
}
if (vectorDot(trace["normal"], (0,0,1)) == 0)
{
//self iprintlnbold("ignoring wall");
return undefined;
}
return trace;
}
bug()
{
newPos = self getVelocity();
if (!isDefined(self.old_velocity))
{
self.old_velocity = newPos;
return;
}
oldPos = self.old_velocity;
delta = length(newPos) - length(oldPos);
if (delta >= 0)
{
self.old_velocity = newPos;
return;
}
speedLoss = delta * -1;
if (speedLoss > 100 && self std\debugging::isDebugger())
self iprintlnbold("BUG? speedLoss=" + speedLoss + " lastSurf=", getTime()-self.lastSurf);
lastSurf = getTime()-self.lastSurf;
if (lastSurf < 300 && speedLoss > 500)
//if (lastSurf < 150 && speedLoss > 800)
{
if (self std\debugging::isDebugger())
self iprintlnbold("REPAIR oldVel=", self.old_velocity);
for (i=0; i<12; i++) // force old velocity if needed 12 times
{
if ( ! self.surfing)
{
if (self std\debugging::isDebugger())
self iprintlnbold("STOP REPAIR, player.surfing=false");
break;
}
if (self isOnGround())
{
if (self std\debugging::isDebugger())
self iprintlnbold("STOP REPAIR");
break;
}
self setVelocity(self.old_velocity);
wait 0.05;
}
}
self.old_velocity = newPos;
}
surf_new()
{
self endon("disconnect");
self endon("spawned_player");
self endon("killed_player");
player = self;
old_velocity = undefined; // bug detection
boost = 20;
setcvar("sv_fps", "20");
self.lastSurf = 0;
self.surfing = false;
while(true)
{
wait 0.05;
/*
iprintlnbold(self std\player::lookAt()["position"]);
wait 0.2;
if (1<2)
continue;
*/
self bug();
/*
// lol, can surf only with airmovement (no speedgain then)
airMovement();
if (1<2)
continue;
*/
/*
trace = player canSurf();
if ( ! isDefined(trace))
{
player airMovement(false);
continue;
}
*/
if ( ! player isOnSurfRamp())
{
player airMovement(false);
continue;
}
// edit again: this is after canSurf now(), because before its "fixing" bunnyhop and wallcrashes without being on ramp
// this is now BEFORE canSurf(), because its the same.
//player iprintlnbold("lastSurf=", getTime()-self.lastSurf);
self.lastSurf = getTime();
player.surfing = true;
if (1<2)
{
player airMovement(true);
continue;
}
currentspeed = self getVelocity();
//self iprintln("boosting with: " + boost_power);
speed_wanted = vectorDot(anglestoforward((0, self.angles[1], 0)), self getVelocity());
//iprintlnbold(maps\mp\_utility::abs(speed_wanted));
//iprintlnbold(speed_wanted, " ", anglestoforward((0, self.angles[1], 0)));
speed_wanted += self forwardButtonPressed() - self backButtonPressed();
//if(speed_wanted > 0)
speed_wanted *= 1.05;
if(maps\mp\_utility::abs(speed_wanted) > 2000)
speed_wanted *= 0.95;
//iprintlnbold(maps\mp\_utility::abs(speed_wanted)); // maybe length(velocity) max 1500 or so
//if(self.origin[2] - trace["position"][2] > 20)
//{
// speed_wanted *= (1 - ((self.origin[2] - trace["position"][2])/50));
//}
speed = std\math::vectorScale(anglestoforward((0, self.angles[1], 0)), speed_wanted);
finalVector = speed + (0, 0, currentspeed[2]);
/*rightspeed = vectorDot(currentspeed, anglestoright(self getplayerangles()));
//iprintlnbold(rightspeed, " ", currentspeed, " ", self getplayerangles(), " ", anglestoright(self getplayerangles()));
if(self leftButtonPressed() && rightspeed > -1*boost && !self rightButtonPressed())
finalVector += std\math::vectorScale(anglestoright(self getplayerangles()), -1 * (rightspeed+boost));
else if(self rightButtonPressed() && rightspeed < boost && !self leftButtonPressed())
finalVector += std\math::vectorScale(anglestoright(self getplayerangles()), -1 * (rightspeed+boost));
*/
//iprintlnbold(finalVector);
self setVelocity(finalVector);
}
}
vectorprod2d(vec1,vec2)
{
num=vec1[0]*vec2[1]-vec1[1]*vec2[0];
return num;
}