-
Notifications
You must be signed in to change notification settings - Fork 14
/
mge.sp
5913 lines (5033 loc) · 219 KB
/
mge.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
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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma semicolon 1 // Force strict semicolon mode.
#pragma newdecls required
// ====[ INCLUDES ]====================================================
#include <sourcemod>
#include <tf2_stocks>
#include <entity_prop_stocks>
#include <sdkhooks>
#include <morecolors>
// ====[ CONSTANTS ]===================================================
#define PL_VERSION "3.0.1"
#define MAXARENAS 63
#define MAXSPAWNS 15
#define HUDFADEOUTTIME 120.0
#define MAPCONFIGFILE "configs/mgemod_spawns.cfg"
#pragma newdecls required
// arena slots
enum
{
SLOT_ONE = 1,
SLOT_TWO,
SLOT_THREE,
SLOT_FOUR
};
// teams
enum
{
TEAM_NONE = 0,
TEAM_SPEC,
TEAM_RED,
TEAM_BLU
};
//arena status
enum
{
AS_IDLE = 0,
AS_PRECOUNTDOWN,
AS_COUNTDOWN,
AS_FIGHT,
AS_AFTERFIGHT,
AS_REPORTED
};
// for neutral cap points
#define NEUTRAL 1
//sounds
#define STOCK_SOUND_COUNT 24
//
#define DEFAULT_CDTIME 3
//
#define MODEL_POINT "models/props_gameplay/cap_point_base.mdl"
#define MODEL_BRIEFCASE "models/flag/briefcase.mdl"
#define MODEL_AMMOPACK "models/items/ammopack_small.mdl"
#define MODEL_LARGE_AMMOPACK "models/items/ammopack_large.mdl"
//#define DEBUG_LOG
// ====[ VARIABLES ]===================================================
// Handle, String, Float, Bool, NUM, TFCT
bool
g_bNoStats,
g_bNoDisplayRating;
// HUD Handles
Handle
hm_HP,
hm_Score,
hm_TeammateHP,
hm_KothTimerBLU,
hm_KothTimerRED,
hm_KothCap;
// Global Variables
char g_sMapName[64],
g_spawnFile[128];
bool g_bBlockFallDamage,
g_bUseSQLite,
g_bAutoCvar;
int
g_iDefaultFragLimit,
g_iAirshotHeight = 80;
// Database
Database db; // Connection to SQL database.
Handle g_hDBReconnectTimer;
char g_sDBConfig[64];
int g_iReconnectInterval;
// Global CVar Handles
ConVar
gcvar_WfP,
gcvar_fragLimit,
gcvar_allowedClasses,
gcvar_blockFallDamage,
gcvar_dbConfig,
gcvar_midairHP,
gcvar_airshotHeight,
gcvar_RocketForceX,
gcvar_RocketForceY,
gcvar_RocketForceZ,
gcvar_autoCvar,
gcvar_bballParticle_red,
gcvar_bballParticle_blue,
gcvar_noDisplayRating,
gcvar_stats,
gcvar_reconnectInterval,
gcvar_spawnFile;
// Classes
bool g_tfctClassAllowed[10];
// Arena Vars
Handle g_tKothTimer [MAXARENAS + 1];
char
g_sArenaName [MAXARENAS + 1][64],
// from chillymge
g_sArenaOriginalName [MAXARENAS + 1][64],
// Cap point trggier name for KOTH
g_sArenaCapTrigger [MAXARENAS + 1][64],
// Cap point name for KOTH
g_sArenaCap [MAXARENAS + 1][64];
float
g_fArenaSpawnOrigin [MAXARENAS + 1][MAXSPAWNS+1][3],
g_fArenaSpawnAngles [MAXARENAS + 1][MAXSPAWNS+1][3],
g_fArenaHPRatio [MAXARENAS + 1],
g_fArenaMinSpawnDist [MAXARENAS + 1],
g_fArenaRespawnTime [MAXARENAS + 1],
g_fKothCappedPercent [MAXARENAS + 1],
g_fTotalTime [MAXARENAS + 1],
g_fCappedTime [MAXARENAS + 1];
bool
g_bArenaAmmomod [MAXARENAS + 1],
g_bArenaMidair [MAXARENAS + 1],
g_bArenaMGE [MAXARENAS + 1],
g_bArenaEndif [MAXARENAS + 1],
g_bArenaBBall [MAXARENAS + 1],
g_bVisibleHoops [MAXARENAS + 1],
g_bArenaInfAmmo [MAXARENAS + 1],
g_bFourPersonArena [MAXARENAS + 1],
g_bArenaAllowChange [MAXARENAS + 1],
g_bArenaAllowKoth [MAXARENAS + 1],
g_bArenaKothTeamSpawn [MAXARENAS + 1],
g_bArenaShowHPToPlayers [MAXARENAS + 1],
g_bArenaUltiduo [MAXARENAS + 1],
g_bArenaKoth [MAXARENAS + 1],
g_bPlayerTouchPoint [MAXARENAS + 1][5],
g_bArenaTurris [MAXARENAS + 1],
g_bOvertimePlayed [MAXARENAS + 1][4],
g_bTimerRunning [MAXARENAS + 1],
g_bArenaHasCap [MAXARENAS + 1],
g_bArenaHasCapTrigger [MAXARENAS + 1],
g_bArenaBoostVectors [MAXARENAS + 1];
int
g_iArenaCount,
g_iArenaAirshotHeight [MAXARENAS + 1],
g_iCappingTeam [MAXARENAS + 1],
g_iCapturePoint [MAXARENAS + 1],
g_iDefaultCapTime [MAXARENAS + 1],
// [what arena is the cap point in][Team Red or Team Blu Time left]
g_iKothTimer [MAXARENAS + 1][4],
// 1 = neutral, 2 = RED, 3 = BLU
g_iPointState [MAXARENAS + 1],
g_iArenaScore [MAXARENAS + 1][3],
g_iArenaQueue [MAXARENAS + 1][MAXPLAYERS + 1],
g_iArenaStatus [MAXARENAS + 1],
// countdown to round start
g_iArenaCd [MAXARENAS + 1],
g_iArenaFraglimit [MAXARENAS + 1],
g_iArenaMgelimit [MAXARENAS + 1],
g_iArenaCaplimit [MAXARENAS + 1],
g_iArenaMinRating [MAXARENAS + 1],
g_iArenaMaxRating [MAXARENAS + 1],
g_iArenaCdTime [MAXARENAS + 1],
g_iArenaSpawns [MAXARENAS + 1],
// [What arena the hoop is in][Hoop 1 or Hoop 2]
g_iBBallHoop [MAXARENAS + 1][3],
g_iBBallIntel [MAXARENAS + 1],
g_iArenaEarlyLeave [MAXARENAS + 1],
g_iELOMenuPage [MAXARENAS + 1];
//int g_tfctArenaAllowedClasses[MAXARENAS + 1][TFClassType+1];
bool g_tfctArenaAllowedClasses[MAXARENAS + 1][10];
// Player vars
Handle g_hWelcomeTimer [MAXPLAYERS + 1];
char g_sPlayerSteamID [MAXPLAYERS + 1][32]; //saving steamid
bool
g_bPlayerTakenDirectHit [MAXPLAYERS + 1],//player was hit directly
g_bPlayerRestoringAmmo [MAXPLAYERS + 1],//player is awaiting full ammo restore
g_bPlayerHasIntel [MAXPLAYERS + 1],
g_bHitBlip [MAXPLAYERS + 1],
g_bShowHud [MAXPLAYERS + 1] = true,
g_iPlayerWaiting [MAXPLAYERS + 1],
g_bCanPlayerSwap [MAXPLAYERS + 1],
g_bCanPlayerGetIntel [MAXPLAYERS + 1];
int
g_iPlayerArena [MAXPLAYERS + 1],
g_iPlayerSlot [MAXPLAYERS + 1],
g_iPlayerHP [MAXPLAYERS + 1], //true HP of players
g_iPlayerSpecTarget [MAXPLAYERS + 1],
g_iPlayerMaxHP [MAXPLAYERS + 1],
g_iClientParticle [MAXPLAYERS + 1],
g_iPlayerClip [MAXPLAYERS + 1][3],
g_iPlayerWins [MAXPLAYERS + 1],
g_iPlayerLosses [MAXPLAYERS + 1],
g_iPlayerRating [MAXPLAYERS + 1],
g_iPlayerHandicap [MAXPLAYERS + 1];
TFClassType g_tfctPlayerClass[MAXPLAYERS + 1];
// Bot things
bool g_bPlayerAskedForBot[MAXPLAYERS + 1];
// Midair
int g_iMidairHP;
// Debug log
char g_sLogFile[PLATFORM_MAX_PATH];
// Endif
float
g_fRocketForceX,
g_fRocketForceY,
g_fRocketForceZ;
// Bball
char
g_sBBallParticleRed[64],
g_sBBallParticleBlue[64];
static const char stockSounds[][] = // Sounds that do not need to be downloaded.
{
"vo/intel_teamcaptured.wav",
"vo/intel_teamdropped.wav",
"vo/intel_teamstolen.wav",
"vo/intel_enemycaptured.wav",
"vo/intel_enemydropped.wav",
"vo/intel_enemystolen.wav",
"vo/announcer_ends_5sec.wav",
"vo/announcer_ends_4sec.wav",
"vo/announcer_ends_3sec.wav",
"vo/announcer_ends_2sec.wav",
"vo/announcer_ends_1sec.wav",
"vo/announcer_ends_10sec.wav",
"vo/announcer_control_point_warning.wav",
"vo/announcer_control_point_warning2.wav",
"vo/announcer_control_point_warning3.wav",
"vo/announcer_overtime.wav",
"vo/announcer_overtime2.wav",
"vo/announcer_overtime3.wav",
"vo/announcer_overtime4.wav",
"vo/announcer_we_captured_control.wav",
"vo/announcer_we_lost_control.wav",
"items/spawn_item.wav",
"vo/announcer_victory.wav",
"vo/announcer_you_failed.wav"
};
public Plugin myinfo =
{
name = "MGE",
author = "Originally by Lange & Cprice; based on kAmmomod by Krolus - maintained by sappho.io, PepperKick, and others",
description = "Duel mod for TF2 with realistic game situations.",
version = PL_VERSION,
url = "https://github.com/sapphonie/MGEMod"
}
/*
** ------------------------------------------------------------------
** ____ ______ __ _
** / __ \____ / ____/__ ______ _____/ /_(_)____ ____ _____
** / / / / __ \ / /_ / / / / __ \/ ___/ __/ // __ \/ __ \/ ___/
** / /_/ / / / / / __/ / /_/ / / / / /__/ /_/ // /_/ / / / (__ )
** \____/_/ /_/ /_/ \__,_/_/ /_/\___/\__/_/ \____/_/ /_/____/
**
** ------------------------------------------------------------------
**/
/* OnPluginStart()
*
* When the plugin is loaded.
* Cvars, variables, and console commands are initialzed here.
* -------------------------------------------------------------------------- */
public void OnPluginStart()
{
LoadTranslations("common.phrases");
LoadTranslations("mgemod.phrases");
//ConVars
CreateConVar("sm_mgemod_version", PL_VERSION, "MGEMod version", FCVAR_SPONLY | FCVAR_NOTIFY);
gcvar_fragLimit = CreateConVar("mgemod_fraglimit", "3", "Default frag limit in duel", FCVAR_NONE, true, 1.0);
gcvar_allowedClasses = CreateConVar("mgemod_allowed_classes", "soldier demoman scout", "Classes that players allowed to choose by default");
gcvar_blockFallDamage = CreateConVar("mgemod_blockdmg_fall", "0", "Block falldamage? (0 = Disabled)", FCVAR_NONE, true, 0.0, true, 1.0);
gcvar_dbConfig = CreateConVar("mgemod_dbconfig", "mgemod", "Name of database config");
gcvar_stats = CreateConVar("mgemod_stats", "1", "Enable/Disable stats.");
gcvar_airshotHeight = CreateConVar("mgemod_airshot_height", "80", "The minimum height at which it will count airshot", FCVAR_NONE, true, 10.0, true, 500.0);
gcvar_RocketForceX = CreateConVar("mgemod_endif_force_x", "1.1", "The amount by which to multiply the X push force on Endif.", FCVAR_NONE, true, 1.0, true, 10.0);
gcvar_RocketForceY = CreateConVar("mgemod_endif_force_y", "1.1", "The amount by which to multiply the Y push force on Endif.", FCVAR_NONE, true, 1.0, true, 10.0);
gcvar_RocketForceZ = CreateConVar("mgemod_endif_force_z", "2.15", "The amount by which to multiply the Z push force on Endif.", FCVAR_NONE, true, 1.0, true, 10.0);
gcvar_autoCvar = CreateConVar("mgemod_autocvar", "1", "Automatically set recommended game cvars? (0 = Disabled)", FCVAR_NONE, true, 0.0, true, 1.0);
gcvar_bballParticle_red = CreateConVar("mgemod_bball_particle_red", "player_intel_trail_red", "Particle effect to attach to Red players in BBall.");
gcvar_bballParticle_blue = CreateConVar("mgemod_bball_particle_blue", "player_intel_trail_blue", "Particle effect to attach to Blue players in BBall.");
gcvar_WfP = FindConVar("mp_waitingforplayers_cancel");
gcvar_midairHP = CreateConVar("mgemod_midair_hp", "5", "", FCVAR_NONE, true, 1.0);
gcvar_noDisplayRating = CreateConVar("mgemod_hide_rating", "0", "Hide the in-game display of rating points. They will still be tracked in the database.");
gcvar_reconnectInterval = CreateConVar("mgemod_reconnect_interval", "5", "How long (in minutes) to wait between database reconnection attempts.");
gcvar_spawnFile = CreateConVar("mgemod_spawnfile", MAPCONFIGFILE, "Spawn file");
// Populate global variables with their corresponding convar values.
g_iDefaultFragLimit = gcvar_fragLimit.IntValue;
g_bBlockFallDamage = gcvar_blockFallDamage.IntValue ? true : false;
g_iAirshotHeight = gcvar_airshotHeight.IntValue;
g_iMidairHP = gcvar_midairHP.IntValue;
g_bAutoCvar = gcvar_autoCvar.IntValue ? true : false;
g_bNoDisplayRating = gcvar_noDisplayRating.IntValue ? true : false;
g_iReconnectInterval = gcvar_reconnectInterval.IntValue;
gcvar_dbConfig.GetString(g_sDBConfig, sizeof(g_sDBConfig));
gcvar_bballParticle_red.GetString(g_sBBallParticleRed, sizeof(g_sBBallParticleRed));
gcvar_bballParticle_blue.GetString(g_sBBallParticleBlue, sizeof(g_sBBallParticleBlue));
gcvar_spawnFile.GetString(g_spawnFile, sizeof(g_spawnFile));
g_bNoStats = gcvar_stats.BoolValue ? false : true;
g_fRocketForceX = gcvar_RocketForceX.FloatValue;
g_fRocketForceY = gcvar_RocketForceY.FloatValue;
g_fRocketForceZ = gcvar_RocketForceZ.FloatValue;
for (int i = 0; i < MAXARENAS + 1; ++i)
{
g_bTimerRunning[i] = false;
g_fCappedTime[i] = 0.0;
g_fTotalTime[i] = 0.0;
}
// Parse default list of allowed classes.
ParseAllowedClasses("", g_tfctClassAllowed);
// Only connect to the SQL DB if stats are enabled.
if (!g_bNoStats)
{
PrepareSQL();
}
// Hook convar changes.
gcvar_spawnFile.AddChangeHook(handler_ConVarChange);
gcvar_fragLimit.AddChangeHook(handler_ConVarChange);
gcvar_allowedClasses.AddChangeHook(handler_ConVarChange);
gcvar_blockFallDamage.AddChangeHook(handler_ConVarChange);
gcvar_dbConfig.AddChangeHook(handler_ConVarChange);
gcvar_stats.AddChangeHook(handler_ConVarChange);
gcvar_airshotHeight.AddChangeHook(handler_ConVarChange);
gcvar_midairHP.AddChangeHook(handler_ConVarChange);
gcvar_RocketForceX.AddChangeHook(handler_ConVarChange);
gcvar_RocketForceY.AddChangeHook(handler_ConVarChange);
gcvar_RocketForceZ.AddChangeHook(handler_ConVarChange);
gcvar_autoCvar.AddChangeHook(handler_ConVarChange);
gcvar_bballParticle_red.AddChangeHook(handler_ConVarChange);
gcvar_bballParticle_blue.AddChangeHook(handler_ConVarChange);
gcvar_noDisplayRating.AddChangeHook(handler_ConVarChange);
gcvar_reconnectInterval.AddChangeHook(handler_ConVarChange);
// Create/register client commands.
RegConsoleCmd("mgemod", Command_Menu, "MGEMod Menu");
RegConsoleCmd("add", Command_Menu, "Usage: add <arena number/arena name>. Add to an arena.");
RegConsoleCmd("swap", Command_Swap, "Ask your teammate to swap classes with you in ultiduo");
RegConsoleCmd("remove", Command_Remove, "Remove from current arena.");
RegConsoleCmd("top5", Command_Top5, "Display the Top 5 players.");
RegConsoleCmd("hitblip", Command_ToogleHitblip, "Toggle hitblip!");
RegConsoleCmd("hud", Command_ToggleHud, "Toggle text hud.");
RegConsoleCmd("hidehud", Command_ToggleHud, "Toggle text hud. (alias)");
RegConsoleCmd("rank", Command_Rank, "Usage: rank <player name>. Show that player's rank.");
RegConsoleCmd("stats", Command_Rank, "Alias for \"rank\".");
RegConsoleCmd("mgehelp", Command_Help);
RegConsoleCmd("first", Command_First, "Join the first available arena.");
RegConsoleCmd("handicap", Command_Handicap, "Reduce your maximum HP. Type '!handicap off' to disable.");
RegConsoleCmd("spec_next", Command_Spec);
RegConsoleCmd("spec_prev", Command_Spec);
RegConsoleCmd("joinclass", Command_JoinClass);
RegAdminCmd("loc", Command_Loc, ADMFLAG_BAN, "Shows client origin and angle vectors");
RegAdminCmd("botme", Command_AddBot, ADMFLAG_BAN, "Add bot to your arena");
RegAdminCmd("conntest", Command_ConnectionTest, ADMFLAG_BAN, "MySQL connection test");
// from chillymge
RegConsoleCmd("1v1", Command_OneVsOne, "Change arena to 1v1");
RegConsoleCmd("2v2", Command_TwoVsTwo, "Change arena to 2v2");
RegAdminCmd("koth", Command_Koth, ADMFLAG_BAN, "Change arena to KOTH Mode");
RegAdminCmd("mge", Command_Mge, ADMFLAG_BAN, "Change arena to MGE Mode");
AddCommandListener(Command_DropItem, "dropitem");
// Create the HUD text handles for later use.
hm_HP = CreateHudSynchronizer();
hm_Score = CreateHudSynchronizer();
hm_KothTimerBLU = CreateHudSynchronizer();
hm_KothTimerRED = CreateHudSynchronizer();
hm_KothCap = CreateHudSynchronizer();
hm_TeammateHP = CreateHudSynchronizer();
// Set up the log file for debug logging.
BuildPath(Path_SM, g_sLogFile, sizeof(g_sLogFile), "logs/mgemod.log");
/* This is here in the event of the plugin being hot-loaded while players are in the server.
Should probably delete this, as the rest of the code doesn't really support hot-loading. */
PrintToChatAll("[MGEMod] Plugin reloaded. Slaying all players to avoid bugs.");
for (int i = 1; i <= MaxClients; i++)
{
if (IsValidClient(i))
{
ForcePlayerSuicide(i);
OnClientPostAdminCheck(i);
g_bCanPlayerSwap[i] = true;
g_bCanPlayerGetIntel[i] = true;
}
}
}
/* OnMapStart()
*
* When the map starts.
* Sounds, models, and spawns are loaded here.
* Most events are hooked here as well.
* -------------------------------------------------------------------------- */
public void OnMapStart()
{
for (int i = 0; i < STOCK_SOUND_COUNT; i++)/* Stock sounds are considered mandatory. */
PrecacheSound(stockSounds[i], true);
// Models. These are used for the artifical flag in BBall.
PrecacheModel(MODEL_BRIEFCASE, true);
PrecacheModel(MODEL_AMMOPACK, true);
//Used for ultiduo/koth arenas
PrecacheModel(MODEL_POINT, true);
g_bNoStats = gcvar_stats.BoolValue ? false : true; /* Reset this variable, since it is forced to false during Event_WinPanel */
// Spawns
int isMapAm = LoadSpawnPoints();
if (isMapAm)
{
for (int i = 0; i <= g_iArenaCount; i++)
{
if (g_bArenaBBall[i])
{
g_iBBallHoop[i][SLOT_ONE] = -1;
g_iBBallHoop[i][SLOT_TWO] = -1;
g_iBBallIntel[i] = -1;
}
if (g_bArenaKoth[i])
{
g_iCapturePoint[i] = -1;
}
}
CreateTimer(1.0, Timer_SpecHudToAllArenas, _, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT);
if (g_bAutoCvar)
{
/* MGEMod often creates situtations where the number of players on RED and BLU will be uneven.
If the server tries to force a player to a different team due to autobalance being on, it will interfere with MGEMod's queue system.
These cvar settings are considered mandatory for MGEMod. */
ServerCommand("mp_autoteambalance 0");
ServerCommand("mp_teams_unbalance_limit 32");
ServerCommand("mp_tournament 0");
LogMessage("AutoCvar: Setting mp_autoteambalance 0, mp_teams_unbalance_limit 32, & mp_tournament 0");
}
HookEvent("player_death", Event_PlayerDeath, EventHookMode_Pre);
HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
HookEvent("player_hurt", Event_PlayerHurt, EventHookMode_Pre);
HookEvent("player_team", Event_PlayerTeam, EventHookMode_Pre);
HookEvent("teamplay_round_start", Event_RoundStart, EventHookMode_Post);
HookEvent("teamplay_win_panel", Event_WinPanel, EventHookMode_Post);
AddNormalSoundHook(sound_hook);
} else {
SetFailState("Map not supported. MGEMod disabled.");
}
for (int i = 0; i < MAXPLAYERS; i++)
{
g_iPlayerWaiting[i] = false;
g_bCanPlayerSwap[i] = true;
g_bCanPlayerGetIntel[i] = true;
}
for (int i = 0; i < MAXARENAS; i++)
{
g_bTimerRunning[i] = false;
g_fCappedTime[i] = 0.0;
g_fTotalTime[i] = 0.0;
}
}
/* OnMapEnd()
*
* When the map ends.
* Repeating timers can be killed here.
* Hooks are removed here.
* -------------------------------------------------------------------------- */
public void OnMapEnd()
{
g_hDBReconnectTimer = null;
g_bNoStats = gcvar_stats.BoolValue ? false : true;
UnhookEvent("player_death", Event_PlayerDeath, EventHookMode_Pre);
UnhookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
UnhookEvent("player_hurt", Event_PlayerHurt, EventHookMode_Pre);
UnhookEvent("player_team", Event_PlayerTeam, EventHookMode_Pre);
UnhookEvent("teamplay_round_start", Event_RoundStart, EventHookMode_Post);
UnhookEvent("teamplay_win_panel", Event_WinPanel, EventHookMode_Post);
RemoveNormalSoundHook(sound_hook);
for (int arena_index = 1; arena_index < g_iArenaCount; arena_index++)
{
if (g_bTimerRunning[arena_index])
{
delete g_tKothTimer[arena_index];
g_bTimerRunning[arena_index] = false;
}
}
}
/* OnEntityCreated(entity, const String:classname[])
*
* When an entity is created.
* This is an SDKHooks forward.
* -------------------------------------------------------------------------- */
public void OnEntityCreated(int entity, const char[] classname)
{
if (StrEqual(classname, "tf_projectile_rocket") || StrEqual(classname, "tf_projectile_pipe"))
SDKHook(entity, SDKHook_Touch, OnProjectileTouch);
}
/* OnProjectileTouch(int entity, int other)
*
* When a projectile is touched.
* This is how direct hits from pipes are rockets are detected.
* -------------------------------------------------------------------------- */
public void OnProjectileTouch(int entity, int other)
{
if (other > 0 && other <= MaxClients)
g_bPlayerTakenDirectHit[other] = true;
}
/* OnClientPostAdminCheck(client)
*
* Called once a client is fully in-game, and authorized with Steam.
* Client-specific variables are initialized here.
* -------------------------------------------------------------------------- */
public void OnClientPostAdminCheck(int client)
{
if (IsFakeClient(client))
{
for (int i = 1; i <= MaxClients; i++)
{
if (g_bPlayerAskedForBot[i])
{
int arena_index = g_iPlayerArena[i];
DataPack pk;
CreateDataTimer(1.5, Timer_AddBotInQueue, pk);
pk.WriteCell(GetClientUserId(client));
pk.WriteCell(arena_index);
g_iPlayerRating[client] = 1551;
g_bPlayerAskedForBot[i] = false;
break;
}
}
}
else
{
ChangeClientTeam(client, TEAM_SPEC);
CreateTimer(5.0, Timer_ShowAdv, GetClientUserId(client)); /* Show advice to type !add in chat */
g_bHitBlip[client] = false;
g_bShowHud[client] = true;
g_bPlayerRestoringAmmo[client] = false;
g_hWelcomeTimer[client] = CreateTimer(15.0, Timer_WelcomePlayer, GetClientUserId(client));
if (!g_bNoStats)
{
char steamid_dirty[31], steamid[64], query[256];
GetClientAuthId(client, AuthId_Steam2, steamid_dirty, sizeof(steamid_dirty));
db.Escape(steamid_dirty, steamid, sizeof(steamid));
strcopy(g_sPlayerSteamID[client], 32, steamid);
Format(query, sizeof(query), "SELECT rating, hitblip, wins, losses FROM mgemod_stats WHERE steamid='%s' LIMIT 1", steamid);
db.Query(T_SQLQueryOnConnect, query, client);
}
}
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}
/* OnClientDisconnect(client)
*
* When a client disconnects from the server.
* Client-specific timers are killed here.
* -------------------------------------------------------------------------- */
public void OnClientDisconnect(int client)
{
// We ignore the kick queue check for this function only so that clients that get kicked still get their elo calculated
if (IsValidClient(client, true) && g_iPlayerArena[client])
{
RemoveFromQueue(client, true);
}
else
{
int
arena_index = g_iPlayerArena[client],
player_slot = g_iPlayerSlot[client],
after_leaver_slot = player_slot + 1,
foe_slot = (player_slot == SLOT_ONE || player_slot == SLOT_THREE) ? SLOT_TWO : SLOT_ONE,
foe = g_iArenaQueue[arena_index][foe_slot];
//Turn all this logic into a helper meathod
int player_teammate, foe2;
if (g_bFourPersonArena[arena_index])
{
player_teammate = getTeammate(client, player_slot, arena_index);
foe2 = getTeammate(foe, foe_slot, arena_index);
}
g_iPlayerArena[client] = 0;
g_iPlayerSlot[client] = 0;
g_iArenaQueue[arena_index][player_slot] = 0;
g_iPlayerHandicap[client] = 0;
if (g_bFourPersonArena[arena_index])
{
if (g_iArenaQueue[arena_index][SLOT_FOUR + 1])
{
int next_client = g_iArenaQueue[arena_index][SLOT_FOUR + 1];
g_iArenaQueue[arena_index][SLOT_FOUR + 1] = 0;
g_iArenaQueue[arena_index][player_slot] = next_client;
g_iPlayerSlot[next_client] = player_slot;
after_leaver_slot = SLOT_FOUR + 2;
char playername[MAX_NAME_LENGTH];
CreateTimer(2.0, Timer_StartDuel, arena_index);
GetClientName(next_client, playername, sizeof(playername));
if (!g_bNoStats && !g_bNoDisplayRating)
MC_PrintToChatAll("%t", "JoinsArena", playername, g_iPlayerRating[next_client], g_sArenaName[arena_index]);
else
MC_PrintToChatAll("%t", "JoinsArenaNoStats", playername, g_sArenaName[arena_index]);
} else {
if (foe && IsFakeClient(foe))
{
ConVar cvar = FindConVar("tf_bot_quota");
int quota = cvar.IntValue;
ServerCommand("tf_bot_quota %d", quota - 1);
}
if (foe2 && IsFakeClient(foe2))
{
ConVar cvar = FindConVar("tf_bot_quota");
int quota = cvar.IntValue;
ServerCommand("tf_bot_quota %d", quota - 1);
}
if (player_teammate && IsFakeClient(player_teammate))
{
ConVar cvar = FindConVar("tf_bot_quota");
int quota = cvar.IntValue;
ServerCommand("tf_bot_quota %d", quota - 1);
}
g_iArenaStatus[arena_index] = AS_IDLE;
return;
}
}
else
{
if (g_iArenaQueue[arena_index][SLOT_TWO + 1])
{
int next_client = g_iArenaQueue[arena_index][SLOT_TWO + 1];
g_iArenaQueue[arena_index][SLOT_TWO + 1] = 0;
g_iArenaQueue[arena_index][player_slot] = next_client;
g_iPlayerSlot[next_client] = player_slot;
after_leaver_slot = SLOT_TWO + 2;
char playername[MAX_NAME_LENGTH];
CreateTimer(2.0, Timer_StartDuel, arena_index);
GetClientName(next_client, playername, sizeof(playername));
if (!g_bNoStats && !g_bNoDisplayRating)
MC_PrintToChatAll("%t", "JoinsArena", playername, g_iPlayerRating[next_client], g_sArenaName[arena_index]);
else
MC_PrintToChatAll("%t", "JoinsArenaNoStats", playername, g_sArenaName[arena_index]);
} else {
if (foe && IsFakeClient(foe))
{
ConVar cvar = FindConVar("tf_bot_quota");
int quota = cvar.IntValue;
ServerCommand("tf_bot_quota %d", quota - 1);
}
g_iArenaStatus[arena_index] = AS_IDLE;
return;
}
}
if (g_iArenaQueue[arena_index][after_leaver_slot])
{
while (g_iArenaQueue[arena_index][after_leaver_slot])
{
g_iArenaQueue[arena_index][after_leaver_slot - 1] = g_iArenaQueue[arena_index][after_leaver_slot];
g_iPlayerSlot[g_iArenaQueue[arena_index][after_leaver_slot]] -= 1;
after_leaver_slot++;
}
g_iArenaQueue[arena_index][after_leaver_slot - 1] = 0;
}
}
if (g_hWelcomeTimer[client] != null)
{
delete g_hWelcomeTimer[client];
}
}
/* OnGameFrame()
*
* This code is run on every frame. Can be very hardware intensive.
* -------------------------------------------------------------------------- */
// note from the future - "this can be hardware intensive" and then its repeated code like 4 times? lol ok
public void OnGameFrame()
{
int arena_index;
for (int client = 1; client <= MaxClients; client++)
{
if (IsValidClient(client) && IsPlayerAlive(client))
{
arena_index = g_iPlayerArena[client];
if (!g_bArenaBBall[arena_index] && !g_bArenaMGE[arena_index] && !g_bArenaKoth[arena_index])
{
/* This is a hack that prevents people from getting one-shot by things
like the direct hit in the Ammomod arenas. */
int replacement_hp = (g_iPlayerMaxHP[client] + 512);
SetEntProp(client, Prop_Send, "m_iHealth", replacement_hp, 1);
}
}
}
for (int arena_index2 = 1; arena_index2 <= g_iArenaCount; ++arena_index2)
{
if (g_bArenaKoth[arena_index2] && g_iArenaStatus[arena_index2] == AS_FIGHT)
{
g_fTotalTime[arena_index2] += 7;
if (g_iPointState[arena_index2] == NEUTRAL || g_iPointState[arena_index2] == TEAM_BLU)
{
//If RED Team is capping and BLU Team isn't and BLU Team has the point increase the cap time
if (!(g_bPlayerTouchPoint[arena_index2][SLOT_TWO] || g_bPlayerTouchPoint[arena_index2][SLOT_FOUR]) && (g_iCappingTeam[arena_index2] == TEAM_RED || g_iCappingTeam[arena_index2] == NEUTRAL))
{
int cap = 0;
if (g_bPlayerTouchPoint[arena_index2][SLOT_ONE])
{
cap++;
//If the player is a Scout add one to the cap speed
if (g_tfctPlayerClass[g_iArenaQueue[arena_index2][SLOT_ONE]] == TF2_GetClass("scout"))
cap++;
int ent = GetPlayerWeaponSlot(g_iArenaQueue[arena_index2][SLOT_ONE], 2);
int iItemDefinitionIndex = GetEntProp(ent, Prop_Send, "m_iItemDefinitionIndex");
//If the player has the Pain Train equipped add one to the cap speed
if (iItemDefinitionIndex == 154)
cap++;
}
if (g_bPlayerTouchPoint[arena_index2][SLOT_THREE])
{
cap++;
//If the player is a Scout add one to the cap speed
if (g_tfctPlayerClass[g_iArenaQueue[arena_index2][SLOT_THREE]] == TF2_GetClass("scout"))
cap++;
int ent = GetPlayerWeaponSlot(g_iArenaQueue[arena_index2][SLOT_THREE], 2);
int iItemDefinitionIndex = GetEntProp(ent, Prop_Send, "m_iItemDefinitionIndex");
//If the player has the Pain Train equipped add one to the cap speed
if (iItemDefinitionIndex == 154)
cap++;
}
//Add cap time if needed
if (cap)
{
//True harmonic cap time, yes!
for (; cap > 0; cap--)
{
g_fCappedTime[arena_index2] += 7.0 / float(cap);
}
g_iCappingTeam[arena_index2] = TEAM_RED;
continue;
}
}
}
if (g_iPointState[arena_index2] == NEUTRAL || g_iPointState[arena_index2] == TEAM_RED)
{
//If BLU Team is capping and Team RED isn't and Team RED has the point increase the cap time
if (!(g_bPlayerTouchPoint[arena_index2][SLOT_ONE] || g_bPlayerTouchPoint[arena_index2][SLOT_THREE]) && (g_iCappingTeam[arena_index2] == TEAM_BLU || g_iCappingTeam[arena_index2] == NEUTRAL))
{
int cap = 0;
if (g_bPlayerTouchPoint[arena_index2][SLOT_TWO])
{
cap++;
//If the player is a Scout add one to the cap speed
if (g_tfctPlayerClass[g_iArenaQueue[arena_index2][SLOT_TWO]] == TF2_GetClass("scout"))
cap++;
int ent = GetPlayerWeaponSlot(g_iArenaQueue[arena_index2][SLOT_TWO], 2);
int iItemDefinitionIndex = GetEntProp(ent, Prop_Send, "m_iItemDefinitionIndex");
//If the player has the Pain Train equipped add one to the cap speed
if (iItemDefinitionIndex == 154)
cap++;
}
if (g_bPlayerTouchPoint[arena_index2][SLOT_FOUR])
{
cap++;
//If the player is a Scout add one to the cap speed
if (g_tfctPlayerClass[g_iArenaQueue[arena_index2][SLOT_FOUR]] == TF2_GetClass("scout"))
cap++;
int ent = GetPlayerWeaponSlot(g_iArenaQueue[arena_index2][SLOT_FOUR], 2);
int iItemDefinitionIndex = GetEntProp(ent, Prop_Send, "m_iItemDefinitionIndex");
//If the player has the Pain Train equipped add one to the cap speed
if (iItemDefinitionIndex == 154)
cap++;
}
//Add cap time if needed
if (cap)
{
//True harmonic cap time, yes!
for (; cap > 0; cap--)
{
g_fCappedTime[arena_index2] += 7.0, float(cap);
}
g_iCappingTeam[arena_index2] = TEAM_BLU;
continue;
}
}
}
//If BLU Team is blocking and RED Team isn't capping and BLU Team has the point increase the cap diminish rate
if ((g_bPlayerTouchPoint[arena_index2][SLOT_TWO] || g_bPlayerTouchPoint[arena_index2][SLOT_FOUR]) &&
(g_iPointState[arena_index2] == NEUTRAL) && g_iCappingTeam[arena_index2] == TEAM_RED &&
!(g_bPlayerTouchPoint[arena_index2][SLOT_ONE] || g_bPlayerTouchPoint[arena_index2][SLOT_THREE]))
{
int cap = 0;
if (g_bPlayerTouchPoint[arena_index2][SLOT_TWO])
{
cap++;
//If the player is a Scout add one to the cap speed
if (g_tfctPlayerClass[g_iArenaQueue[arena_index2][SLOT_TWO]] == TF2_GetClass("scout"))
cap++;
int ent = GetPlayerWeaponSlot(g_iArenaQueue[arena_index2][SLOT_TWO], 2);
int iItemDefinitionIndex = GetEntProp(ent, Prop_Send, "m_iItemDefinitionIndex");
//If the player has the Pain Train equipped add one to the cap speed
if (iItemDefinitionIndex == 154)
cap++;
}
if (g_bPlayerTouchPoint[arena_index2][SLOT_FOUR])
{
cap++;
//If the player is a Scout add one to the cap speed
if (g_tfctPlayerClass[g_iArenaQueue[arena_index2][SLOT_FOUR]] == TF2_GetClass("scout"))
cap++;
int ent = GetPlayerWeaponSlot(g_iArenaQueue[arena_index2][SLOT_FOUR], 2);
int iItemDefinitionIndex = GetEntProp(ent, Prop_Send, "m_iItemDefinitionIndex");
//If the player has the Pain Train equipped add one to the cap speed
if (iItemDefinitionIndex == 154)
cap++;
}
//Add cap time if needed
if (cap)
{
//True harmonic cap time, yes!
for (; cap > 0; cap--)
{
g_fCappedTime[arena_index2] -= 7.0, float(cap);
}
g_iCappingTeam[arena_index2] = TEAM_BLU;
continue;
}
}
//If RED Team is blocking and BLU Team isn't capping and RED Team has the point increase the cap diminish rate
if ((g_bPlayerTouchPoint[arena_index2][SLOT_ONE] || g_bPlayerTouchPoint[arena_index2][SLOT_THREE]) &&
(g_iPointState[arena_index2] == NEUTRAL) && g_iCappingTeam[arena_index2] == TEAM_BLU &&
!(g_bPlayerTouchPoint[arena_index2][SLOT_TWO] || g_bPlayerTouchPoint[arena_index2][SLOT_FOUR]))
{
int cap = 0;
if (g_bPlayerTouchPoint[arena_index2][SLOT_ONE])
{
cap++;
//If the player is a Scout add one to the cap speed
if (g_tfctPlayerClass[g_iArenaQueue[arena_index2][SLOT_ONE]] == TF2_GetClass("scout"))
cap++;
int ent = GetPlayerWeaponSlot(g_iArenaQueue[arena_index2][SLOT_ONE], 2);
int iItemDefinitionIndex = GetEntProp(ent, Prop_Send, "m_iItemDefinitionIndex");
//If the player has the Pain Train equipped add one to the cap speed
if (iItemDefinitionIndex == 154)
cap++;
}
if (g_bPlayerTouchPoint[arena_index2][SLOT_THREE])
{
cap++;
//If the player is a Scout add one to the cap speed
if (g_tfctPlayerClass[g_iArenaQueue[arena_index2][SLOT_THREE]] == TF2_GetClass("scout"))
cap++;
int ent = GetPlayerWeaponSlot(g_iArenaQueue[arena_index2][SLOT_THREE], 2);
int iItemDefinitionIndex = GetEntProp(ent, Prop_Send, "m_iItemDefinitionIndex");
//If the player has the Pain Train equipped add one to the cap speed
if (iItemDefinitionIndex == 154)
cap++;
}
//Add cap time if needed
if (cap)
{
//True harmonic cap time, yes!
for (; cap > 0; cap--)
{
g_fCappedTime[arena_index2] -= 7.0, float(cap);
}
g_iCappingTeam[arena_index2] = TEAM_RED;
continue;
}
}
//If both teams are touching the point, do nothing
if ((g_bPlayerTouchPoint[arena_index2][SLOT_TWO] || g_bPlayerTouchPoint[arena_index2][SLOT_FOUR]) && (g_bPlayerTouchPoint[arena_index2][SLOT_ONE] || g_bPlayerTouchPoint[arena_index2][SLOT_THREE]))
continue;
// If in overtime, revert cap at 6x speed, if not, revert cap slowly
if (g_bOvertimePlayed[arena_index][TEAM_RED] || g_bOvertimePlayed[arena_index][TEAM_BLU])
g_fCappedTime[arena_index2] -= 6.0;
else
g_fCappedTime[arena_index2]--;
}
}
}
/* OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
*
* When a client takes damage.
* -------------------------------------------------------------------------- */
public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
if (!IsValidClient(victim) || !IsValidClient(attacker))
return Plugin_Continue;
// Fall damage negation.
if ((damagetype & DMG_FALL) && g_bBlockFallDamage)
{
damage = 0.0;
return Plugin_Changed;
}
return Plugin_Continue;
}