-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathsuperzombiefortress.sp
More file actions
2822 lines (2316 loc) · 75.3 KB
/
superzombiefortress.sp
File metadata and controls
2822 lines (2316 loc) · 75.3 KB
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
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <clientprefs>
#include <tf2>
#include <tf2_stocks>
#include <tf2attributes>
#include <tf_econ_data>
#include <dhooks>
#include <morecolors>
#undef REQUIRE_EXTENSIONS
#tryinclude <tf2items>
#define REQUIRE_EXTENSIONS
#pragma newdecls required
#include "include/superzombiefortress.inc"
#define PLUGIN_VERSION "4.7.3"
#define PLUGIN_VERSION_REVISION "manual"
#define MAX_CONTROL_POINTS 8
#define MINI_DISPENSER_MAX_METAL 200 // It's actually still DISPENSER_MAX_METAL_AMMO of 400 the max for mini dispenser, this value is only used on hud displays
#define ATTRIB_VISION 406
#define SECONDS_PER_MINUTE 60
#define SECONDS_PER_HOUR 3600
#define SECONDS_PER_DAY 86400
#define SECONDS_PER_MONTH 2629743
// Also used in the item schema to define vision filter or vision mode opt in
#define TF_VISION_FILTER_NONE 0
#define TF_VISION_FILTER_PYRO (1<<0) // 1
#define TF_VISION_FILTER_HALLOWEEN (1<<1) // 2
#define TF_VISION_FILTER_ROME (1<<2) // 4
// settings for m_takedamage
#define DAMAGE_NO 0
#define DAMAGE_EVENTS_ONLY 1 // Call damage functions, but don't modify health
#define DAMAGE_YES 2
#define DAMAGE_AIM 3
// Phys prop spawnflags
#define SF_PHYSPROP_START_ASLEEP 0x000001
#define SF_PHYSPROP_DONT_TAKE_PHYSICS_DAMAGE 0x000002 // this prop can't be damaged by physics collisions
#define SF_PHYSPROP_DEBRIS 0x000004
#define SF_PHYSPROP_MOTIONDISABLED 0x000008 // motion disabled at startup (flag only valid in spawn - motion can be enabled via input)
#define SF_PHYSPROP_TOUCH 0x000010 // can be 'crashed through' by running player (plate glass)
#define SF_PHYSPROP_PRESSURE 0x000020 // can be broken by a player standing on it
#define SF_PHYSPROP_ENABLE_ON_PHYSCANNON 0x000040 // enable motion only if the player grabs it with the physcannon
#define SF_PHYSPROP_NO_ROTORWASH_PUSH 0x000080 // The rotorwash doesn't push these
#define SF_PHYSPROP_ENABLE_PICKUP_OUTPUT 0x000100 // If set, allow the player to +USE this for the purposes of generating an output
#define SF_PHYSPROP_PREVENT_PICKUP 0x000200 // If set, prevent +USE/Physcannon pickup of this prop
#define SF_PHYSPROP_PREVENT_PLAYER_TOUCH_ENABLE 0x000400 // If set, the player will not cause the object to enable its motion when bumped into
#define SF_PHYSPROP_HAS_ATTACHED_RAGDOLLS 0x000800 // Need to remove attached ragdolls on enable motion/etc
#define SF_PHYSPROP_FORCE_TOUCH_TRIGGERS 0x001000 // Override normal debris behavior and respond to triggers anyway
#define SF_PHYSPROP_FORCE_SERVER_SIDE 0x002000 // Force multiplayer physics object to be serverside
#define SF_PHYSPROP_RADIUS_PICKUP 0x004000 // For Xbox, makes small objects easier to pick up by allowing them to be found
#define SF_PHYSPROP_ALWAYS_PICK_UP 0x100000 // Physcannon can always pick this up, no matter what mass or constraints may apply.
#define SF_PHYSPROP_NO_COLLISIONS 0x200000 // Don't enable collisions on spawn
#define SF_PHYSPROP_IS_GIB 0x400000 // Limit # of active gibs
enum
{
COLLISION_GROUP_NONE = 0,
COLLISION_GROUP_DEBRIS, // Collides with nothing but world and static stuff
COLLISION_GROUP_DEBRIS_TRIGGER, // Same as debris, but hits triggers
COLLISION_GROUP_INTERACTIVE_DEBRIS, // Collides with everything except other interactive debris or debris
COLLISION_GROUP_INTERACTIVE, // Collides with everything except interactive debris or debris
COLLISION_GROUP_PLAYER,
COLLISION_GROUP_BREAKABLE_GLASS,
COLLISION_GROUP_VEHICLE,
COLLISION_GROUP_PLAYER_MOVEMENT, // For HL2, same as Collision_Group_Player, for
// TF2, this filters out other players and CBaseObjects
COLLISION_GROUP_NPC, // Generic NPC group
COLLISION_GROUP_IN_VEHICLE, // for any entity inside a vehicle
COLLISION_GROUP_WEAPON, // for any weapons that need collision detection
COLLISION_GROUP_VEHICLE_CLIP, // vehicle clip brush to restrict vehicle movement
COLLISION_GROUP_PROJECTILE, // Projectiles!
COLLISION_GROUP_DOOR_BLOCKER, // Blocks entities not permitted to get near moving doors
COLLISION_GROUP_PASSABLE_DOOR, // Doors that the player shouldn't collide with
COLLISION_GROUP_DISSOLVING, // Things that are dissolving are in this group
COLLISION_GROUP_PUSHAWAY, // Nonsolid on client and server, pushaway in player code
COLLISION_GROUP_NPC_ACTOR, // Used so NPCs in scripts ignore the player.
COLLISION_GROUP_NPC_SCRIPTED, // USed for NPCs in scripts that should not collide with each other
LAST_SHARED_COLLISION_GROUP
};
enum
{
VISION_MODE_NONE = 0,
VISION_MODE_PYRO,
VISION_MODE_HALLOWEEN,
VISION_MODE_ROME,
MAX_VISION_MODES
};
enum
{
MELEE_NOCRIT = 0,
MELEE_MINICRIT = 1,
MELEE_CRIT = 2,
};
// entity effects
enum
{
EF_BONEMERGE = 0x001, // Performs bone merge on client side
EF_BRIGHTLIGHT = 0x002, // DLIGHT centered at entity origin
EF_DIMLIGHT = 0x004, // player flashlight
EF_NOINTERP = 0x008, // don't interpolate the next frame
EF_NOSHADOW = 0x010, // Don't cast no shadow
EF_NODRAW = 0x020, // don't draw entity
EF_NORECEIVESHADOW = 0x040, // Don't receive no shadow
EF_BONEMERGE_FASTCULL = 0x080, // For use with EF_BONEMERGE. If this is set, then it places this ent's origin at its
// parent and uses the parent's bbox + the max extents of the aiment.
// Otherwise, it sets up the parent's bones every frame to figure out where to place
// the aiment, which is inefficient because it'll setup the parent's bones even if
// the parent is not in the PVS.
EF_ITEM_BLINK = 0x100, // blink an item so that the user notices it.
EF_PARENT_ANIMATES = 0x200, // always assume that the parent entity is animating
EF_MAX_BITS = 10
};
enum SolidType_t
{
SOLID_NONE = 0, // no solid model
SOLID_BSP = 1, // a BSP tree
SOLID_BBOX = 2, // an AABB
SOLID_OBB = 3, // an OBB (not implemented yet)
SOLID_OBB_YAW = 4, // an OBB, constrained so that it can only yaw
SOLID_CUSTOM = 5, // Always call into the entity for tests
SOLID_VPHYSICS = 6, // solid vphysics object, get vcollide from the model and collide with that
SOLID_LAST,
};
enum
{
WeaponSlot_Primary = 0,
WeaponSlot_Secondary,
WeaponSlot_Melee,
WeaponSlot_PDABuild,
WeaponSlot_PDADisguise = 3,
WeaponSlot_PDADestroy,
WeaponSlot_InvisWatch = 4,
WeaponSlot_BuilderEngie,
};
enum SZFRoundState
{
SZFRoundState_Setup,
SZFRoundState_Grace,
SZFRoundState_Active,
SZFRoundState_End,
};
enum Infected
{
Infected_Unknown = -1,
Infected_None,
Infected_Tank,
Infected_Boomer,
Infected_Charger,
Infected_Screamer,
Infected_Stalker,
Infected_Hunter,
Infected_Smoker,
Infected_Spitter,
Infected_Jockey,
Infected_Count
}
enum struct WeaponClasses
{
int iIndex;
char sAttribs[256];
char sLogName[64];
char sIconName[64];
}
enum struct ClientClasses
{
//Survivor, Zombie and Infected
bool bEnabled;
int iHealth;
int iRegen;
float flSpeed;
//Survivor
int iAmmo;
//Zombie and Infected
int iDegen;
ArrayList aWeapons;
float flHorde;
float flMaxHorde;
bool bGlow;
bool bThirdperson;
int iColor[4];
char sMessage[64];
char sMenu[64];
char sWorldModel[PLATFORM_MAX_PATH];
char sViewModel[PLATFORM_MAX_PATH];
bool bViewModelAnim;
char sSoundSpawn[PLATFORM_MAX_PATH];
int iRageCooldown;
Function callback_spawn;
Function callback_rage;
Function callback_think;
Function callback_touch;
Function callback_damage;
Function callback_attack;
Function callback_death;
//Infected
TFClassType iInfectedClass;
bool GetWeapon(int &iPos, WeaponClasses weapon)
{
if (!this.aWeapons || iPos < 0 || iPos >= this.aWeapons.Length)
return false;
this.aWeapons.GetArray(iPos, weapon);
iPos++;
return true;
}
bool GetWeaponFromIndex(int iIndex, WeaponClasses buffer)
{
int iPos;
WeaponClasses weapon;
while (this.GetWeapon(iPos, weapon))
{
if (weapon.iIndex != iIndex)
continue;
buffer = weapon;
return true;
}
return false;
}
bool GetWeaponSlot(int iSlot, WeaponClasses buffer)
{
if (!this.aWeapons)
return false;
// Get one of the weapon in slot by random
WeaponClasses[] weapons = new WeaponClasses[this.aWeapons.Length];
int iCount;
int iPos;
WeaponClasses weapon;
while (this.GetWeapon(iPos, weapon))
{
if (TF2_GetItemSlot(weapon.iIndex) == iSlot)
weapons[iCount++] = weapon;
}
if (iCount == 0)
return false;
buffer = weapons[GetRandomInt(0, iCount - 1)];
return true;
}
int GetWeaponSlotIndex(int iSlot)
{
WeaponClasses weapon;
if (!this.GetWeaponSlot(iSlot, weapon))
return -1;
return weapon.iIndex;
}
bool HasWeaponIndex(int iIndex)
{
int iPos;
WeaponClasses weapon;
while (this.GetWeapon(iPos, weapon))
{
if (weapon.iIndex == iIndex)
return true;
}
return false;
}
}
ClientClasses g_ClientClasses[MAXPLAYERS + 1];
SZFRoundState g_nRoundState = SZFRoundState_Setup;
Infected g_nInfected[MAXPLAYERS + 1];
Infected g_nNextInfected[MAXPLAYERS + 1];
TFTeam TFTeam_Zombie = TFTeam_Blue;
TFTeam TFTeam_Survivor = TFTeam_Red;
TFClassType g_iClassDisplay[] = {
TFClass_Unknown,
TFClass_Scout,
TFClass_Soldier,
TFClass_Pyro,
TFClass_DemoMan,
TFClass_Heavy,
TFClass_Engineer,
TFClass_Medic,
TFClass_Sniper,
TFClass_Spy,
};
char g_sClassNames[view_as<int>(TFClass_Engineer) + 1][] = {
"",
"Scout",
"Sniper",
"Soldier",
"Demoman",
"Medic",
"Heavy",
"Pyro",
"Spy",
"Engineer",
};
char g_sInfectedNames[view_as<int>(Infected_Count)][] = {
"None",
"Tank",
"Boomer",
"Charger",
"Screamer",
"Stalker",
"Hunter",
"Smoker",
"Spitter",
"Jockey",
};
#define SPITTER_SPIT_MODEL "models/weapons/w_bugbait.mdl"
char g_sSpitterParticles[][] = {
"unusual_risingstar_green_glow",
"unusual_meteor_fireball_small_green",
};
Cookie g_cFirstTimeSurvivor;
Cookie g_cFirstTimeZombie;
Cookie g_cSoundPreference;
Cookie g_cForceZombieStartMapName;
Cookie g_cForceZombieStartTimestamp;
//Global State
bool g_bEnabled;
bool g_bNewFullRound;
bool g_bLastSurvivor;
bool g_bTF2Items;
bool g_bGiveNamedItemSkip;
ArrayList g_aSurvivorDeathTimes;
int g_iZombiesKilledSpree;
float g_flRoundStarted;
int g_iRoundTimestamp;
//Client State
int g_iHorde[MAXPLAYERS + 1];
int g_iCapturingPoint[MAXPLAYERS + 1];
int g_iRageTimer[MAXPLAYERS + 1];
float g_flStopChatSpam[MAXPLAYERS + 1];
StringMap g_mRoundPlayedAsZombie;
int g_iRoundPlayedCount;
//Global Timer Handles
Handle g_hTimerMain;
Handle g_hTimerMainSlow;
Handle g_hTimerHoarde;
Handle g_hTimerDataCollect;
Handle g_hTimerProgress;
//Cvar Handles
ConVar g_cvForceOn;
ConVar g_cvDebug;
ConVar g_cvRatio;
ConVar g_cvScaleProgress;
ConVar g_cvScaleSurvivors;
ConVar g_cvScaleLastCP;
ConVar g_cvWeaponSpawnReappear;
ConVar g_cvWeaponPickupChance;
ConVar g_cvWeaponRareChance;
ConVar g_cvWeaponRareCap;
ConVar g_cvTankHealth;
ConVar g_cvTankHealthMin;
ConVar g_cvTankHealthMax;
ConVar g_cvTankTime;
ConVar g_cvTankStab;
ConVar g_cvTankDebrisLifetime;
ConVar g_cvSpecialInfectedInterval;
ConVar g_cvJockeyMovementVictim;
ConVar g_cvJockeyMovementAttacker;
ConVar g_cvFrenzyTankChance;
ConVar g_cvFrenzyRespawnStress;
ConVar g_cvStunImmunity;
ConVar g_cvLastStandKingRuneDuration;
ConVar g_cvLastStandDefenseDuration;
ConVar g_cvDispenserAmmoCooldown;
ConVar g_cvDispenserAmmoMax;
ConVar g_cvDispenserHealRate;
ConVar g_cvDispenserHealMax;
ConVar g_cvBannerRequirement;
ConVar g_cvMeleeIgnoreTeammates;
ConVar g_cvPunishAvoidingPlayers;
enum struct ConVarEvent
{
ConVar cvCooldown;
ConVar cvSurvivorDeathInterval; // Seconds interval to consider for survivor deaths
ConVar cvSurvivorDeathThreshold; // Min threshold for % of survivors died within interval
ConVar cvKillSpree; // Killing spree requirement since last survivor death, multiplied by % of zombies in playerbase
ConVar cvProgress; // Min % of playerbase being survivor to trigger by map progress
ConVar cvChance; // % Chance to randomly trigger it
float flCooldown;
void SetCooldown()
{
this.flCooldown = GetGameTime();
}
bool CanDoEvent()
{
float flGameTime = GetGameTime();
if (this.flCooldown + this.cvCooldown.FloatValue > flGameTime)
return false;
// Random chance
if (GetRandomFloat(0.0, 1.0) < this.cvChance.FloatValue)
{
CPrintToChatDebug("Triggered event from random chance (%.2f%%)", this.cvChance.FloatValue * 100.0);
return true;
}
// Check if there too few survivor deaths within timeframe
float flTotal;
float flInterval = this.cvSurvivorDeathInterval.FloatValue;
int iLength = g_aSurvivorDeathTimes.Length;
for (int i = 0; i < iLength; i++)
{
float flDeath = g_aSurvivorDeathTimes.Get(i);
if (flDeath + flInterval < flGameTime)
continue;
// from 1.0 to 0.0, value fades down
flTotal += 1.0 - ((flGameTime - flDeath) / flInterval);
}
int iSurvivors = GetSurvivorCount();
int iZombies = GetZombieCount();
// Counting both dead and alive survivors
float flThreshold = (iSurvivors + iLength) * this.cvSurvivorDeathThreshold.FloatValue;
if (flGameTime - g_flRoundStarted < flInterval) // If game has just started, lower the threshold
flThreshold *= (flGameTime - g_flRoundStarted) / flInterval;
if (flTotal < flThreshold)
{
CPrintToChatDebug("Triggered event from few survivor deaths (%.2f deaths < threshold %.2f)", flTotal, flThreshold);
return true;
}
// Check if there too many zombie kills since last survivor death
float flZombiePercentage = float(iZombies) / float(iSurvivors + iZombies);
if (g_iZombiesKilledSpree >= this.cvKillSpree.FloatValue * flZombiePercentage)
{
CPrintToChatDebug("Triggered event from killing spree (%d killed >= threshold %.2f)", g_iZombiesKilledSpree, this.cvKillSpree.FloatValue * flZombiePercentage);
return true;
}
// Check if there too many survivors and map has progressed fast (flMinPercentage from 1.0 to flMinCooldown)
float flProgress = GetMapProgress();
if (0.0 <= flProgress <= 1.0)
{
float flMinCooldown = this.cvProgress.FloatValue;
float flMinPercentage = 1.0 - (flProgress * (1.0 - flMinCooldown));
float flSurvivorPercentage = 1.0 - flZombiePercentage;
if (flSurvivorPercentage >= flMinPercentage)
{
CPrintToChatDebug("Triggered event from too many survivors (%.2f >= threshold %.2f)", flSurvivorPercentage, flMinPercentage);
return true;
}
}
return false;
}
}
ConVarEvent g_FrenzyEvent;
ConVarEvent g_TankEvent;
float g_flZombieDamageScale = 1.0;
ArrayList g_aFastRespawn;
int g_iDamageZombie[MAXPLAYERS + 1];
int g_iDamageTakenLife[MAXPLAYERS + 1];
int g_iDamageDealtLife[MAXPLAYERS + 1];
float g_flDamageDealtAgainstTank[MAXPLAYERS + 1];
bool g_bTankRefreshed;
int g_iControlPointsInfo[MAX_CONTROL_POINTS][2];
int g_iControlPoints;
bool g_bCapturingLastPoint;
int g_iCarryingItem[MAXPLAYERS + 1] = {INVALID_ENT_REFERENCE, ...};
float g_flTimeProgress;
float g_flRageRespawnStress;
float g_flInfectedInterval;
float g_flInfectedCooldown[view_as<int>(Infected_Count)]; //GameTime
int g_iInfectedCooldown[view_as<int>(Infected_Count)]; //Client who started the cooldown
int g_iTanksSpawned;
bool g_bZombieRage;
bool g_bSpawnAsSpecialInfected[MAXPLAYERS + 1];
int g_iKillsThisLife[MAXPLAYERS + 1];
int g_iMaxHealth[MAXPLAYERS + 1];
bool g_bShouldBacteriaPlay[MAXPLAYERS + 1] = {true, ...};
float g_flTimeStartAsZombie[MAXPLAYERS + 1];
float g_flBannerMeter[MAXPLAYERS + 1];
float g_flDispenserUsage[MAXPLAYERS + 1];
char g_sForceZombieStartMapName[MAXPLAYERS + 1][64];
int g_iForceZombieStartTimestamp[MAXPLAYERS + 1];
//Map overwrites
int g_iMaxRareWeapons;
float g_flCapScale = -1.0;
bool g_bSurvival;
bool g_bNoMusic;
bool g_bNoDirectorTanks;
bool g_bNoDirectorRages;
bool g_bDirectorSpawnTeleport;
//Cookies
Cookie g_cWeaponsPicked;
Cookie g_cWeaponsRarePicked;
Cookie g_cWeaponsCalled;
//SDK offsets
int g_iOffsetItemDefinitionIndex;
#include "szf/weapons.sp"
#include "szf/sound.sp"
#include "szf/classes.sp"
#include "szf/command.sp"
#include "szf/config.sp"
#include "szf/console.sp"
#include "szf/convar.sp"
#include "szf/dhook.sp"
#include "szf/event.sp"
#include "szf/forward.sp"
#include "szf/infected.sp"
#include "szf/menu.sp"
#include "szf/native.sp"
#include "szf/pickupweapons.sp"
#include "szf/sdkcall.sp"
#include "szf/sdkhook.sp"
#include "szf/stocks.sp"
#include "szf/stun.sp"
#include "szf/viewmodel.sp"
public Plugin myinfo =
{
name = "Super Zombie Fortress",
author = "42, Alex Turtle, Batfoxkid, Haxton Sale, Mikusch, sasch, wo, MekuCube (original)",
description = "Originally based off MekuCube's 1.05 version.",
version = PLUGIN_VERSION ... "." ... PLUGIN_VERSION_REVISION,
url = "https://github.com/redsunservers/SuperZombieFortress"
}
////////////////////////////////////////////////////////////
//
// Sourcemod Callbacks
//
////////////////////////////////////////////////////////////
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
Forward_AskLoad();
Native_AskLoad();
RegPluginLibrary("superzombiefortress");
return APLRes_Success;
}
public void OnPluginStart()
{
//Add server tag.
AddServerTag("zf");
AddServerTag("szf");
LoadTranslations("superzombiefortress.phrases");
//Initialize global state
g_bSurvival = false;
g_bNoMusic = false;
g_bNoDirectorTanks = false;
g_bNoDirectorRages = false;
g_bDirectorSpawnTeleport = false;
g_bEnabled = false;
g_bNewFullRound = true;
g_bLastSurvivor = false;
g_aSurvivorDeathTimes = new ArrayList();
g_cFirstTimeZombie = new Cookie("szf_firsttimezombie", "Whether this player is playing as Infected for the first time.", CookieAccess_Protected);
g_cFirstTimeSurvivor = new Cookie("szf_firsttimesurvivor2", "Whether this player is playing as a Survivor for the first time.", CookieAccess_Protected);
g_cSoundPreference = new Cookie("szf_musicpreference", "Player's sound preference.", CookieAccess_Protected);
g_cForceZombieStartTimestamp = new Cookie("szf_forcezombiestart_timestamp", "Timestamp of when the player was detected skipping playing on the Infected team.", CookieAccess_Protected);
g_cForceZombieStartMapName = new Cookie("szf_forcezombiestart_mapname", "Name of the map that the player was detected skipping playing on the Infected team on.", CookieAccess_Protected);
g_bTF2Items = LibraryExists("TF2Items");
GameData hSDKHooks = new GameData("sdkhooks.games");
if (!hSDKHooks)
SetFailState("Could not find sdkhooks.games gamedata!");
GameData hTF2 = new GameData("sm-tf2.games");
if (!hTF2)
SetFailState("Could not find sm-tf2.games gamedata!");
GameData hSZF = new GameData("szf");
if (!hSZF)
SetFailState("Could not find szf gamedata!");
DHook_Init(hSZF);
SDKCall_Init(hSDKHooks, hTF2, hSZF);
g_iOffsetItemDefinitionIndex = hSZF.GetOffset("CEconItemView::m_iItemDefinitionIndex");
delete hSDKHooks;
delete hTF2;
delete hSZF;
Command_Init();
Config_Init();
Console_Init();
ConVar_Init();
Event_Init();
Weapons_Init();
//Incase of late-load
for (int iClient = 1; iClient <= MaxClients; iClient++)
if (IsClientInGame(iClient))
OnClientPutInServer(iClient);
}
public void OnLibraryAdded(const char[] sName)
{
if (StrEqual(sName, "TF2Items"))
{
g_bTF2Items = true;
//We cant allow TF2Items load while GiveNamedItem already hooked due to crash
if (DHook_IsGiveNamedItemActive())
SetFailState("Do not load TF2Items midgame while Super Zombie Fortress is already loaded!");
}
}
public void OnLibraryRemoved(const char[] sName)
{
if (StrEqual(sName, "TF2Items"))
{
g_bTF2Items = false;
//TF2Items unloaded with GiveNamedItem unhooked, we can now safely hook GiveNamedItem ourself
if (g_bEnabled)
for (int iClient = 1; iClient <= MaxClients; iClient++)
if (IsClientInGame(iClient))
DHook_HookGiveNamedItem(iClient);
}
}
public void OnPluginEnd()
{
if (g_bEnabled)
{
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (IsClientInGame(iClient))
{
Sound_EndAllMusic(iClient);
SetEntProp(iClient, Prop_Send, "m_nModelIndexOverrides", 0, _, VISION_MODE_ROME);
}
}
SZFDisable();
if (GameRules_GetRoundState() >= RoundState_Preround) //Must check if round on-going, otherwise possible crash
TF2_EndRound(TFTeam_Zombie);
}
}
public void OnClientCookiesCached(int iClient)
{
char sValue[32];
int iValue;
g_cSoundPreference.Get(iClient, sValue, sizeof(sValue));
Sound_UpdateClientSetting(iClient, view_as<SoundSetting>(StringToInt(sValue)));
g_cForceZombieStartTimestamp.Get(iClient, sValue, sizeof(sValue));
iValue = StringToInt(sValue);
g_iForceZombieStartTimestamp[iClient] = iValue;
g_cForceZombieStartMapName.Get(iClient, g_sForceZombieStartMapName[iClient], sizeof(g_sForceZombieStartMapName[]));
}
public void OnConfigsExecuted()
{
if (IsMapSZF() || g_cvForceOn.BoolValue)
{
SZFEnable();
GetMapSettings();
}
}
public void OnMapStart()
{
g_iRoundTimestamp = GetTime();
}
public void OnMapEnd()
{
if (!g_bEnabled)
return;
g_nRoundState = SZFRoundState_End;
SZFDisable();
}
void GetMapSettings()
{
int iEntity = -1;
while ((iEntity = FindEntityByClassname(iEntity, "info_target")) != -1)
{
char sTargetName[64];
GetEntPropString(iEntity, Prop_Data, "m_iName", sTargetName, sizeof(sTargetName));
if (StrContains(sTargetName, "szf_survivalmode", false) == 0)
{
g_bSurvival = true;
}
else if (StrContains(sTargetName, "szf_nomusic", false) == 0)
{
g_bNoMusic = true;
}
else if (StrContains(sTargetName, "szf_director_notank", false) == 0)
{
g_bNoDirectorTanks = true;
}
else if (StrContains(sTargetName, "szf_director_norage", false) == 0)
{
g_bNoDirectorRages = true;
}
else if (StrContains(sTargetName, "szf_director_spawnteleport", false) == 0)
{
g_bDirectorSpawnTeleport = true;
}
else if (StrContains(sTargetName, "szf_rarecap_", false) == 0)
{
ReplaceString(sTargetName, sizeof(sTargetName), "szf_rarecap_", "", false);
if(StringToIntEx(sTargetName, g_iMaxRareWeapons) == 0)
g_iMaxRareWeapons = g_cvWeaponRareCap.IntValue;
}
}
}
public void OnClientPutInServer(int iClient)
{
g_iDamageZombie[iClient] = 0;
g_flTimeStartAsZombie[iClient] = 0.0;
if (AreClientCookiesCached(iClient))
OnClientCookiesCached(iClient);
if (!g_bEnabled)
return;
CreateTimer(10.0, Timer_InitialHelp, iClient, TIMER_FLAG_NO_MAPCHANGE);
DHook_HookGiveNamedItem(iClient);
SDKHook_HookClient(iClient);
}
public void OnClientDisconnect(int iClient)
{
DHook_UnhookGiveNamedItem(iClient);
if (!g_bEnabled)
return;
CheckZombieBypass(iClient);
Sound_EndAllMusic(iClient);
DropCarryingItem(iClient);
CheckLastSurvivor(iClient);
Weapons_ClientDisconnect(iClient);
}
public void OnEntityCreated(int iEntity, const char[] sClassname)
{
if (!g_bEnabled)
return;
DHook_OnEntityCreated(iEntity, sClassname);
SDKHook_OnEntityCreated(iEntity, sClassname);
if (StrEqual(sClassname, "tf_dropped_weapon") || StrEqual(sClassname, "item_powerup_rune")) //Never allow dropped weapon and rune dropped from survivors
RemoveEntity(iEntity);
}
public void OnEntityDestroyed(int iEntity)
{
if (!g_bEnabled || iEntity == INVALID_ENT_REFERENCE)
return;
char sClassname[256];
GetEntityClassname(iEntity, sClassname, sizeof(sClassname));
if (StrEqual(sClassname, "tf_gas_manager"))
{
// Gas manager don't call EndTouch on delete, we'll have to manually call it
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (!IsValidLivingSurvivor(iClient))
continue;
float vecOrigin[3], vecMins[3], vecMaxs[3];
GetClientAbsOrigin(iClient, vecOrigin);
GetClientMins(iClient, vecMins);
GetClientMaxs(iClient, vecMaxs);
TR_ClipRayHullToEntity(vecOrigin, vecOrigin, vecMins, vecMaxs, MASK_PLAYERSOLID, iEntity);
if (TR_DidHit())
GasManager_EndTouch(iEntity, iClient);
}
}
}
public void TF2_OnWaitingForPlayersStart()
{
if (!g_bEnabled)
return;
g_nRoundState = SZFRoundState_Setup;
}
public void TF2_OnWaitingForPlayersEnd()
{
if (!g_bEnabled)
return;
g_nRoundState = SZFRoundState_Grace;
}
public void TF2_OnConditionAdded(int iClient, TFCond nCond)
{
if (!g_bEnabled)
return;
SDKCall_SetSpeed(iClient);
if (IsSurvivor(iClient))
{
switch (nCond)
{
case TFCond_Disguising:
{
// Prevent able to disguise as spy, can't show zombie model of it
while (view_as<TFClassType>(GetEntProp(iClient, Prop_Send, "m_nDesiredDisguiseClass")) == TFClass_Spy)
SetEntProp(iClient, Prop_Send, "m_nDesiredDisguiseClass", GetRandomInt(view_as<int>(TFClass_Scout), view_as<int>(TFClass_Engineer)));
}
case TFCond_Gas:
{
//Dont give gas cond from spitter
TF2_RemoveCondition(iClient, TFCond_Gas);
}
}
}
else if (IsZombie(iClient))
{
switch (nCond)
{
case TFCond_Taunting:
{
//Prevents tank from getting stunned by Holiday Punch and disallows taunt kills
if (g_nInfected[iClient] == Infected_Tank && g_nRoundState == SZFRoundState_Active)
TF2_RemoveCondition(iClient, nCond);
}
}
}
}
public void TF2_OnConditionRemoved(int iClient, TFCond nCond)
{
if (!g_bEnabled)
return;
SDKCall_SetSpeed(iClient);
if (nCond == TFCond_Taunting)
ViewModel_UpdateClient(iClient); // taunting removes EF_NODRAW from weapon, readd it back
else if (nCond == TFCond_Disguised)
SetEntProp(iClient, Prop_Send, "m_nModelIndexOverrides", 0, _, VISION_MODE_ROME); //Reset disguise model
}
public Action TF2_OnIsHolidayActive(TFHoliday nHoliday, bool &bResult)
{
if (!g_bEnabled)
return Plugin_Continue;
//Force enable a holiday to allow zombie voodoo soul to work
//Shouldnt touch any other holidays as it may affect unneeded changes
if (nHoliday == TFHoliday_HalloweenOrFullMoon)
{
bResult = true;
return Plugin_Changed;
}
return Plugin_Continue;
}
void EndGracePeriod()
{
if (!g_bEnabled)
return;
if (g_nRoundState != SZFRoundState_Grace)
return; //No point in ending grace period if it's not grace period it in the first place.
g_nRoundState = SZFRoundState_Active;
CPrintToChatAll("%t", "Grace_End", "{orange}");
//Disable func_respawnroom so clients dont accidentally respawn and join zombie
int iEntity = -1;
while ((iEntity = FindEntityByClassname(iEntity, "func_respawnroom")) != -1)
{
if (view_as<TFTeam>(GetEntProp(iEntity, Prop_Send, "m_iTeamNum")) == TFTeam_Survivor)
RemoveEntity(iEntity);
}
g_flRoundStarted = GetGameTime();
g_flTimeProgress = 0.0;
g_hTimerProgress = CreateTimer(6.0, Timer_Progress, _, TIMER_REPEAT);
g_FrenzyEvent.SetCooldown();
g_TankEvent.SetCooldown();
g_flInfectedInterval = GetGameTime();
g_aSurvivorDeathTimes.Clear();
}
////////////////////////////////////////////////////////////
//
// Periodic Timer Callbacks
//
////////////////////////////////////////////////////////////
public Action Timer_Main(Handle hTimer) //1 second
{
if (!g_bEnabled)
return Plugin_Continue;
Handle_SurvivorAbilities();
Handle_ZombieAbilities();
UpdateZombieDamageScale();
Sound_Timer();
if (g_bZombieRage)
SetTeamRespawnTime(TFTeam_Zombie, 0.0);
else
SetTeamRespawnTime(TFTeam_Zombie, fMax(6.0, 12.0 / fMax(0.6, g_flZombieDamageScale)));