-
Notifications
You must be signed in to change notification settings - Fork 2
/
l4d_ReverseBurn_and_ExplosionAnnouncer.sp
1327 lines (1124 loc) · 51.4 KB
/
l4d_ReverseBurn_and_ExplosionAnnouncer.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
/*
ReverseBurn and ExplosionAnnouncer (l4d_ReverseBurn_and_ExplosionAnnouncer) by Mystik Spiral
Smart reverse of burn damage from explodables (gascans, fireworks, etc.) if the victim is burned instantly and continuously.
It was created to help mitigate the damage by griefers attempting to kill/incap their teammates by burning them.
Reverses the following explodable burn types:
Gas can, barricade gas can, fuel barrel, gas pump, and fireworks crate.
Announces the following explosion types:
Gas can, barricade gas can, fuel barrel, gas pump, fireworks crate, propane tank, and oxygen tank.
Features:
- Burn damage is reversed only if victim(s) are burned instantly (within 0.75 second of ignition) and continuously (takes burn damage more than once per second).
- If player runs into fire more than 0.75 seconds after ignition, burn damage is treated normally.
- When burn damage is reversed, during each burn cycle (approximately 6x per second):
- Attacker takes 70% damage for each instantly/continuously burned victim
- Standing burn victims lose 1PermHP which is converted to 2TempHP as incentive to move out of the fire quickly.
- Before ignition, any players already incapped or with only 1TotalHP do not take any burn damage.
- Bots do not take burn damage but do move out of the fire as quickly as possible.
- Griefers cannot kill or incap a victim by burning them (victims still take some damage as stated above).
- In all other scenarios, burn damage behaves normally.
- Option to reverse burn/blast damage if attacker is an admin. [RBaTA_admin, default: 0/false]
- Option to reverse blast/explosion damage. [RBaTA_blast, default: 1/true]
- If both RBaEA and RBaTA plugins are loaded, RBaEA takes precedence to avoid both plugins reversing blast/explosion damage.
- Option to ban attacker (griefer) that disconnects during reverse burn. [RBaTA_banburndisconnect, default: 1/true]
- Option to set ban duration in minutes. [RBaTA_banduration, default: 2880 (2 days)]
Common Scenarios:
- Griefer attempts to kill the whole team by burning them.
Usual end result: Griefer takes 210% damage (70% per victim x 3 victims) plus possible additional self-damage and everyone else takes relatively minor damage.
- Player starts fire (which does not burn anyone within 0.75 seconds) and griefer runs into it.
Usual end result: Griefer takes normal damage and player that started the fire takes no damage.
Suggestion:
To minimize griefer impact, use the ReverseBurn and ExplosionAnnouncer plugin along with...
ReverseBurn and ThrowableAnnouncer (l4d_ReverseBurn_and_ThrowableAnnouncer)
- Smart reverse of burn damage from throwables, like molotovs.
- Option to reverse blast damage, like pipe bombs.
Reverse Friendly-Fire (l4d_reverse_ff)
- Reverse friendly-fire weapon damage. Attacker takes damage, victim does not.
When these three plugins are combined, griefers will usually get frustrated and leave since they cannot damage anyone other than themselves.
Although griefers will take significant damage, other players may not notice any difference in game play (except laughing at stupid griefer fails).
Credits:
This plugin began life as **[Explosion Announcer](https://forums.alliedmods.net/showthread.php?t=328006)** by Marttt. The original plugin kept track of explodable entities, when they were exploded, and announced who did it. I hooked on to that announcement to track whether that explodable (gascan, fireworks, etc.) instantly burned any other players, and if so, to ensure the attacker took the vast majority of the damage. If no other players are instantly burned, then burn damage is treated normally.
Want to contribute code enhancements?
Create a pull request using this GitHub repository:
https://github.com/Mystik-Spiral/l4d_ReverseBurn_and_ExplosionAnnouncer
Plugin discussion: https://forums.alliedmods.net/showthread.php?t=331164
*/
// ====================================================================================================
// Plugin Info - define
// ====================================================================================================
#define PLUGIN_NAME "[L4D & L4D2] ReverseBurn and ExplosionAnnouncer"
#define PLUGIN_AUTHOR "Mystik Spiral"
#define PLUGIN_DESCRIPTION "Reverses damage when victim burned instantly and continuously"
#define PLUGIN_VERSION "1.2.1"
#define PLUGIN_URL "https://forums.alliedmods.net/showthread.php?t=331164"
// ====================================================================================================
// Plugin Info
// ====================================================================================================
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = PLUGIN_DESCRIPTION,
version = PLUGIN_VERSION,
url = PLUGIN_URL
}
// ====================================================================================================
// Includes
// ====================================================================================================
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
// ====================================================================================================
// Pragmas
// ====================================================================================================
#pragma semicolon 1
#pragma newdecls required
// ====================================================================================================
// Cvar Flags
// ====================================================================================================
#define CVAR_FLAGS FCVAR_NOTIFY
#define CVAR_FLAGS_PLUGIN_VERSION FCVAR_NOTIFY|FCVAR_DONTRECORD|FCVAR_SPONLY
// ====================================================================================================
// Filenames
// ====================================================================================================
#define CONFIG_FILENAME "l4d_ReverseBurn_and_ExplosionAnnouncer" //MS
#define TRANSLATION_FILENAME "l4d_ReverseBurn_and_ExplosionAnnouncer.phrases" //MS
// ====================================================================================================
// Defines
// ====================================================================================================
#define CLASSNAME_WEAPON_GASCAN "weapon_gascan"
#define CLASSNAME_PROP_FUEL_BARREL "prop_fuel_barrel"
#define MODEL_GASCAN "models/props_junk/gascan001a.mdl"
#define MODEL_FUEL_BARREL "models/props_industrial/barrel_fuel.mdl"
#define MODEL_PROPANECANISTER "models/props_junk/propanecanister001a.mdl"
#define MODEL_OXYGENTANK "models/props_equipment/oxygentank01.mdl"
#define MODEL_BARRICADE_GASCAN "models/props_unique/wooden_barricade_gascans.mdl"
#define MODEL_GAS_PUMP "models/props_equipment/gas_pump_nodebris.mdl"
#define MODEL_FIREWORKS_CRATE "models/props_junk/explosive_box001.mdl"
#define TEAM_SPECTATOR 1
#define TEAM_SURVIVOR 2
#define TEAM_INFECTED 3
#define TEAM_HOLDOUT 4
#define FLAG_TEAM_NONE (0 << 0) // 0 | 0000
#define FLAG_TEAM_SURVIVOR (1 << 0) // 1 | 0001
#define FLAG_TEAM_INFECTED (1 << 1) // 2 | 0010
#define FLAG_TEAM_SPECTATOR (1 << 2) // 4 | 0100
#define FLAG_TEAM_HOLDOUT (1 << 3) // 8 | 1000
#define TYPE_NONE 0
#define TYPE_GASCAN 1
#define TYPE_FUEL_BARREL 2
#define TYPE_PROPANECANISTER 3
#define TYPE_OXYGENTANK 4
#define TYPE_BARRICADE_GASCAN 5
#define TYPE_GAS_PUMP 6
#define TYPE_FIREWORKS_CRATE 7
#define MAX_TYPES 7
#define MAXENTITIES 2048
// ====================================================================================================
// Plugin Cvars
// ====================================================================================================
static ConVar g_hCvar_Enabled;
static ConVar g_hCvar_SpamProtection;
static ConVar g_hCvar_SpamTypeCheck;
static ConVar g_hCvar_Team;
static ConVar g_hCvar_Self;
static ConVar g_hCvar_Gascan;
static ConVar g_hCvar_FuelBarrel;
static ConVar g_hCvar_PropaneCanister;
static ConVar g_hCvar_OxygenTank;
static ConVar g_hCvar_BarricadeGascan;
static ConVar g_hCvar_GasPump;
static ConVar g_hCvar_FireworksCrate;
static ConVar g_hCvar_PillsDecayRate; //MS
static ConVar g_hCvar_BanBurnDisconnect; //MS
static ConVar g_hCvar_BanDuration; //MS
static ConVar g_hCvar_Admin; //MS
static ConVar g_hCvar_Blast; //MS
// ====================================================================================================
// Handles
// ====================================================================================================
Handle g_hBeginBurn[MAXPLAYERS + 1]; //MS
Handle g_hFinishBurn[MAXPLAYERS + 1]; //MS
// ====================================================================================================
// bool - Plugin Variables
// ====================================================================================================
static bool g_bL4D2;
static bool g_bConfigLoaded;
static bool g_bEventsHooked;
static bool g_bCvar_Enabled;
static bool g_bCvar_SpamProtection;
static bool g_bCvar_SpamTypeCheck;
static bool g_bCvar_Team;
static bool g_bCvar_Self;
static bool g_bCvar_Gascan;
static bool g_bCvar_FuelBarrel;
static bool g_bCvar_PropaneCanister;
static bool g_bCvar_OxygenTank;
static bool g_bCvar_BarricadeGascan;
static bool g_bCvar_GasPump;
static bool g_bCvar_FireworksCrate;
static bool g_bCvar_BanBurnDisconnect; //MS
static bool g_bFirstBurn[MAXPLAYERS + 1]; //MS
static bool g_bReverseBurnAtk[MAXPLAYERS + 1]; //MS
static bool g_bReverseBurnVic[MAXPLAYERS + 1]; //MS
static bool g_bBothRBPlugins; //MS
static bool g_bAllReversePlugins; //MS
static bool g_bReverseFFPlugin; //MS
static bool g_bCvar_Admin; //MS
static bool g_bCvar_Blast; //MS
// ====================================================================================================
// int - Plugin Variables
// ====================================================================================================
static int g_iModel_Gascan = -1;
static int g_iModel_FuelBarrel = -1;
static int g_iModel_PropaneCanister = -1;
static int g_iModel_OxygenTank = -1;
static int g_iModel_BarricadeGascan = -1;
static int g_iModel_GasPump = -1;
static int g_iModel_FireworksCrate = -1;
static int g_iCvar_Team;
static int g_iCvar_BanDuration; //MS
static int g_iBurnVictim[MAXPLAYERS + 1]; //MS
static int g_iBurnToggle[MAXPLAYERS + 1]; //MS
// ====================================================================================================
// float - Plugin Variables
// ====================================================================================================
static float g_fCvar_SpamProtection;
static float gc_fLastChatOccurrence[MAXPLAYERS+1][MAX_TYPES+1];
static float g_fLastRevBurnTime[MAXPLAYERS + 1]; //MS
static float g_fPillsDecayRate; //MS
static float g_fLastBlastMsg[MAXPLAYERS + 1]; //MS
// ====================================================================================================
// entity - Plugin Variables
// ====================================================================================================
static int ge_iType[MAXENTITIES+1];
static int ge_iLastAttacker[MAXENTITIES+1];
// ====================================================================================================
// Plugin Start
// ====================================================================================================
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
EngineVersion engine = GetEngineVersion();
if (engine != Engine_Left4Dead && engine != Engine_Left4Dead2)
{
strcopy(error, err_max, "This plugin only runs in \"Left 4 Dead\" and \"Left 4 Dead 2\" game");
return APLRes_SilentFailure;
}
g_bL4D2 = (engine == Engine_Left4Dead2);
return APLRes_Success;
}
/****************************************************************************************************/
public void OnPluginStart()
{
LoadPluginTranslations();
//MS (ConVar names)
CreateConVar("RBaEA_version", PLUGIN_VERSION, PLUGIN_DESCRIPTION, CVAR_FLAGS_PLUGIN_VERSION);
g_hCvar_Enabled = CreateConVar("RBaEA_enable", "1", "Enable/Disable the plugin.\n0 = Disable, 1 = Enable.", CVAR_FLAGS, true, 0.0, true, 1.0);
g_hCvar_Admin = CreateConVar("RBaEA_admin", "0", "Reverse burn/blast when attacker is an admin.\n0 = Do not reverse burn/blast damage for admins, 1 = Reverse burn/blast damage for admins", CVAR_FLAGS, true, 0.0, true, 1.0); //MS
g_hCvar_Blast = CreateConVar("RBaEA_blast", "1", "Reverse blast damage (propane/oxygen tank, gas pump).\n0 = Do not reverse blast damage, 1 = Reverse blast damage", CVAR_FLAGS, true, 0.0, true, 1.0); //MS
g_hCvar_BanBurnDisconnect = CreateConVar("RBaEA_banburndisconnect", "1", "Ban attacker that disconnects during reverse burn.\n0 = Do not ban, 1 = Ban", CVAR_FLAGS, true, 0.0, true, 1.0); //MS
g_hCvar_BanDuration = CreateConVar("RBaEA_banduration", "2880", "Ban duration in minutes. (0 = Permanent, Default 2880 = 2 days)", CVAR_FLAGS); //MS
g_hCvar_SpamProtection = CreateConVar("RBaEA_spam_protection", "3.0", "Delay in seconds to output to the chat the message from the same client again.\n0 = OFF.", CVAR_FLAGS, true, 0.0);
g_hCvar_SpamTypeCheck = CreateConVar("RBaEA_spam_type_check", "1", "Whether the plugin should apply chat spam protection by entity type.\nExample: \"gascans\" and \"propane canisters\" are of different types.\n0 = OFF, 1 = ON.", CVAR_FLAGS, true, 0.0, true, 1.0);
g_hCvar_Team = CreateConVar("RBaEA_team", "1", "Which teams should the message be transmitted to.\n0 = NONE, 1 = SURVIVOR, 2 = INFECTED, 4 = SPECTATOR, 8 = HOLDOUT.\nAdd numbers greater than 0 for multiple options.\nExample: \"3\", enables for SURVIVOR and INFECTED.", CVAR_FLAGS, true, 0.0, true, 15.0);
g_hCvar_Self = CreateConVar("RBaEA_self", "1", "Should the message be transmitted to those who exploded it.\n0 = OFF, 1 = ON.", CVAR_FLAGS, true, 0.0, true, 1.0);
g_hCvar_Gascan = CreateConVar("RBaEA_gascan", "1", "Output to the chat every time someone explodes (last hit) a gascan.\n0 = OFF, 1 = ON.", CVAR_FLAGS, true, 0.0, true, 1.0);
g_hCvar_FuelBarrel = CreateConVar("RBaEA_fuelbarrel", "1", "Output to the chat every time someone explodes (last hit) a fuel barrel.\n0 = OFF, 1 = ON.", CVAR_FLAGS, true, 0.0, true, 1.0);
g_hCvar_PropaneCanister = CreateConVar("RBaEA_propanecanister", "1", "Output to the chat every time someone explodes (last hit) a propane canister.\n0 = OFF, 1 = ON.", CVAR_FLAGS, true, 0.0, true, 1.0);
g_hCvar_OxygenTank = CreateConVar("RBaEA_oxygentank", "1", "Output to the chat every time someone explodes (last hit) a oxygen tank.\n0 = OFF, 1 = ON.", CVAR_FLAGS, true, 0.0, true, 1.0);
g_hCvar_BarricadeGascan = CreateConVar("RBaEA_barricadegascan", "1", "Output to the chat every time someone explodes (last hit) a barricade with gascans.\n0 = OFF, 1 = ON.", CVAR_FLAGS, true, 0.0, true, 1.0);
g_hCvar_GasPump = CreateConVar("RBaEA_gaspump", "1", "Output to the chat every time someone explodes (last hit) a gas pump.\n0 = OFF, 1 = ON.", CVAR_FLAGS, true, 0.0, true, 1.0);
if (g_bL4D2)
g_hCvar_FireworksCrate = CreateConVar("RBaEA_fireworkscrate", "1", "Output to the chat every time someone explodes (last hit) a fireworks crate.\nL4D2 only.\n0 = OFF, 1 = ON.", CVAR_FLAGS, true, 0.0, true, 1.0);
g_hCvar_PillsDecayRate = FindConVar("pain_pills_decay_rate"); //MS
// Hook plugin ConVars change
g_hCvar_Enabled.AddChangeHook(Event_ConVarChanged);
g_hCvar_Admin.AddChangeHook(Event_ConVarChanged); //MS
g_hCvar_Blast.AddChangeHook(Event_ConVarChanged); //MS
g_hCvar_BanBurnDisconnect.AddChangeHook(Event_ConVarChanged); //MS
g_hCvar_BanDuration.AddChangeHook(Event_ConVarChanged); //MS
g_hCvar_SpamProtection.AddChangeHook(Event_ConVarChanged);
g_hCvar_SpamTypeCheck.AddChangeHook(Event_ConVarChanged);
g_hCvar_Team.AddChangeHook(Event_ConVarChanged);
g_hCvar_Self.AddChangeHook(Event_ConVarChanged);
g_hCvar_Gascan.AddChangeHook(Event_ConVarChanged);
g_hCvar_FuelBarrel.AddChangeHook(Event_ConVarChanged);
g_hCvar_PropaneCanister.AddChangeHook(Event_ConVarChanged);
g_hCvar_OxygenTank.AddChangeHook(Event_ConVarChanged);
g_hCvar_BarricadeGascan.AddChangeHook(Event_ConVarChanged);
g_hCvar_GasPump.AddChangeHook(Event_ConVarChanged);
if (g_bL4D2)
g_hCvar_FireworksCrate.AddChangeHook(Event_ConVarChanged);
g_hCvar_PillsDecayRate.AddChangeHook(Event_ConVarChanged); //MS
// Load plugin configs from .cfg
AutoExecConfig(true, CONFIG_FILENAME);
// Admin Commands
RegAdminCmd("sm_print_cvars_l4d_explosion_announcer", CmdPrintCvars, ADMFLAG_ROOT, "Prints the plugin related cvars and their respective values to the console.");
}
public void LoadPluginTranslations()
{
char path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, PLATFORM_MAX_PATH, "translations/%s.txt", TRANSLATION_FILENAME);
if (FileExists(path))
LoadTranslations(TRANSLATION_FILENAME);
else
SetFailState("Missing required translation file on \"translations/%s.txt\", please re-download.", TRANSLATION_FILENAME);
}
/****************************************************************************************************/
public void OnMapStart()
{
g_iModel_Gascan = PrecacheModel(MODEL_GASCAN, true);
g_iModel_FuelBarrel = PrecacheModel(MODEL_FUEL_BARREL, true);
g_iModel_PropaneCanister = PrecacheModel(MODEL_PROPANECANISTER, true);
g_iModel_OxygenTank = PrecacheModel(MODEL_OXYGENTANK, true);
g_iModel_BarricadeGascan = PrecacheModel(MODEL_BARRICADE_GASCAN, true);
g_iModel_GasPump = PrecacheModel(MODEL_GAS_PUMP, true);
if (g_bL4D2)
g_iModel_FireworksCrate = PrecacheModel(MODEL_FIREWORKS_CRATE, true);
}
/****************************************************************************************************/
public void OnConfigsExecuted()
{
GetCvars();
g_bConfigLoaded = true;
LateLoad();
HookEvents(g_bCvar_Enabled);
}
/****************************************************************************************************/
public void Event_ConVarChanged(Handle convar, const char[] sOldValue, const char[] sNewValue)
{
GetCvars();
HookEvents(g_bCvar_Enabled);
}
/****************************************************************************************************/
public void GetCvars()
{
g_bCvar_Enabled = g_hCvar_Enabled.BoolValue;
g_fCvar_SpamProtection = g_hCvar_SpamProtection.FloatValue;
g_bCvar_SpamProtection = (g_fCvar_SpamProtection > 0.0);
g_bCvar_SpamTypeCheck = g_hCvar_SpamTypeCheck.BoolValue;
g_iCvar_Team = g_hCvar_Team.IntValue;
g_bCvar_Team = (g_iCvar_Team > 0);
g_bCvar_Self = g_hCvar_Self.BoolValue;
g_bCvar_Gascan = g_hCvar_Gascan.BoolValue;
g_bCvar_FuelBarrel = g_hCvar_FuelBarrel.BoolValue;
g_bCvar_PropaneCanister = g_hCvar_PropaneCanister.BoolValue;
g_bCvar_OxygenTank = g_hCvar_OxygenTank.BoolValue;
g_bCvar_BarricadeGascan = g_hCvar_BarricadeGascan.BoolValue;
g_bCvar_GasPump = g_hCvar_GasPump.BoolValue;
if (g_bL4D2)
g_bCvar_FireworksCrate = g_hCvar_FireworksCrate.BoolValue;
g_fPillsDecayRate = g_hCvar_PillsDecayRate.FloatValue; //MS
g_bCvar_Admin = g_hCvar_Admin.BoolValue; //MS
g_bCvar_Blast = g_hCvar_Blast.BoolValue; //MS
g_bCvar_BanBurnDisconnect = g_hCvar_BanBurnDisconnect.BoolValue; //MS
g_iCvar_BanDuration = g_hCvar_BanDuration.IntValue; //MS
}
/****************************************************************************************************/
public void HookEvents(bool hook)
{
if (hook && !g_bEventsHooked)
{
g_bEventsHooked = true;
HookEvent("break_prop", Event_BreakProp);
return;
}
if (!hook && g_bEventsHooked)
{
g_bEventsHooked = false;
UnhookEvent("break_prop", Event_BreakProp);
return;
}
}
/****************************************************************************************************/
public void Event_BreakProp(Event event, const char[] name, bool dontBroadcast)
{
if (!g_bCvar_Enabled)
return;
if (!g_bCvar_Team)
return;
int entity = event.GetInt("entindex");
int type = ge_iType[entity];
if (type == TYPE_NONE)
return;
int client = GetClientOfUserId(event.GetInt("userid"));
if (client == 0)
client = GetClientOfUserId(ge_iLastAttacker[entity]);
if (!IsValidClient(client))
return;
OutputMessage(client, type);
}
/****************************************************************************************************/
public void OnClientDisconnect(int client)
{
for (int type = TYPE_NONE; type <= MAX_TYPES; type++)
{
gc_fLastChatOccurrence[client][type] = 0.0;
}
if (g_bReverseBurnAtk[client] && g_bCvar_BanBurnDisconnect) //MS
{ //MS
//ban attacker for disconnecting during reverse burn //MS
char BanMsg[50]; //MS
Format(BanMsg, sizeof(BanMsg), "%t", "BurnGriefer", client); //MS
BanClient(client, g_iCvar_BanDuration, BANFLAG_AUTO, "BurnGriefer", BanMsg, _, client); //MS
} //MS
}
/****************************************************************************************************/
public void LateLoad()
{
int entity;
if (g_bL4D2)
{
entity = INVALID_ENT_REFERENCE;
while ((entity = FindEntityByClassname(entity, CLASSNAME_WEAPON_GASCAN)) != INVALID_ENT_REFERENCE)
{
SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
HookSingleEntityOutput(entity, "OnKilled", OnKilled, true);
}
}
entity = INVALID_ENT_REFERENCE;
while ((entity = FindEntityByClassname(entity, CLASSNAME_PROP_FUEL_BARREL)) != INVALID_ENT_REFERENCE)
{
RequestFrame(OnNextFrame, EntIndexToEntRef(entity));
}
entity = INVALID_ENT_REFERENCE;
while ((entity = FindEntityByClassname(entity, "prop_physics*")) != INVALID_ENT_REFERENCE)
{
if (HasEntProp(entity, Prop_Send, "m_isCarryable")) // CPhysicsProp
RequestFrame(OnNextFrame, EntIndexToEntRef(entity));
}
entity = INVALID_ENT_REFERENCE;
while ((entity = FindEntityByClassname(entity, "physics_prop")) != INVALID_ENT_REFERENCE)
{
RequestFrame(OnNextFrame, EntIndexToEntRef(entity));
}
for (int client = 1; client <= MaxClients; client++) //MS
{ //MS
if (IsClientInGame(client)) //MS
OnClientPutInServer(client); //MS
} //MS
}
/****************************************************************************************************/
public void OnNextFrame(int entityRef)
{
int entity = EntRefToEntIndex(entityRef);
if (entity == INVALID_ENT_REFERENCE)
return;
OnSpawnPost(entity);
}
/****************************************************************************************************/
public void OnEntityDestroyed(int entity)
{
if (!g_bConfigLoaded)
return;
if (!IsValidEntityIndex(entity))
return;
ge_iType[entity] = TYPE_NONE;
ge_iLastAttacker[entity] = 0;
}
/****************************************************************************************************/
public void OnEntityCreated(int entity, const char[] classname)
{
if (!g_bConfigLoaded)
return;
if (!IsValidEntityIndex(entity))
return;
switch (classname[0])
{
case 'w':
{
if (!g_bL4D2)
return;
if (StrEqual(classname, CLASSNAME_WEAPON_GASCAN))
{
ge_iType[entity] = TYPE_GASCAN;
SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
HookSingleEntityOutput(entity, "OnKilled", OnKilled, true);
return;
}
}
case 'p':
{
if (HasEntProp(entity, Prop_Send, "m_isCarryable")) // CPhysicsProp
{
SDKHook(entity, SDKHook_SpawnPost, OnSpawnPost);
return;
}
}
}
}
/****************************************************************************************************/
public void OnSpawnPost(int entity)
{
if (GetEntProp(entity, Prop_Data, "m_iHammerID") == -1) // Ignore entities with hammerid -1
return;
int modelIndex = GetEntProp(entity, Prop_Send, "m_nModelIndex");
if (modelIndex == g_iModel_Gascan)
{
ge_iType[entity] = TYPE_GASCAN;
SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
return;
}
if (modelIndex == g_iModel_FuelBarrel)
{
ge_iType[entity] = TYPE_FUEL_BARREL;
SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
return;
}
if (modelIndex == g_iModel_PropaneCanister)
{
ge_iType[entity] = TYPE_PROPANECANISTER;
SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
return;
}
if (modelIndex == g_iModel_OxygenTank)
{
ge_iType[entity] = TYPE_OXYGENTANK;
SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
return;
}
if (modelIndex == g_iModel_BarricadeGascan)
{
ge_iType[entity] = TYPE_BARRICADE_GASCAN;
SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
return;
}
if (modelIndex == g_iModel_GasPump)
{
ge_iType[entity] = TYPE_GAS_PUMP;
SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
return;
}
if (!g_bL4D2)
return;
if (modelIndex == g_iModel_FireworksCrate)
{
ge_iType[entity] = TYPE_FIREWORKS_CRATE;
SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
return;
}
}
/****************************************************************************************************/
public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
if (!g_bCvar_Enabled)
return Plugin_Continue;
if (IsValidClient(attacker))
ge_iLastAttacker[victim] = GetClientUserId(attacker);
return Plugin_Continue;
}
/****************************************************************************************************/
public void OnKilled(const char[] output, int caller, int activator, float delay)
{
if (!g_bCvar_Enabled)
return;
if (!g_bCvar_Team)
return;
int type = ge_iType[caller];
if (type == TYPE_NONE)
return;
if (IsValidClient(activator))
ge_iLastAttacker[caller] = GetClientUserId(activator);
if (ge_iLastAttacker[caller] == 0)
return;
int client = GetClientOfUserId(ge_iLastAttacker[caller]);
if (!IsValidClient(client))
return;
OutputMessage(client, type);
}
/****************************************************************************************************/
public void OutputMessage(int attacker, int type)
{
if ((!g_bFirstBurn[attacker]) && !(type == TYPE_PROPANECANISTER || type == TYPE_OXYGENTANK)) //MS
{ //MS
g_bFirstBurn[attacker] = true; //MS
g_hBeginBurn[attacker] = CreateTimer(0.75, BeginBurnTimer, attacker); //MS
} //MS
if (g_bCvar_SpamProtection)
{
if (g_bCvar_SpamTypeCheck)
{
if (GetGameTime() - gc_fLastChatOccurrence[attacker][type] < g_fCvar_SpamProtection)
return;
gc_fLastChatOccurrence[attacker][type] = GetGameTime();
}
else
{
if (GetGameTime() - gc_fLastChatOccurrence[attacker][TYPE_NONE] < g_fCvar_SpamProtection)
return;
gc_fLastChatOccurrence[attacker][TYPE_NONE] = GetGameTime();
}
}
switch (type)
{
case TYPE_GASCAN:
{
if (!g_bCvar_Gascan)
return;
for (int client = 1; client <= MaxClients; client++)
{
if (!IsClientInGame(client))
continue;
if (IsFakeClient(client))
continue;
if (attacker == client)
{
if (!g_bCvar_Self)
continue;
}
else
{
if (!(GetTeamFlag(GetClientTeam(client)) & g_iCvar_Team))
continue;
}
CPrintToChat(client, "%T", "Exploded a gascan", client, attacker);
}
}
case TYPE_FUEL_BARREL:
{
if (!g_bCvar_FuelBarrel)
return;
for (int client = 1; client <= MaxClients; client++)
{
if (!IsClientInGame(client))
continue;
if (IsFakeClient(client))
continue;
if (attacker == client)
{
if (!g_bCvar_Self)
continue;
}
else
{
if (!(GetTeamFlag(GetClientTeam(client)) & g_iCvar_Team))
continue;
}
CPrintToChat(client, "%T", "Exploded a fuel barrel", client, attacker);
}
}
case TYPE_PROPANECANISTER:
{
if (!g_bCvar_PropaneCanister)
return;
for (int client = 1; client <= MaxClients; client++)
{
if (!IsClientInGame(client))
continue;
if (IsFakeClient(client))
continue;
if (attacker == client)
{
if (!g_bCvar_Self)
continue;
}
else
{
if (!(GetTeamFlag(GetClientTeam(client)) & g_iCvar_Team))
continue;
}
CPrintToChat(client, "%T", "Exploded a propane canister", client, attacker);
}
}
case TYPE_OXYGENTANK:
{
if (!g_bCvar_OxygenTank)
return;
for (int client = 1; client <= MaxClients; client++)
{
if (!IsClientInGame(client))
continue;
if (IsFakeClient(client))
continue;
if (attacker == client)
{
if (!g_bCvar_Self)
continue;
}
else
{
if (!(GetTeamFlag(GetClientTeam(client)) & g_iCvar_Team))
continue;
}
CPrintToChat(client, "%T", "Exploded an oxygen tank", client, attacker);
}
}
case TYPE_BARRICADE_GASCAN:
{
if (!g_bCvar_BarricadeGascan)
return;
for (int client = 1; client <= MaxClients; client++)
{
if (!IsClientInGame(client))
continue;
if (IsFakeClient(client))
continue;
if (attacker == client)
{
if (!g_bCvar_Self)
continue;
}
else
{
if (!(GetTeamFlag(GetClientTeam(client)) & g_iCvar_Team))
continue;
}
CPrintToChat(client, "%T", "Exploded a barricade with gascans", client, attacker);
}
}
case TYPE_GAS_PUMP:
{
if (!g_bCvar_GasPump)
return;
for (int client = 1; client <= MaxClients; client++)
{
if (!IsClientInGame(client))
continue;
if (IsFakeClient(client))
continue;
if (attacker == client)
{
if (!g_bCvar_Self)
continue;
}
else
{
if (!(GetTeamFlag(GetClientTeam(client)) & g_iCvar_Team))
continue;
}
CPrintToChat(client, "%T", "Exploded a gas pump", client, attacker);
}
}
case TYPE_FIREWORKS_CRATE:
{
if (!g_bCvar_FireworksCrate)
return;
for (int client = 1; client <= MaxClients; client++)
{
if (!IsClientInGame(client))
continue;
if (IsFakeClient(client))
continue;
if (attacker == client)
{
if (!g_bCvar_Self)
continue;
}
else
{
if (!(GetTeamFlag(GetClientTeam(client)) & g_iCvar_Team))
continue;
}
CPrintToChat(client, "%T", "Exploded a fireworks crate", client, attacker);
}
}
}
}
// ====================================================================================================
// Admin Commands
// ====================================================================================================
public Action CmdPrintCvars(int client, int args)
{
PrintToConsole(client, "");
PrintToConsole(client, "======================================================================");
PrintToConsole(client, "");
PrintToConsole(client, "--------------- Plugin Cvars (l4d_explosion_announcer) ---------------");
PrintToConsole(client, "");
PrintToConsole(client, "l4d_explosion_announcer_version : %s", PLUGIN_VERSION);
PrintToConsole(client, "l4d_explosion_announcer_enable : %b (%s)", g_bCvar_Enabled, g_bCvar_Enabled ? "true" : "false");
PrintToConsole(client, "l4d_explosion_announcer_spam_protection : %.2f (%s)", g_fCvar_SpamProtection, g_bCvar_SpamProtection ? "true" : "false");
PrintToConsole(client, "l4d_explosion_announcer_spam_type_check : %b (%s)", g_bCvar_SpamTypeCheck, g_bCvar_SpamTypeCheck ? "true" : "false");
PrintToConsole(client, "l4d_explosion_announcer_team : %i (%s)", g_iCvar_Team, g_bCvar_Team ? "true" : "false");
PrintToConsole(client, "l4d_explosion_announcer_self : %b (%s)", g_bCvar_Self, g_bCvar_Self ? "true" : "false");
PrintToConsole(client, "l4d_explosion_announcer_gascan : %b (%s)", g_bCvar_Gascan, g_bCvar_Gascan ? "true" : "false");
PrintToConsole(client, "l4d_explosion_announcer_fuelbarrel : %b (%s)", g_bCvar_FuelBarrel, g_bCvar_FuelBarrel ? "true" : "false");
PrintToConsole(client, "l4d_explosion_announcer_propanecanister : %b (%s)", g_bCvar_PropaneCanister, g_bCvar_PropaneCanister ? "true" : "false");
PrintToConsole(client, "l4d_explosion_announcer_oxygentank : %b (%s)", g_bCvar_OxygenTank, g_bCvar_OxygenTank ? "true" : "false");
PrintToConsole(client, "l4d_explosion_announcer_barricadegascan : %b (%s)", g_bCvar_BarricadeGascan, g_bCvar_BarricadeGascan ? "true" : "false");
PrintToConsole(client, "l4d_explosion_announcer_gaspump : %b (%s)", g_bCvar_GasPump, g_bCvar_GasPump ? "true" : "false");
if (g_bL4D2) PrintToConsole(client, "l4d_explosion_announcer_fireworkscrate : %b (%s)", g_bCvar_FireworksCrate, g_bCvar_FireworksCrate ? "true" : "false");
PrintToConsole(client, "");
PrintToConsole(client, "======================================================================");
PrintToConsole(client, "");
return Plugin_Handled;
}
// ====================================================================================================
// Helpers
// ====================================================================================================
/**
* Validates if is a valid client index.
*
* @param client Client index.
* @return True if client index is valid, false otherwise.
*/
bool IsValidClientIndex(int client)
{
return (1 <= client <= MaxClients);
}
/****************************************************************************************************/
/**
* Validates if is a valid client.
*
* @param client Client index.
* @return True if client index is valid and client is in game, false otherwise.
*/
bool IsValidClient(int client)
{
return (IsValidClientIndex(client) && IsClientInGame(client));
}
/****************************************************************************************************/
/**
* Validates if is a valid entity index (between MaxClients+1 and 2048).
*
* @param entity Entity index.
* @return True if entity index is valid, false otherwise.
*/
bool IsValidEntityIndex(int entity)
{
return (MaxClients+1 <= entity <= GetMaxEntities());
}
/****************************************************************************************************/
/**
* Returns the team flag from a team.
*
* @param team Team index.
* @return Team flag.
*/
int GetTeamFlag(int team)
{
switch (team)
{
case TEAM_SURVIVOR:
return FLAG_TEAM_SURVIVOR;
case TEAM_INFECTED:
return FLAG_TEAM_INFECTED;
case TEAM_SPECTATOR:
return FLAG_TEAM_SPECTATOR;
case TEAM_HOLDOUT:
return FLAG_TEAM_HOLDOUT;
default:
return FLAG_TEAM_NONE;
}
}
// ====================================================================================================
// colors.inc replacement (Thanks to Silvers)
// ====================================================================================================
/**
* Prints a message to a specific client in the chat area.
* Supports color tags.
*
* @param client Client index.
* @param message Message (formatting rules).
* @return No return.
*
* On error/Errors: If the client is not connected an error will be thrown.
*/
public void CPrintToChat(int client, char[] message, any ...)
{