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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
|
/*
Small features that aren't worth splitting into their own file.
*/
// =====[ GOKZ.CFG ]=====
void OnMapStart_KZConfig()
{
char gokzCfgFullPath[PLATFORM_MAX_PATH];
FormatEx(gokzCfgFullPath, sizeof(gokzCfgFullPath), "cfg/%s", GOKZ_CFG_SERVER);
if (FileExists(gokzCfgFullPath))
{
ServerCommand("exec %s", GOKZ_CFG_SERVER);
}
else
{
SetFailState("Failed to load file: \"%s\". Check that it exists.", gokzCfgFullPath);
}
}
// =====[ GODMODE ]=====
void OnPlayerSpawn_GodMode(int client)
{
// Stop players from taking damage
SetEntProp(client, Prop_Data, "m_takedamage", 0);
SetEntityFlags(client, GetEntityFlags(client) | FL_GODMODE);
}
// =====[ NOCLIP ]=====
int noclipReleaseTime[MAXPLAYERS + 1];
void ToggleNoclip(int client)
{
if (Movement_GetMovetype(client) != MOVETYPE_NOCLIP)
{
EnableNoclip(client);
}
else
{
DisableNoclip(client);
}
}
void EnableNoclip(int client)
{
if (IsValidClient(client) && IsPlayerAlive(client))
{
if (GOKZ_GetCoreOption(client, Option_Safeguard) > Safeguard_Disabled && GOKZ_GetTimerRunning(client) && GOKZ_GetValidTimer(client))
{
GOKZ_PrintToChat(client, true, "%t", "Safeguard - Blocked");
GOKZ_PlayErrorSound(client);
return;
}
Movement_SetMovetype(client, MOVETYPE_NOCLIP);
GOKZ_StopTimer(client);
}
}
void DisableNoclip(int client)
{
if (IsValidClient(client) && IsPlayerAlive(client) && Movement_GetMovetype(client) == MOVETYPE_NOCLIP)
{
noclipReleaseTime[client] = GetGameTickCount();
Movement_SetMovetype(client, MOVETYPE_WALK);
SetEntProp(client, Prop_Send, "m_CollisionGroup", GOKZ_COLLISION_GROUP_STANDARD);
// Prevents an exploit that would let you noclip out of start zones
RemoveNoclipGroundFlag(client);
}
}
void ToggleNoclipNotrigger(int client)
{
if (Movement_GetMovetype(client) != MOVETYPE_NOCLIP)
{
EnableNoclipNotrigger(client);
}
else
{
DisableNoclipNotrigger(client);
}
}
void EnableNoclipNotrigger(int client)
{
if (IsValidClient(client) && IsPlayerAlive(client))
{
if (GOKZ_GetCoreOption(client, Option_Safeguard) > Safeguard_Disabled && GOKZ_GetTimerRunning(client) && GOKZ_GetValidTimer(client))
{
GOKZ_PrintToChat(client, true, "%t", "Safeguard - Blocked");
GOKZ_PlayErrorSound(client);
return;
}
Movement_SetMovetype(client, MOVETYPE_NOCLIP);
SetEntProp(client, Prop_Send, "m_CollisionGroup", GOKZ_COLLISION_GROUP_NOTRIGGER);
GOKZ_StopTimer(client);
}
}
void DisableNoclipNotrigger(int client)
{
if (IsValidClient(client) && IsPlayerAlive(client) && Movement_GetMovetype(client) == MOVETYPE_NOCLIP)
{
noclipReleaseTime[client] = GetGameTickCount();
Movement_SetMovetype(client, MOVETYPE_WALK);
SetEntProp(client, Prop_Send, "m_CollisionGroup", GOKZ_COLLISION_GROUP_STANDARD);
// Prevents an exploit that would let you noclip out of start zones
RemoveNoclipGroundFlag(client);
}
}
void RemoveNoclipGroundFlag(int client)
{
float startPosition[3], endPosition[3];
GetClientAbsOrigin(client, startPosition);
endPosition = startPosition;
endPosition[2] = startPosition[2] - 2.0;
Handle trace = TR_TraceHullFilterEx(
startPosition,
endPosition,
view_as<float>( { -16.0, -16.0, 0.0 } ),
view_as<float>( { 16.0, 16.0, 72.0 } ),
MASK_PLAYERSOLID,
TraceEntityFilterPlayers,
client);
if (!TR_DidHit(trace))
{
SetEntityFlags(client, GetEntityFlags(client) & ~FL_ONGROUND);
}
delete trace;
}
bool JustNoclipped(int client)
{
return GetGameTickCount() - noclipReleaseTime[client] <= GOKZ_TIMER_START_NOCLIP_TICKS;
}
void OnClientPutInServer_Noclip(int client)
{
noclipReleaseTime[client] = 0;
}
// =====[ TURNBINDS ]=====
static int turnbindsLastLeftStart[MAXPLAYERS + 1];
static int turnbindsLastRightStart[MAXPLAYERS + 1];
static float turnbindsLastValidYaw[MAXPLAYERS + 1];
static int turnbindsOldButtons[MAXPLAYERS + 1];
void OnClientPutInServer_Turnbinds(int client)
{
turnbindsLastLeftStart[client] = 0;
turnbindsLastRightStart[client] = 0;
}
// Ensures that there is a minimum time between starting to turnbind in one direction
// and then starting to turnbind in the other direction
void OnPlayerRunCmd_Turnbinds(int client, int buttons, int tickcount, float angles[3])
{
if (IsFakeClient(client))
{
return;
}
if (buttons & IN_LEFT && tickcount < turnbindsLastRightStart[client] + RoundToNearest(GOKZ_TURNBIND_COOLDOWN / GetTickInterval()))
{
angles[1] = turnbindsLastValidYaw[client];
TeleportEntity(client, NULL_VECTOR, angles, NULL_VECTOR);
buttons = 0;
}
else if (buttons & IN_RIGHT && tickcount < turnbindsLastLeftStart[client] + RoundToNearest(GOKZ_TURNBIND_COOLDOWN / GetTickInterval()))
{
angles[1] = turnbindsLastValidYaw[client];
TeleportEntity(client, NULL_VECTOR, angles, NULL_VECTOR);
buttons = 0;
}
else
{
turnbindsLastValidYaw[client] = angles[1];
if (!(turnbindsOldButtons[client] & IN_LEFT) && (buttons & IN_LEFT))
{
turnbindsLastLeftStart[client] = tickcount;
}
if (!(turnbindsOldButtons[client] & IN_RIGHT) && (buttons & IN_RIGHT))
{
turnbindsLastRightStart[client] = tickcount;
}
turnbindsOldButtons[client] = buttons;
}
}
// =====[ PLAYER COLLISION ]=====
void OnPlayerSpawn_PlayerCollision(int client)
{
// Let players go through other players
SetEntProp(client, Prop_Send, "m_CollisionGroup", GOKZ_COLLISION_GROUP_STANDARD);
}
void OnSetModel_PlayerCollision(int client)
{
// Fix custom models temporarily changing player collisions
SetEntPropVector(client, Prop_Data, "m_vecMins", PLAYER_MINS);
if (GetEntityFlags(client) & FL_DUCKING == 0)
{
SetEntPropVector(client, Prop_Data, "m_vecMaxs", PLAYER_MAXS);
}
else
{
SetEntPropVector(client, Prop_Data, "m_vecMaxs", PLAYER_MAXS_DUCKED);
}
}
// =====[ FORCE SV_FULL_ALLTALK 1 ]=====
void OnRoundStart_ForceAllTalk()
{
gCV_sv_full_alltalk.BoolValue = true;
}
// =====[ ERROR SOUNDS ]=====
#define SOUND_ERROR "buttons/button10.wav"
void PlayErrorSound(int client)
{
if (GOKZ_GetCoreOption(client, Option_ErrorSounds) == ErrorSounds_Enabled)
{
GOKZ_EmitSoundToClient(client, SOUND_ERROR, _, "Error");
}
}
// =====[ STOP SOUNDS ]=====
Action OnNormalSound_StopSounds(int entity)
{
char className[20];
GetEntityClassname(entity, className, sizeof(className));
if (StrEqual(className, "func_button", false))
{
return Plugin_Handled; // No sounds directly from func_button
}
return Plugin_Continue;
}
// =====[ JOIN TEAM HANDLING ]=====
static bool hasSavedPosition[MAXPLAYERS + 1];
static float savedOrigin[MAXPLAYERS + 1][3];
static float savedAngles[MAXPLAYERS + 1][3];
static bool savedOnLadder[MAXPLAYERS + 1];
void OnClientPutInServer_JoinTeam(int client)
{
// Automatically put the player on a team if he doesn't choose one.
// The mp_force_pick_time convar is the built in way to do this, but that obviously
// does not call GOKZ_JoinTeam which includes a fix for spawning in the void when
// there is no valid spawns available.
CreateTimer(12.0, Timer_ForceJoinTeam, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
hasSavedPosition[client] = false;
}
public Action Timer_ForceJoinTeam(Handle timer, int userid)
{
int client = GetClientOfUserId(userid);
if (IsValidClient(client))
{
int team = GetClientTeam(client);
if (team == CS_TEAM_NONE)
{
GOKZ_JoinTeam(client, CS_TEAM_SPECTATOR, false);
}
}
return Plugin_Stop;
}
void OnTimerStart_JoinTeam(int client)
{
hasSavedPosition[client] = false;
}
void JoinTeam(int client, int newTeam, bool restorePos, bool forceBroadcast = false)
{
KZPlayer player = KZPlayer(client);
int currentTeam = GetClientTeam(client);
// Don't use CS_TEAM_NONE
if (newTeam == CS_TEAM_NONE)
{
newTeam = CS_TEAM_SPECTATOR;
}
if (newTeam == CS_TEAM_SPECTATOR && currentTeam != CS_TEAM_SPECTATOR)
{
if (currentTeam != CS_TEAM_NONE)
{
player.GetOrigin(savedOrigin[client]);
player.GetEyeAngles(savedAngles[client]);
savedOnLadder[client] = player.Movetype == MOVETYPE_LADDER;
hasSavedPosition[client] = true;
}
if (!player.Paused && !player.CanPause)
{
player.StopTimer();
}
ChangeClientTeam(client, CS_TEAM_SPECTATOR);
Call_GOKZ_OnJoinTeam(client, newTeam);
}
else if (newTeam == CS_TEAM_CT && currentTeam != CS_TEAM_CT
|| newTeam == CS_TEAM_T && currentTeam != CS_TEAM_T)
{
ForcePlayerSuicide(client);
CS_SwitchTeam(client, newTeam);
CS_RespawnPlayer(client);
if (restorePos && hasSavedPosition[client])
{
TeleportPlayer(client, savedOrigin[client], savedAngles[client]);
if (savedOnLadder[client])
{
player.Movetype = MOVETYPE_LADDER;
}
}
else
{
player.StopTimer();
// Just joining a team alone can put you into weird invalid spawns.
// Need to teleport the player to a valid one.
float spawnOrigin[3];
float spawnAngles[3];
GetValidSpawn(spawnOrigin, spawnAngles);
TeleportPlayer(client, spawnOrigin, spawnAngles);
}
hasSavedPosition[client] = false;
Call_GOKZ_OnJoinTeam(client, newTeam);
}
else if (forceBroadcast)
{
Call_GOKZ_OnJoinTeam(client, newTeam);
}
}
void SendFakeTeamEvent(int client)
{
// Send a fake event to close the team menu
Event event = CreateEvent("player_team");
event.SetInt("userid", GetClientUserId(client));
event.FireToClient(client);
event.Cancel();
}
// =====[ VALID JUMP TRACKING ]=====
/*
Valid jump tracking is intended to detect when the player
has performed a normal jump that hasn't been affected by
(unexpected) teleports or other cases that may result in
the player becoming airborne, such as spawning.
There are ways to trick the plugin, but it is rather
unlikely to happen during normal gameplay.
*/
static bool validJump[MAXPLAYERS + 1];
static float validJumpTeleportOrigin[MAXPLAYERS + 1][3];
static int lastInvalidatedTick[MAXPLAYERS + 1];
bool GetValidJump(int client)
{
return validJump[client];
}
static void InvalidateJump(int client)
{
lastInvalidatedTick[client] = GetGameTickCount();
if (validJump[client])
{
validJump[client] = false;
Call_GOKZ_OnJumpInvalidated(client);
}
}
void OnStopTouchGround_ValidJump(int client, bool jumped, bool ladderJump, bool jumpbug)
{
if (Movement_GetMovetype(client) == MOVETYPE_WALK && lastInvalidatedTick[client] != GetGameTickCount())
{
validJump[client] = true;
Call_GOKZ_OnJumpValidated(client, jumped, ladderJump, jumpbug);
}
else
{
InvalidateJump(client);
}
}
void OnPlayerRunCmdPost_ValidJump(int client)
{
if (gB_VelocityTeleported[client] || gB_OriginTeleported[client])
{
InvalidateJump(client);
}
}
void OnChangeMovetype_ValidJump(int client, MoveType oldMovetype, MoveType newMovetype)
{
if (oldMovetype == MOVETYPE_LADDER && newMovetype == MOVETYPE_WALK && lastInvalidatedTick[client] != GetGameTickCount()) // Ladderjump
{
validJump[client] = true;
Call_GOKZ_OnJumpValidated(client, false, true, false);
}
else
{
InvalidateJump(client);
}
}
void OnClientDisconnect_ValidJump(int client)
{
InvalidateJump(client);
}
void OnPlayerSpawn_ValidJump(int client)
{
// That should definitely be out of bounds
CopyVector({ 40000.0, 40000.0, 40000.0 }, validJumpTeleportOrigin[client]);
InvalidateJump(client);
}
void OnPlayerDeath_ValidJump(int client)
{
InvalidateJump(client);
}
void OnValidOriginChange_ValidJump(int client, const float origin[3])
{
CopyVector(origin, validJumpTeleportOrigin[client]);
}
void OnTeleport_ValidJump(int client)
{
float origin[3];
Movement_GetOrigin(client, origin);
if (gB_OriginTeleported[client] && GetVectorDistance(validJumpTeleportOrigin[client], origin, true) <= EPSILON)
{
gB_OriginTeleported[client] = false;
CopyVector({ 40000.0, 40000.0, 40000.0 }, validJumpTeleportOrigin[client]);
return;
}
if (gB_OriginTeleported[client])
{
InvalidateJump(client);
Call_GOKZ_OnTeleport(client);
}
if (gB_VelocityTeleported[client])
{
InvalidateJump(client);
}
}
// =====[ FIRST SPAWN ]=====
static bool hasSpawned[MAXPLAYERS + 1];
void OnClientPutInServer_FirstSpawn(int client)
{
hasSpawned[client] = false;
}
void OnPlayerSpawn_FirstSpawn(int client)
{
int team = GetClientTeam(client);
if (!hasSpawned[client] && (team == CS_TEAM_CT || team == CS_TEAM_T))
{
hasSpawned[client] = true;
Call_GOKZ_OnFirstSpawn(client);
}
}
// =====[ TIME LIMIT ]=====
void OnConfigsExecuted_TimeLimit()
{
CreateTimer(1.0, Timer_TimeLimit, _, TIMER_REPEAT);
}
public Action Timer_TimeLimit(Handle timer)
{
int timelimit;
if (!GetMapTimeLimit(timelimit) || timelimit == 0)
{
return Plugin_Continue;
}
int timeleft;
// Check for less than -1 in case we miss 0 - ignore -1 because that means infinite time limit
if (GetMapTimeLeft(timeleft) && (timeleft == 0 || timeleft < -1))
{
CreateTimer(5.0, Timer_EndRound); // End the round after a delay or it won't end the map
return Plugin_Stop;
}
return Plugin_Continue;
}
public Action Timer_EndRound(Handle timer)
{
CS_TerminateRound(1.0, CSRoundEnd_Draw, true);
return Plugin_Continue;
}
// =====[ COURSE REGISTER ]=====
static bool startRegistered[GOKZ_MAX_COURSES];
static bool endRegistered[GOKZ_MAX_COURSES];
static bool courseRegistered[GOKZ_MAX_COURSES];
bool GetCourseRegistered(int course)
{
return courseRegistered[course];
}
void RegisterCourseStart(int course)
{
startRegistered[course] = true;
TryRegisterCourse(course);
}
void RegisterCourseEnd(int course)
{
endRegistered[course] = true;
TryRegisterCourse(course);
}
void OnMapStart_CourseRegister()
{
for (int course = 0; course < GOKZ_MAX_COURSES; course++)
{
courseRegistered[course] = false;
}
}
static void TryRegisterCourse(int course)
{
if (!courseRegistered[course] && startRegistered[course] && endRegistered[course])
{
courseRegistered[course] = true;
Call_GOKZ_OnCourseRegistered(course);
}
}
// =====[ SPAWN FIXES ]=====
void OnMapStart_FixMissingSpawns()
{
int tSpawn = FindEntityByClassname(-1, "info_player_terrorist");
int ctSpawn = FindEntityByClassname(-1, "info_player_counterterrorist");
if (tSpawn == -1 && ctSpawn == -1)
{
LogMessage("Couldn't fix spawns because none exist.");
return;
}
if (tSpawn == -1 || ctSpawn == -1)
{
float origin[3], angles[3];
GetValidSpawn(origin, angles);
int newSpawn = CreateEntityByName((tSpawn == -1) ? "info_player_terrorist" : "info_player_counterterrorist");
if (DispatchSpawn(newSpawn))
{
TeleportEntity(newSpawn, origin, angles, NULL_VECTOR);
}
}
}
// =====[ BUTTONS ]=====
void OnClientPreThinkPost_UseButtons(int client)
{
if (GOKZ_GetCoreOption(client, Option_ButtonThroughPlayers) == ButtonThroughPlayers_Enabled && GetEntProp(client, Prop_Data, "m_afButtonPressed") & IN_USE)
{
int entity = FindUseEntity(client);
if (entity != -1)
{
AcceptEntityInput(entity, "Use", client, client, 1);
}
}
}
static int FindUseEntity(int client)
{
float fwd[3];
float angles[3];
GetClientEyeAngles(client, angles);
GetAngleVectors(angles, fwd, NULL_VECTOR, NULL_VECTOR);
Handle trace;
float eyeOrigin[3];
GetClientEyePosition(client, eyeOrigin);
int useableContents = (MASK_NPCSOLID_BRUSHONLY | MASK_OPAQUE_AND_NPCS) & ~CONTENTS_OPAQUE;
float endpos[3];
// Check if +use trace collide with a player first, so we don't activate any button twice
trace = TR_TraceRayFilterEx(eyeOrigin, angles, useableContents, RayType_Infinite, TRFOtherPlayersOnly, client);
if (TR_DidHit(trace))
{
int ent = TR_GetEntityIndex(trace);
if (ent < 1 || ent > MaxClients)
{
return -1;
}
// Search for a button behind it.
trace = TR_TraceRayFilterEx(eyeOrigin, angles, useableContents, RayType_Infinite, TraceEntityFilterPlayers);
if (TR_DidHit(trace))
{
char buffer[20];
ent = TR_GetEntityIndex(trace);
// Make sure that it is a button, and this button activates when pressed.
// If it is not a button, check its parent to see if it is a button.
bool isButton;
while (ent != -1)
{
GetEntityClassname(ent, buffer, sizeof(buffer));
if (StrEqual("func_button", buffer, false) && GetEntProp(ent, Prop_Data, "m_spawnflags") & SF_BUTTON_USE_ACTIVATES)
{
isButton = true;
break;
}
else
{
ent = GetEntPropEnt(ent, Prop_Data, "m_hMoveParent");
}
}
if (isButton)
{
TR_GetEndPosition(endpos, trace);
float delta[3];
for (int i = 0; i < 2; i++)
{
delta[i] = endpos[i] - eyeOrigin[i];
}
// Z distance is treated differently.
float m_vecMins[3];
float m_vecMaxs[3];
float m_vecOrigin[3];
GetEntPropVector(ent, Prop_Send, "m_vecOrigin", m_vecOrigin);
GetEntPropVector(ent, Prop_Send, "m_vecMins", m_vecMins);
GetEntPropVector(ent, Prop_Send, "m_vecMaxs", m_vecMaxs);
delta[2] = IntervalDistance(endpos[2], m_vecOrigin[2] + m_vecMins[2], m_vecOrigin[2] + m_vecMaxs[2]);
if (GetVectorLength(delta) < 80.0)
{
return ent;
}
}
}
}
int nearestEntity;
float nearestPoint[3];
float nearestDist = FLOAT_MAX;
ArrayList entities = new ArrayList();
TR_EnumerateEntitiesSphere(eyeOrigin, 80.0, 1<<5, AddEntities, entities);
for (int i = 0; i < entities.Length; i++)
{
char buffer[64];
int ent = entities.Get(i);
GetEntityClassname(ent, buffer, sizeof(buffer));
// Check if the entity is a button and it is pressable.
if (StrEqual("func_button", buffer, false) && GetEntProp(ent, Prop_Data, "m_spawnflags") & SF_BUTTON_USE_ACTIVATES)
{
float point[3];
CalcNearestPoint(ent, eyeOrigin, point);
float dir[3];
for (int j = 0; j < 3; j++)
{
dir[j] = point[j] - eyeOrigin[2];
}
// Check the maximum angle the player can be away from the button.
float minimumDot = GetEntPropFloat(ent, Prop_Send, "m_flUseLookAtAngle");
NormalizeVector(dir, dir);
float dot = GetVectorDotProduct(dir, fwd);
if (dot < minimumDot)
{
continue;
}
float dist = CalcDistanceToLine(point, eyeOrigin, fwd);
if (dist < nearestDist)
{
trace = TR_TraceRayFilterEx(eyeOrigin, point, useableContents, RayType_EndPoint, TraceEntityFilterPlayers);
if (TR_GetFraction(trace) == 1.0 || TR_GetEntityIndex(trace) == ent)
{
CopyVector(point, nearestPoint);
nearestDist = dist;
nearestEntity = ent;
}
}
}
}
// We found the closest button, but we still need to check if there is a player in front of it or not.
// In the case that there isn't a player inbetween, we don't return the entity index, because that button will be pressed by the game function anyway.
// If there is, we will press two buttons at once, the "right" button found by this function and the "wrong" button that we only happen to press because
// there is a player in the way.
trace = TR_TraceRayFilterEx(eyeOrigin, nearestPoint, useableContents, RayType_EndPoint, TRFOtherPlayersOnly);
if (TR_DidHit(trace))
{
return nearestEntity;
}
return -1;
}
public bool AddEntities(int entity, ArrayList entities)
{
entities.Push(entity);
return true;
}
static float IntervalDistance(float x, float x0, float x1)
{
if (x0 > x1)
{
float tmp = x0;
x0 = x1;
x1 = tmp;
}
if (x < x0)
{
return x0 - x;
}
else if (x > x1)
{
return x - x1;
}
return 0.0;
}
// TraceRay filter for other players exclusively.
public bool TRFOtherPlayersOnly(int entity, int contentmask, int client)
{
return (0 < entity <= MaxClients) && (entity != client);
}
// =====[ SAFE MODE ]=====
void ToggleNubSafeGuard(int client)
{
if (GOKZ_GetCoreOption(client, Option_Safeguard) == Safeguard_EnabledNUB)
{
GOKZ_SetCoreOption(client, Option_Safeguard, Safeguard_Disabled);
}
else
{
GOKZ_SetCoreOption(client, Option_Safeguard, Safeguard_EnabledNUB);
}
}
void ToggleProSafeGuard(int client)
{
if (GOKZ_GetCoreOption(client, Option_Safeguard) == Safeguard_EnabledPRO)
{
GOKZ_SetCoreOption(client, Option_Safeguard, Safeguard_Disabled);
}
else
{
GOKZ_SetCoreOption(client, Option_Safeguard, Safeguard_EnabledPRO);
}
}
|