forked from SilvDev/Various_Scripts_Collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
l4d_anomaly.sp
1170 lines (928 loc) · 37.5 KB
/
l4d_anomaly.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
/*
* Anomaly
* Copyright (C) 2024 Silvers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define PLUGIN_VERSION "1.13"
/*======================================================================================
Plugin Info:
* Name : [L4D & L4D2] Anomaly
* Author : SilverShot
* Descrp : Randomly spawns an anomaly somewhere on the map that moves around and electrocutes people.
* Link : https://forums.alliedmods.net/showthread.php?t=321872
* Plugins : https://sourcemod.net/plugins.php?exact=exact&sortby=title&search=1&author=Silvers
========================================================================================
Change Log:
1.13 (23-Jan-2024)
- Added cvar "l4d_anomaly_movement" to control if players can be moving or stationary to be ignored anomaly. Requested by "JustMadMan".
- Changes to fix the Anomaly being able to damage through floors. Thanks to "JustMadMan" for reporting.
1.12 (10-Jan-2024)
- Fixed the "l4d_anomaly_modes_tog" cvar detecting Versus and Survival modes incorrectly.
1.11 (22-Nov-2023)
- Added command "sm_anomoff" to remove all anomalies. Requested by "kochiurun119".
- Changed command "sm_anom" to allow specifying a time until spawn, this overrides the minimum spawn flow distance. Requested by "kochiurun119".
1.10 (20-Sep-2022)
- Added cvars "l4d_anomaly_type_infected", "l4d_anomaly_type_special", "l4d_anomaly_type_survivor" and "l4d_anomaly_type_witch" to control the damage type.
- Requested by "Sam B".
1.9 (25-Jun-2022)
- Changed the classname of the anomaly to prevent conflicts with other plugins that were expecting an actual "prop_physics" entity.
1.8 (18-Nov-2021)
- Changed forward "L4D_OnGameModeChange" to be compatible with "Left4DHooks" plugin version 1.63 and newer.
- Compatibility support for SourceMod 1.11. Fixed various warnings.
- Removed some old unused code.
1.7 (12-Sep-2021)
- Fixed plugin conflict with those detecting the "tank_rock" entity. Thanks to "sonic155" for reporting.
- Now using the new "Left4DHooks" native and forward: "L4D_GetGameModeType" and "L4D_OnGameModeChange".
- Requires "Left4DHooks" version "1.54" or newer.
1.6 (20-Jun-2021)
- Fixed not deleting the Anomaly when the plugin was toggled off.
1.5 (10-Apr-2021)
- Fixed affecting players who have not spawned and are Special Infected ghosts.
- Fixed damage cvars not applying correctly to Special Infected.
1.4 (15-May-2020)
- Replaced "point_hurt" entity with "SDKHooks_TakeDamage" function.
1.3 (10-May-2020)
- Extra checks to prevent "IsAllowedGameMode" throwing errors.
- Various changes to tidy up code.
1.2 (01-Apr-2020)
- Fixed "IsAllowedGameMode" from throwing errors when the "_tog" cvar was changed before MapStart.
1.1 (05-Mar-2020)
- Now spawns in the same place for both Versus teams.
1.0 (04-Mar-2020)
- Initial release.
======================================================================================*/
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
// #include <left4dhooks>
// Instead of using the include above. Adding these here so it compiles on the forum. Plugin will fail without left4dhooks being present anyway.
native bool L4D_GetRandomPZSpawnPosition(int client, int zombieClass, int attempts, float vecPos[3]);
native float L4D2Direct_GetFlowDistance(int client);
native float L4D2Direct_GetMapMaxFlowDistance();
native int L4D_GetHighestFlowSurvivor();
native int L4D_GetGameModeType();
#define CVAR_FLAGS FCVAR_NOTIFY
#define DEBUG 0 // 0=Off. 1=Flow + location. 2=With glow outline.
#define GROUND_HEIGHT 40.0 // Height to spawn above ground
#define TICK_THINK 0.1 // How often the think tick fires
#define TICK_MOVE 2.0 // How often the move tick fires
#define TICK_HEIGHT 1.0 // How often the height tick fires
#define MODEL_SPRITE "models/sprites/glow01.spr"
#define PARTICLE_ELMOS "st_elmos_fire_cp0"
#define PARTICLE_TES1 "electrical_arc_01"
#define PARTICLE_TES2 "electrical_arc_01_system"
#define PARTICLE_TES3 "st_elmos_fire"
#define SOUND_VENDOR1 "ambient/spacial_loops/vendingmachinehum_loop.wav"
#define SOUND_VENDOR2 "ambient/ambience/generator_amb01_loop.wav"
#define SOUND_VENDOR3 "ambient/spacial_loops/fluorescent_lights_loop.wav"
static const char g_sSoundsZap[][] =
{
"ambient/energy/zap1.wav",
"ambient/energy/zap2.wav",
"ambient/energy/zap3.wav",
"ambient/energy/zap5.wav",
"ambient/energy/zap6.wav",
"ambient/energy/zap7.wav",
"ambient/energy/zap8.wav",
"ambient/energy/zap9.wav"
};
ConVar g_hCvarMPGameMode, g_hCvarAllow, g_hCvarModes, g_hCvarModesOff, g_hCvarModesTog, g_hCvarDamageDist, g_hCvarDamageInfe, g_hCvarDamageSpec, g_hCvarDamageSurv, g_hCvarDamageWitch, g_hCvarDamageTime,
g_hCvarMovement, g_hCvarRandDist, g_hCvarRandMax, g_hCvarRandMin, g_hCvarSpawnMax, g_hCvarSpawnMin, g_hCvarTypeInfe, g_hCvarTypeSpec, g_hCvarTypeSurv, g_hCvarTypeWitch;
Handle g_hTimer;
bool g_bCvarAllow, g_bLeft4Dead2;
float g_fCvarDamageDist, g_fCvarDamageTime, g_fCvarRandDist, g_fCvarRandMax, g_fCvarRandMin, g_fCvarSpawnMax, g_fCvarSpawnMin, g_fFlowMax, g_fFlowMin, g_fRandNext;
float g_fTickDmgs, g_fTickMove, g_fTickHeight, g_vLastPos[3], g_vSpawnPos[3];
int g_iCvarDamageInfe, g_iCvarDamageSpec, g_iCvarDamageSurv, g_iCvarDamageWitch, g_iCvarMovement, g_iCvarTypeInfe, g_iCvarTypeSpec, g_iCvarTypeSurv, g_iCvarTypeWitch;
int g_iAnomaly;
int g_iLighting;
int g_iPlayerSpawn, g_iRoundStart;
// ====================================================================================================
// PLUGIN
// ====================================================================================================
public Plugin myinfo =
{
name = "[L4D & L4D2] Anomaly",
author = "SilverShot",
description = "Randomly spawns an anomaly somewhere on the map that moves around and electrocutes people.",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=321872"
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
EngineVersion test = GetEngineVersion();
if( test == Engine_Left4Dead ) g_bLeft4Dead2 = false;
else if( test == Engine_Left4Dead2 ) g_bLeft4Dead2 = true;
else
{
strcopy(error, err_max, "Plugin only supports Left 4 Dead 1 & 2.");
return APLRes_SilentFailure;
}
return APLRes_Success;
}
public void OnPluginStart()
{
// ====================================================================================================
// CVARS
// ====================================================================================================
g_hCvarAllow = CreateConVar( "l4d_anomaly_allow", "1", "0=Plugin off, 1=Plugin on.", CVAR_FLAGS );
g_hCvarModes = CreateConVar( "l4d_anomaly_modes", "", "Turn on the plugin in these game modes, separate by commas (no spaces). (Empty = all).", CVAR_FLAGS );
g_hCvarModesOff = CreateConVar( "l4d_anomaly_modes_off", "", "Turn off the plugin in these game modes, separate by commas (no spaces). (Empty = none).", CVAR_FLAGS );
g_hCvarModesTog = CreateConVar( "l4d_anomaly_modes_tog", "0", "Turn on the plugin in these game modes. 0=All, 1=Coop, 2=Survival, 4=Versus, 8=Scavenge. Add numbers together.", CVAR_FLAGS );
g_hCvarDamageDist = CreateConVar( "l4d_anomaly_damage_distance", "250.0", "How close entities must be to the anomaly before being struck.", CVAR_FLAGS );
g_hCvarDamageInfe = CreateConVar( "l4d_anomaly_damage_infected", "20", "0.0=Off, also disables effects. The amount of damage to deal to Common Infected when being struck.", CVAR_FLAGS );
g_hCvarDamageSpec = CreateConVar( "l4d_anomaly_damage_special", "20", "0.0=Off, also disables effects. The amount of damage to deal to Special Infected when being struck.", CVAR_FLAGS );
g_hCvarDamageSurv = CreateConVar( "l4d_anomaly_damage_survivor", "10", "0.0=Off, also disables effects. The amount of damage to deal to Survivors when being struck.", CVAR_FLAGS );
g_hCvarDamageWitch = CreateConVar( "l4d_anomaly_damage_witch", "50", "0.0=Off, also disables effects. The amount of damage to deal to Witches when being struck.", CVAR_FLAGS );
g_hCvarDamageTime = CreateConVar( "l4d_anomaly_damage_time", "1.5", "How often to damage entities within range.", CVAR_FLAGS );
g_hCvarMovement = CreateConVar( "l4d_anomaly_movement", "1", "Ignore shooting players who are moving slower than this: 0=Off, 1=Stationary, 2=Crouch walking, 3=Walking.", CVAR_FLAGS );
g_hCvarRandDist = CreateConVar( "l4d_anomaly_random_dist", "200.0", "How far can random sparks shoot out. These do not affect players and only visual effect.", CVAR_FLAGS );
g_hCvarRandMax = CreateConVar( "l4d_anomaly_random_max", "5.0", "0.0=Off. Display random sparks and sound after this many seconds maximum.", CVAR_FLAGS );
g_hCvarRandMin = CreateConVar( "l4d_anomaly_random_min", "2.0", "0.0=Off. Display random sparks and sound after this many seconds minimum.", CVAR_FLAGS );
g_hCvarSpawnMax = CreateConVar( "l4d_anomaly_spawn_max", "70.0", "0.0=Off. Automatically spawns anomaly when Survivors pass between this minimum and maximum map flow distance percent.", CVAR_FLAGS, true, 0.0, true, 100.0 );
g_hCvarSpawnMin = CreateConVar( "l4d_anomaly_spawn_min", "20.0", "0.0=Off. Automatically spawns anomaly when Survivors pass between this minimum and maximum map flow distance percent.", CVAR_FLAGS, true, 0.0, true, 100.0 );
g_hCvarTypeInfe = CreateConVar( "l4d_anomaly_type_infected", g_bLeft4Dead2 ? "33554432" : "536870912", "The type of damage to deal to Common Infected.", CVAR_FLAGS );
g_hCvarTypeSpec = CreateConVar( "l4d_anomaly_type_special", "16777216", "The type of damage to deal to Special Infected.", CVAR_FLAGS );
g_hCvarTypeSurv = CreateConVar( "l4d_anomaly_type_survivor", "16777216", "The type of damage to deal to Survivors.", CVAR_FLAGS );
g_hCvarTypeWitch = CreateConVar( "l4d_anomaly_type_witch", "64", "The type of damage to deal to Witches.", CVAR_FLAGS );
CreateConVar( "l4d_anomaly_version", PLUGIN_VERSION, "Anomaly plugin version.", FCVAR_NOTIFY|FCVAR_DONTRECORD);
AutoExecConfig(true, "l4d_anomaly");
g_hCvarMPGameMode = FindConVar("mp_gamemode");
g_hCvarAllow.AddChangeHook(ConVarChanged_Allow);
g_hCvarModes.AddChangeHook(ConVarChanged_Allow);
g_hCvarModesOff.AddChangeHook(ConVarChanged_Allow);
g_hCvarModesTog.AddChangeHook(ConVarChanged_Allow);
g_hCvarDamageDist.AddChangeHook(ConVarChanged_Cvars);
g_hCvarDamageInfe.AddChangeHook(ConVarChanged_Cvars);
g_hCvarDamageSpec.AddChangeHook(ConVarChanged_Cvars);
g_hCvarDamageSurv.AddChangeHook(ConVarChanged_Cvars);
g_hCvarDamageWitch.AddChangeHook(ConVarChanged_Cvars);
g_hCvarDamageTime.AddChangeHook(ConVarChanged_Cvars);
g_hCvarMovement.AddChangeHook(ConVarChanged_Cvars);
g_hCvarRandMax.AddChangeHook(ConVarChanged_Cvars);
g_hCvarRandMin.AddChangeHook(ConVarChanged_Cvars);
g_hCvarSpawnMax.AddChangeHook(ConVarChanged_Cvars);
g_hCvarSpawnMin.AddChangeHook(ConVarChanged_Cvars);
g_hCvarTypeInfe.AddChangeHook(ConVarChanged_Cvars);
g_hCvarTypeSpec.AddChangeHook(ConVarChanged_Cvars);
g_hCvarTypeSurv.AddChangeHook(ConVarChanged_Cvars);
g_hCvarTypeWitch.AddChangeHook(ConVarChanged_Cvars);
// ====================================================================================================
// COMMANDS
// ====================================================================================================
RegAdminCmd("sm_anomaly", CmdAnomaly, ADMFLAG_ROOT, "Create an Anomaly where your crosshair is pointing.");
RegAdminCmd("sm_anom", CmdAnom, ADMFLAG_ROOT, "Create an Anomaly near you using the random spawn placement system. [Optional arg: number of seconds until spawn].");
RegAdminCmd("sm_anomoff", CmdRemove, ADMFLAG_ROOT, "Removes any active anomaly.");
}
public void OnPluginEnd()
{
DeleteAnomaly(g_iAnomaly);
}
public void OnMapEnd()
{
g_iRoundStart = 0;
g_iPlayerSpawn = 0;
g_vSpawnPos = view_as<float>({ 0.0, 0.0, 0.0 });
DeleteAnomaly(g_iAnomaly);
delete g_hTimer;
}
public void OnMapStart()
{
PrecacheModel(MODEL_SPRITE);
PrecacheParticle(PARTICLE_ELMOS);
PrecacheParticle(PARTICLE_TES1);
PrecacheParticle(PARTICLE_TES2);
PrecacheParticle(PARTICLE_TES3);
PrecacheSound(SOUND_VENDOR1);
PrecacheSound(SOUND_VENDOR2);
PrecacheSound(SOUND_VENDOR3);
for( int i = 0; i < sizeof(g_sSoundsZap); i++ ) PrecacheSound(g_sSoundsZap[i], true);
}
// ====================================================================================================
// COMMANDS
// ====================================================================================================
Action CmdRemove(int client, int args)
{
DeleteAnomaly(g_iAnomaly);
return Plugin_Handled;
}
Action CmdAnom(int client, int args)
{
if( !g_bCvarAllow )
{
ReplyToCommand(client, "Plugin disabled by allow or mode cvars.");
return Plugin_Handled;
}
if( args != 0 )
{
char sTemp[6];
GetCmdArg(1, sTemp, sizeof(sTemp));
float time = StringToFloat(sTemp);
if( time > 0.0 )
{
delete g_hTimer;
g_fFlowMin = 0.0;
g_hTimer = CreateTimer(time, TimerSpawn);
}
}
else
{
float vPos[3];
L4D_GetRandomPZSpawnPosition(client, g_bLeft4Dead2 ? 5 : 0, 10, vPos);
CreateAnomaly(vPos);
}
return Plugin_Handled;
}
Action CmdAnomaly(int client, int args)
{
if( !client )
{
ReplyToCommand(client, "Command can only be used %s", IsDedicatedServer() ? "in game on a dedicated server." : "in chat on a Listen server.");
return Plugin_Handled;
}
if( !g_bCvarAllow )
{
ReplyToCommand(client, "Plugin disabled by allow or mode cvars.");
return Plugin_Handled;
}
float vPos[3], vAng[3];
GetClientEyePosition(client, vPos);
GetClientEyeAngles(client, vAng);
if( SetTeleportEndPoint(client, vPos, vAng) == false )
{
ReplyToCommand(client, "Invalid position, try again.");
return Plugin_Handled;
}
vPos[2] += GROUND_HEIGHT;
CreateAnomaly(vPos);
return Plugin_Handled;
}
// ====================================================================================================
// CVARS
// ====================================================================================================
public void OnConfigsExecuted()
{
IsAllowed();
// Select the same flow distance for both Versus teams, this is called once per map.
g_fFlowMin = GetRandomFloat(g_fCvarSpawnMin, g_fCvarSpawnMax);
#if DEBUG
PrintToServer("Anomaly selected to spawn after flow: %f", g_fFlowMin);
#endif
}
void ConVarChanged_Allow(Handle convar, const char[] oldValue, const char[] newValue)
{
IsAllowed();
}
void ConVarChanged_Cvars(Handle convar, const char[] oldValue, const char[] newValue)
{
GetCvars();
}
void GetCvars()
{
g_fCvarDamageDist = g_hCvarDamageDist.FloatValue;
g_iCvarDamageInfe = g_hCvarDamageInfe.IntValue;
g_iCvarDamageSpec = g_hCvarDamageSpec.IntValue;
g_iCvarDamageSurv = g_hCvarDamageSurv.IntValue;
g_iCvarDamageWitch = g_hCvarDamageWitch.IntValue;
g_fCvarDamageTime = g_hCvarDamageTime.FloatValue;
g_iCvarMovement = g_hCvarMovement.IntValue;
g_fCvarRandDist = g_hCvarRandDist.FloatValue;
g_fCvarRandMax = g_hCvarRandMax.FloatValue;
g_fCvarRandMin = g_hCvarRandMin.FloatValue;
g_fCvarSpawnMax = g_hCvarSpawnMax.FloatValue;
g_fCvarSpawnMin = g_hCvarSpawnMin.FloatValue;
g_iCvarTypeInfe = g_hCvarTypeInfe.IntValue;
g_iCvarTypeSpec = g_hCvarTypeSpec.IntValue;
g_iCvarTypeSurv = g_hCvarTypeSurv.IntValue;
g_iCvarTypeWitch = g_hCvarTypeWitch.IntValue;
if( g_fCvarSpawnMin && g_fCvarSpawnMax )
g_fFlowMin = GetRandomFloat(g_fCvarSpawnMin, g_fCvarSpawnMax);
}
void IsAllowed()
{
bool bCvarAllow = g_hCvarAllow.BoolValue;
bool bAllowMode = IsAllowedGameMode();
GetCvars();
if( g_bCvarAllow == false && bCvarAllow == true && bAllowMode == true )
{
g_bCvarAllow = true;
CreateTimer(1.0, TimerStart, _, TIMER_FLAG_NO_MAPCHANGE);
HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_PostNoCopy);
}
else if( g_bCvarAllow == true && (bCvarAllow == false || bAllowMode == false) )
{
g_bCvarAllow = false;
DeleteAnomaly(g_iAnomaly);
delete g_hTimer;
UnhookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
UnhookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
UnhookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_PostNoCopy);
}
}
int g_iCurrentMode;
public void L4D_OnGameModeChange(int gamemode)
{
g_iCurrentMode = gamemode;
}
bool IsAllowedGameMode()
{
if( g_hCvarMPGameMode == null )
return false;
int iCvarModesTog = g_hCvarModesTog.IntValue;
if( iCvarModesTog != 0 )
{
if( g_iCurrentMode == 0 )
g_iCurrentMode = L4D_GetGameModeType();
if( g_iCurrentMode == 0 )
return false;
switch( g_iCurrentMode ) // Left4DHooks values are flipped for these modes, sadly
{
case 2: g_iCurrentMode = 4;
case 4: g_iCurrentMode = 2;
}
if( !(iCvarModesTog & g_iCurrentMode) )
return false;
}
char sGameModes[64], sGameMode[64];
g_hCvarMPGameMode.GetString(sGameMode, sizeof(sGameMode));
Format(sGameMode, sizeof(sGameMode), ",%s,", sGameMode);
g_hCvarModes.GetString(sGameModes, sizeof(sGameModes));
if( sGameModes[0] )
{
Format(sGameModes, sizeof(sGameModes), ",%s,", sGameModes);
if( StrContains(sGameModes, sGameMode, false) == -1 )
return false;
}
g_hCvarModesOff.GetString(sGameModes, sizeof(sGameModes));
if( sGameModes[0] )
{
Format(sGameModes, sizeof(sGameModes), ",%s,", sGameModes);
if( StrContains(sGameModes, sGameMode, false) != -1 )
return false;
}
return true;
}
// ====================================================================================================
// ANOMALY SPAWN
// ====================================================================================================
void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
g_iRoundStart = 0;
g_iPlayerSpawn = 0;
DeleteAnomaly(g_iAnomaly);
delete g_hTimer;
}
void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
if( g_iPlayerSpawn == 1 && g_iRoundStart == 0 )
CreateTimer(1.0, TimerStart, _, TIMER_FLAG_NO_MAPCHANGE);
g_iRoundStart = 1;
}
void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
if( g_iPlayerSpawn == 0 && g_iRoundStart == 1 )
CreateTimer(1.0, TimerStart, _, TIMER_FLAG_NO_MAPCHANGE);
g_iPlayerSpawn = 1;
}
Action TimerStart(Handle timer)
{
g_fFlowMax = L4D2Direct_GetMapMaxFlowDistance();
if( g_fFlowMin && g_hTimer == null ) g_hTimer = CreateTimer(1.0, TimerSpawn, _, TIMER_REPEAT);
return Plugin_Continue;
}
Action TimerSpawn(Handle timer)
{
float flow;
int client = L4D_GetHighestFlowSurvivor();
if( client > 0 )
{
flow = L4D2Direct_GetFlowDistance(client);
if( flow )
{
flow = flow / g_fFlowMax * 100;
}
}
if( flow > g_fFlowMin )
{
float vPos[3];
// Versus same spawn pos for both teams
if( g_iCurrentMode == 4 && g_vSpawnPos[0] != 0.0 && g_vSpawnPos[1] != 0.0 )
{
vPos = g_vSpawnPos;
}
else
{
// GetClientAbsOrigin(client, vPos);
// int area = L4D_GetNearestNavArea(vPos);
// L4D_FindRandomSpot(area, vPos);
// Above spawns next to player.
// Hopefully within bounds and rarely out-of-bounds.
// g_bLeft4Dead2 ? 7 : 4 == Witch.
// g_bLeft4Dead2 ? 8 : 5 == Tank.
// g_bLeft4Dead2 ? 9 : 6 == Unknown.
// 0 = Common Infected, seems good for L4D1. 5 = Jockey, seems good for L4D2.
L4D_GetRandomPZSpawnPosition(client, g_bLeft4Dead2 ? 5 : 0, 10, vPos);
if( g_iCurrentMode == 4 )
g_vSpawnPos = vPos;
}
CreateAnomaly(vPos);
#if DEBUG
PrintToServer("Anomaly auto spawning at: %f %f %f", vPos[0], vPos[1], vPos[2]);
#endif
g_hTimer = null;
return Plugin_Stop;
}
return Plugin_Continue;
}
// ====================================================================================================
// ANOMALY CREATE
// ====================================================================================================
void DeleteAnomaly(int entity)
{
if( entity && EntRefToEntIndex(entity) != INVALID_ENT_REFERENCE )
{
StopSound(entity, SNDCHAN_AUTO, SOUND_VENDOR1);
StopSound(entity, SNDCHAN_AUTO, SOUND_VENDOR2);
StopSound(entity, SNDCHAN_AUTO, SOUND_VENDOR3);
// Prevent plugin conflicts for any plugins detecting "tank_rock" in "OnEntityDestroyed":
DispatchKeyValue(entity, "classname", "anomaly");
RemoveEntity(entity);
}
}
void CreateAnomaly(float vPos[3])
{
// Only supports 1 anomaly at a time. No plans to change.
DeleteAnomaly(g_iAnomaly);
// Create
int entity = CreateEntityByName("tank_rock"); // DO NOT USE "pipe_bomb_projectile" or bots won't shoot any common. Using "tank_rock" to prevent "molotov_projectile" showing flames, and support L4D1.
if( entity == -1 ) return;
g_iAnomaly = EntIndexToEntRef(entity);
SetEntProp(entity, Prop_Data, "m_iHammerID", 92950); // Other plugins using "tank_rock" entity can use this ident to exclude affecting Anomaly plugin.
DispatchSpawn(entity);
// Set origin and velocity
float vVel[3];
vVel[0] = GetRandomFloat(-50.0, 50.0);
vVel[1] = GetRandomFloat(-50.0, 50.0);
vVel[2] = 0.0;
TeleportEntity(entity, vPos, NULL_VECTOR, vVel);
// Set gravity and elasticity
SetEntPropFloat(entity, Prop_Data, "m_flGravity", -0.000001);
SetEntPropFloat(entity, Prop_Data, "m_flElasticity", 1.0);
// Invisible
SetEntityRenderMode(entity, RENDER_TRANSCOLOR);
SetEntityRenderColor(entity, 0, 0, 0, 0);
// Glow debug
#if DEBUG == 2
if( g_bLeft4Dead2 )
{
SetEntProp(entity, Prop_Send, "m_iGlowType", 3);
SetEntProp(entity, Prop_Send, "m_glowColorOverride", 16737280); // 0 100 255
SetEntProp(entity, Prop_Send, "m_nGlowRange", 0);
AcceptEntityInput(entity, "StartGlowing");
}
#endif
// Effects
MakeLightDynamic(view_as<float>({0.0, 0.0, 0.0}), NULL_VECTOR, entity);
MakeEnvSprite(view_as<float>({ 0.0, 0.0, 0.0 }), view_as<float>({ 180.0, 0.0, 90.0 }), entity);
// Particles
DisplayParticle(PARTICLE_ELMOS, view_as<float>({0.0, 0.0, 0.0}), NULL_VECTOR, entity); // Pulsating
DisplayParticle(PARTICLE_TES2, view_as<float>({0.0, 0.0, 0.0}), NULL_VECTOR, entity); // Random electricity
// Sounds
EmitSoundToAll(SOUND_VENDOR1, entity, SNDCHAN_AUTO, SNDLEVEL_DISHWASHER);
EmitSoundToAll(SOUND_VENDOR2, entity, SNDCHAN_AUTO, SNDLEVEL_DISHWASHER);
if( GetRandomInt(0, 3) == 0 )
EmitSoundToAll(SOUND_VENDOR3, entity, SNDCHAN_AUTO, SNDLEVEL_DISHWASHER); // Alarm sort of sound
// Change classname to prevent conflict with other plugins detecting "tank_rock".
DispatchKeyValue(entity, "classname", "anomaly"); // Using a random classname that doesn't exist to prevent conflicts with other plugins
// Think function
g_fRandNext = 0.0;
g_fTickMove = 0.0;
g_fTickHeight = 0.0;
g_fTickDmgs = 0.0;
CreateTimer(TICK_THINK, TimerThink, g_iAnomaly, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
// ====================================================================================================
// ANOMALY THINK
// ====================================================================================================
Action TimerThink(Handle timer, int entity)
{
float fTickTime = GetGameTime();
// Validate alive
if( EntRefToEntIndex(entity) == INVALID_ENT_REFERENCE )
{
return Plugin_Stop;
}
// Stuck check
bool stuck;
float vPos[3], vEnd[3];
GetEntPropVector(entity, Prop_Data, "m_vecAbsOrigin", vEnd);
if( GetVectorDistance(vEnd, g_vLastPos) < 1.0 )
{
stuck = true;
} else {
g_vLastPos = vEnd;
}
// Random elect shots
if( g_fCvarRandMax && g_fCvarRandMin )
{
if( g_fRandNext < fTickTime )
{
g_fRandNext = fTickTime + GetRandomFloat(g_fCvarRandMin, g_fCvarRandMax);
// Random angle
float vAng[3];
vAng[0] = GetRandomFloat(-90.0, 90.0);
vAng[1] = GetRandomFloat(-180.0, 180.0);
vPos = vEnd;
// Trace to nearest wall, if any
if( SetTeleportEndPoint(EntRefToEntIndex(entity), vPos, vAng) )
{
float dist = GetVectorDistance(vPos, vEnd);
if( dist > g_fCvarRandDist ) dist = g_fCvarRandDist;
else dist -= 10.0; // Slightly away from surfaces
NormalizeVector(vAng, vAng);
vPos[0] = vEnd[0] + (vAng[0] * dist);
vPos[1] = vEnd[1] + (vAng[1] * dist);
vPos[2] = vEnd[2] + (vAng[2] * dist);
TeslaShock(entity, 0, vPos);
PlaySound(entity, g_sSoundsZap[GetRandomInt(0, sizeof(g_sSoundsZap) - 1)]);
}
}
}
// Change velocity direction
if( g_fTickMove < fTickTime )
{
g_fTickMove = fTickTime + TICK_MOVE;
// 1 in 4 chance to change direction
if( stuck || GetRandomInt(0, 3) == 0 )
{
vPos[0] = GetRandomFloat(-50.0, 50.0);
vPos[1] = GetRandomFloat(-50.0, 50.0);
vPos[2] = 0.0;
TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, vPos);
}
}
else
{
// Keep average height above ground
if( g_fTickHeight < fTickTime )
{
g_fTickHeight = fTickTime + TICK_HEIGHT;
vPos = vEnd;
if( SetTeleportEndPoint(EntRefToEntIndex(entity), vPos, view_as<float>({ 89.0, 0.0, 0.0 })) ) // Trace down
{
float height = vEnd[2] - vPos[2];
if( height > 65 )
{
GetEntPropVector(entity, Prop_Data, "m_vecAbsVelocity", vPos);
vPos[2] = -5.0;
TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, vPos);
}
else if( height < 40 )
{
GetEntPropVector(entity, Prop_Data, "m_vecAbsVelocity", vPos);
vPos[2] = 5.0;
TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, vPos);
}
else
{
GetEntPropVector(entity, Prop_Data, "m_vecAbsVelocity", vPos);
vPos[2] = 0.0;
TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, vPos);
}
}
}
}
// Damage check
if( g_fTickDmgs < fTickTime )
{
g_fTickDmgs = fTickTime + g_fCvarDamageTime;
float distance;
for( int i = 1; i <= MaxClients; i++ )
{
if( IsClientInGame(i) && IsPlayerAlive(i) )
{
// Ignore players who are stationary, crouch walking or walking
if( g_iCvarMovement )
{
GetEntPropVector(i, Prop_Data, "m_vecAbsVelocity", vPos);
distance = GetVectorLength(vPos);
switch( g_iCvarMovement )
{
case 1: if( distance < 1 ) continue;
case 2: if( distance < 76 ) continue;
case 3: if( distance < 86 ) continue;
}
}
GetClientAbsOrigin(i, vPos);
if( GetVectorDistance(vPos, vEnd) < g_fCvarDamageDist )
{
DoDamage(entity, i, vPos);
}
}
}
int infected = -1;
if( g_iCvarDamageInfe )
{
while( (infected = FindEntityByClassname(infected, "infected")) != INVALID_ENT_REFERENCE )
{
GetEntPropVector(infected, Prop_Data, "m_vecOrigin", vPos);
if( GetVectorDistance(vPos, vEnd) < g_fCvarDamageDist )
{
DoDamage(entity, infected, vPos, 4);
}
}
}
infected = -1;
if( g_iCvarDamageWitch )
{
while( (infected = FindEntityByClassname(infected, "witch")) != INVALID_ENT_REFERENCE )
{
GetEntPropVector(infected, Prop_Data, "m_vecOrigin", vPos);
if( GetVectorDistance(vPos, vEnd) < g_fCvarDamageDist )
{
DoDamage(entity, infected, vPos, 5);
}
}
}
}
return Plugin_Continue;
}
// ====================================================================================================
// TESLA SHOCK
// ====================================================================================================
int g_iLastLight;
void DoDamage(int entity, int client, float vPos[3], int type = 0)
{
// Type
if( client <= MaxClients )
{
int team = GetClientTeam(client);
if( g_iCvarDamageSurv && team == 2 )
type = 2;
else if( g_iCvarDamageSpec && team == 3 && GetEntProp(client, Prop_Send, "m_isGhost") == 0 )
type = 3;
}
if( type == 0 ) return;
// Visible
float vEnd[3];
GetEntPropVector(entity, Prop_Data, "m_vecOrigin", vEnd);
if( IsVisibleTo(EntRefToEntIndex(entity), vEnd, vPos) == false ) return;
// Damage
switch( type )
{
case 2: SDKHooks_TakeDamage(client, entity, entity, float(g_iCvarDamageSurv), g_iCvarTypeSurv, -1, NULL_VECTOR, vEnd); // Survivor
case 3: SDKHooks_TakeDamage(client, entity, entity, float(g_iCvarDamageSpec), g_iCvarTypeSpec, -1, NULL_VECTOR, vEnd); // Special Infected
case 4: SDKHooks_TakeDamage(client, entity, entity, float(g_iCvarDamageInfe), g_iCvarTypeInfe, -1, NULL_VECTOR, vEnd); // Common L4D2 / L4D1
case 5: SDKHooks_TakeDamage(client, entity, entity, float(g_iCvarDamageWitch),g_iCvarTypeWitch, -1, NULL_VECTOR, vEnd); // Witch
}
// Teleport
if( type == 2 || type == 3 )
{
MakeVectorFromPoints(vEnd, vPos, vEnd);
NormalizeVector(vEnd, vEnd);
ScaleVector(vEnd, 400.0);
vEnd[2] = 300.0;
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vEnd);
}
// Effects
TeslaShock(entity, client);
// Light color
if( !g_iLastLight && g_iLighting && EntRefToEntIndex(g_iLighting) != INVALID_ENT_REFERENCE )
{
g_iLastLight = 250;
DispatchKeyValue(g_iLighting, "_light", "250 50 150 255");
CreateTimer(0.1, TimerColor, _, TIMER_REPEAT);
}
}
Action TimerColor(Handle timer)
{
if( !g_iLighting || EntRefToEntIndex(g_iLighting) == INVALID_ENT_REFERENCE ) return Plugin_Stop;
g_iLastLight -= 10;
if( g_iLastLight <= 0 )
{
g_iLastLight = 0;
return Plugin_Stop;
}
static char temp[16];
Format(temp, sizeof(temp), "%d 50 150 255", g_iLastLight);
DispatchKeyValue(g_iLighting, "_light", temp);
return Plugin_Continue;
}
void TeslaShock(int grenade, int target, float vEnd[3] = NULL_VECTOR)
{
static char sTemp[32];
float vPos[3];
int entity;
int iType = GetRandomInt(0, 1);
// PARTICLE TARGET
entity = CreateEntityByName(g_bLeft4Dead2 ? "info_particle_target" : "info_particle_system");
if( iType == 0 )
DispatchKeyValue(entity, "effect_name", PARTICLE_TES1);
else if( iType == 1 )
DispatchKeyValue(entity, "effect_name", PARTICLE_TES3);
Format(sTemp, sizeof(sTemp), "tesla%d%d%d", entity, grenade, target);
DispatchKeyValue(entity, "targetname", sTemp);
SetVariantString("!activator");
AcceptEntityInput(entity, "SetParent", grenade);
vPos[2] = 1.0;
TeleportEntity(entity, vPos, NULL_VECTOR, NULL_VECTOR);
DispatchSpawn(entity);
ActivateEntity(entity);
AcceptEntityInput(entity, "Start");
InputKill(entity, 1.5);
// PARTICLE
entity = CreateEntityByName("info_particle_system");
DispatchKeyValue(entity, "cpoint1", sTemp);
if( iType == 0 )
DispatchKeyValue(entity, "effect_name", PARTICLE_TES1);
else if( iType == 1 )
DispatchKeyValue(entity, "effect_name", PARTICLE_TES3);
AcceptEntityInput(entity, "Start");
if( target )
{
SetVariantString("!activator");
AcceptEntityInput(entity, "SetParent", target);
vPos[2] = GetRandomFloat(20.0, 50.0);
TeleportEntity(entity, vPos, NULL_VECTOR, NULL_VECTOR);
} else {
TeleportEntity(entity, vEnd, NULL_VECTOR, NULL_VECTOR);
}
DispatchSpawn(entity);
ActivateEntity(entity);
InputKill(entity, 1.5);
// SOUND
PlaySound(entity, g_sSoundsZap[GetRandomInt(0, sizeof(g_sSoundsZap) - 1)]);
}
void PlaySound(int entity, const char[] sound, int level = SNDLEVEL_NORMAL)
{
EmitSoundToAll(sound, entity, level == SNDLEVEL_RAIDSIREN ? SNDCHAN_ITEM : SNDCHAN_AUTO, level);
}
void InputKill(int entity, float time)
{
static char temp[40];
Format(temp, sizeof(temp), "OnUser4 !self:Kill::%f:-1", time);
SetVariantString(temp);
AcceptEntityInput(entity, "AddOutput");
AcceptEntityInput(entity, "FireUser4");
}
// ====================================================================================================
// PARTICLES
// ====================================================================================================
int DisplayParticle(const char[] sParticle, const float vPos[3], const float vAng[3], int client = 0)
{
int entity = CreateEntityByName("info_particle_system");
if( entity != -1 )
{
DispatchKeyValue(entity, "effect_name", sParticle);
DispatchSpawn(entity);