forked from SilvDev/Various_Scripts_Collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathl4d_ignited_stay.sp
1364 lines (1135 loc) · 39.9 KB
/
l4d_ignited_stay.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
/*
* Throwables Stay Ignited
* Copyright (C) 2022 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.9"
/*======================================================================================
Plugin Info:
* Name : [L4D & L4D2] Throwables Stay Ignited
* Author : SilverShot
* Descrp : Keeps ignited throwables on fire and prevents them from randomly extinguishing. Adjust burning duration. Can also block picking up ignited.
* Link : https://forums.alliedmods.net/showthread.php?t=333679
* Plugins : https://sourcemod.net/plugins.php?exact=exact&sortby=title&search=1&author=Silvers
========================================================================================
Change Log:
1.9 (28-Dec-2022)
- Fixed not respawning Scavenge gascans under certain conditions. Thanks to "thewintersoldier97" for reporting.
1.8 (27-Dec-2022)
- Fixed not respawning Scavenge gascans on the first map from server start. Thanks to "HarryPotter" for reporting.
- Fixed not respawning Scavenge gascans when "Scavenge Score Fix - Gascan Pouring" plugin is installed.
1.7 (06-Nov-2022)
- Fixed Oxygen Tanks not whistling before exploding. Thanks to "Iizuka07" for reporting.
1.6 (14-Jul-2022)
- Changes to fix warnings when compiling on SourceMod 1.11.
1.5 (10-Oct-2021)
- Fixed an error that could occur with invalid clients.
1.4 (07-Oct-2021)
- Fixed not respawning Scavenge gascans correctly.
- Minor changes to code to clean and fix a potential issue with respawning gascans.
- Prevents conflicts with "Scavenge Score Fix" plugin version 2.3+ when using "l4d2_scavenge_score_respawn" feature.
1.3 (29-Sep-2021)
- Changed method of creating an explosive to prevent it being visible (still sometimes shows, but probably less).
- L4D2: Fixed GasCans not registering the thrower for damage credit when exploding.
1.2 (04-Aug-2021)
- L4D2: Made the plugin compatible with "Saferoom Lock: Scavenge" plugin by "Eärendil". Thanks to "Maur0" for reporting.
1.1 (04-Aug-2021)
- Fixed Scavenge GasCans not respawning and skin not showing when held. Thanks to "Maur0" for reporting.
- Fixed throwables exploding in hand when owner take damage. Thanks to "Maur0" for reporting.
- L4D2: Added cvar "l4d_ignited_respawn" to control when to respawn Scavenge gascans after they are destroyed.
1.0 (29-Jul-2021)
- Initial release.
======================================================================================*/
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#define CVAR_FLAGS FCVAR_NOTIFY
#define DEBUGGING 0
#define MODEL_GASCAN "models/props_junk/gascan001a.mdl"
#define MODEL_CRATE "models/props_junk/explosive_box001.mdl"
#define MODEL_OXYGEN "models/props_equipment/oxygentank01.mdl"
#define MODEL_PROPANE "models/props_junk/propanecanister001a.mdl"
// After a player is ignited/walks in fire, the throwable flames will disappear a second or so later. This fixes that by equipping a new throwable and igniting it.
// Set to 0.0 to disable.
#define REFIRE_TIME 0.3
// Maximum range for Scavenge gascans to match with their spawner
#define RANGE_MAX 30.0
ConVar g_hCvarAllow, g_hCvarModes, g_hCvarModesOff, g_hCvarModesTog, g_hCvarMPGameMode, g_hCvarOxygen, g_hCvarRespawn, g_hCvarTimeF, g_hCvarTimeG, g_hCvarTimeP, g_hCvarTimeO, g_hCvarTypes;
bool g_bCvarAllow, g_bMapStarted, g_bLeft4Dead2, g_bRemovingItem, g_bBlockGrab;
int g_iCvarOxygen, g_iCvarTypes, g_iDroppingItem;
float g_fCvarRespawn, g_fCvarTimeF, g_fCvarTimeG, g_fCvarTimeP, g_fCvarTimeO;
float g_fFireTime[2048];
int g_iLastClient[2048];
int g_iHolding2[MAXPLAYERS+1];
int g_iHolding1[MAXPLAYERS+1];
int g_iOxygen[MAXPLAYERS+1];
int g_iFlamed; // Last entity on fire when dropped/grabbed - tracking entity changes
int g_iSpawned; // Last oxygen tank damaged when dropped - tracking entity changes
Handle g_hTimerReflame[MAXPLAYERS+1];
int g_iScavenge[2048];
int g_iPlayerSpawn, g_iRoundStart;
// ====================================================================================================
// PLUGIN START
// ====================================================================================================
public Plugin myinfo =
{
name = "[L4D & L4D2] Throwables Stay Ignited",
author = "SilverShot",
description = "Keeps ignited throwables on fire and prevents them from randomly extinguishing. Adjust burning duration. Can also block picking up ignited.",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=333679"
}
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_ignited_allow", "1", "0=Plugin off, 1=Plugin on.", CVAR_FLAGS );
g_hCvarModes = CreateConVar( "l4d_ignited_modes", "", "Turn on the plugin in these game modes, separate by commas (no spaces). (Empty = all).", CVAR_FLAGS );
g_hCvarModesOff = CreateConVar( "l4d_ignited_modes_off", "", "Turn off the plugin in these game modes, separate by commas (no spaces). (Empty = none).", CVAR_FLAGS );
g_hCvarModesTog = CreateConVar( "l4d_ignited_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_hCvarOxygen = CreateConVar( "l4d_ignited_oxygen", "1", "What to do with damaged Oxygen Tanks that are about to explode: 0=Prevent picking up. 1=Explode in players hands.", CVAR_FLAGS );
if( g_bLeft4Dead2 )
{
g_hCvarRespawn = CreateConVar( "l4d_ignited_respawn", "20.0", "How many seconds after a Scavenge Gascan is destroyed until it respawns.", CVAR_FLAGS );
g_hCvarTimeF = CreateConVar( "l4d_ignited_time_fireworks", "2.0", "How many seconds should Firework Crates stay ignited on fire before exploding.", CVAR_FLAGS, true, 0.2 );
}
g_hCvarTimeG = CreateConVar( "l4d_ignited_time_gascan", "2.0", "How many seconds should Gascans stay ignited on fire before exploding.", CVAR_FLAGS, true, 0.2 );
g_hCvarTimeO = CreateConVar( "l4d_ignited_time_oxygen", "2.0", "How many seconds should Oxygen Tanks stay ignited on fire before exploding.", CVAR_FLAGS, true, 0.2 );
g_hCvarTimeP = CreateConVar( "l4d_ignited_time_propane", "2.0", "How many seconds should Propane Tanks stay ignited on fire before exploding.", CVAR_FLAGS, true, 0.2 );
g_hCvarTypes = CreateConVar( "l4d_ignited_types", "15", "Which throwables can be picked up while ignited, otherwise they cannot. 0=All, 1=GasCan, 2=Oxygen Tank, 4=Propane Tank, 8=Firework Crate, 15=All. Add numbers together.", CVAR_FLAGS );
CreateConVar( "l4d_ignited_version", PLUGIN_VERSION, "Throwables Stay Ignited plugin version.", FCVAR_NOTIFY|FCVAR_DONTRECORD);
AutoExecConfig(true, "l4d_ignited");
g_hCvarMPGameMode = FindConVar("mp_gamemode");
g_hCvarMPGameMode.AddChangeHook(ConVarChanged_Allow);
g_hCvarModes.AddChangeHook(ConVarChanged_Allow);
g_hCvarModesOff.AddChangeHook(ConVarChanged_Allow);
g_hCvarModesTog.AddChangeHook(ConVarChanged_Allow);
g_hCvarAllow.AddChangeHook(ConVarChanged_Allow);
g_hCvarOxygen.AddChangeHook(ConVarChanged_Cvars);
if( g_bLeft4Dead2 )
{
g_hCvarRespawn.AddChangeHook(ConVarChanged_Cvars);
g_hCvarTimeF.AddChangeHook(ConVarChanged_Cvars);
}
g_hCvarTimeG.AddChangeHook(ConVarChanged_Cvars);
g_hCvarTimeP.AddChangeHook(ConVarChanged_Cvars);
g_hCvarTimeO.AddChangeHook(ConVarChanged_Cvars);
g_hCvarTypes.AddChangeHook(ConVarChanged_Cvars);
g_iRoundStart = 1;
// ====================
// Test commands
// ====================
// RegAdminCmd("sm_flame", CmdFlame, ADMFLAG_ROOT, "Ignites the currently held gascan.");
// RegAdminCmd("sm_flameme", CmdFlameMe, ADMFLAG_ROOT, "Ignites the player for testing.");
// RegAdminCmd("sm_ignites", CmdIgnite, ADMFLAG_ROOT, "Ignites the entity aimed at.");
}
// ====================================================================================================
// COMMANDS
// ====================================================================================================
stock Action CmdFlameMe(int client, int args)
{
SDKHooks_TakeDamage(client, 0, 0, 1.0, DMG_BURN);
return Plugin_Handled;
}
stock Action CmdIgnite(int client, int args)
{
int entity = GetClientAimTarget(client, false);
if( entity != -1 )
IgniteEntity(entity, 60.0);
return Plugin_Handled;
}
stock Action CmdFlame(int client, int args)
{
g_iFlamed = 0;
int weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if( weapon != -1 )
{
float time;
char classname[32];
GetEdictClassname(weapon, classname, sizeof(classname));
if( strcmp(classname[7], "gascan") == 0 ) time = g_fCvarTimeG;
else if( strcmp(classname[7], "oxygentank") == 0 ) time = g_fCvarTimeO;
else if( strcmp(classname[7], "propanetank") == 0 ) time = g_fCvarTimeP;
else if( g_bLeft4Dead2 && strcmp(classname[7], "fireworkcrate") == 0 ) time = g_fCvarTimeF;
if( time )
{
if( g_bLeft4Dead2 ) g_iHolding2[client] = EntIndexToEntRef(weapon);
else g_iHolding1[client] = weapon;
g_fFireTime[weapon] = GetGameTime() + time;
AcceptEntityInput(weapon, "Ignite");
int flame = GetEntPropEnt(weapon, Prop_Send, "m_hEffectEntity");
if( flame != -1 && IsValidEntity(flame) )
{
SetEntPropFloat(flame, Prop_Data, "m_flLifetime", GetGameTime() + time);
ReplyToCommand(client, "Ignited weapon (%d) flame (%d)", weapon, flame);
}
}
}
return Plugin_Handled;
}
// ====================================================================================================
// CVARS
// ====================================================================================================
public void OnMapStart()
{
g_bMapStarted = true;
}
public void OnMapEnd()
{
g_iFlamed = 0;
g_iRoundStart = 0;
g_iPlayerSpawn = 0;
g_bMapStarted = false;
}
public void OnConfigsExecuted()
{
IsAllowed();
}
void ConVarChanged_Cvars(Handle convar, const char[] oldValue, const char[] newValue)
{
GetCvars();
}
void GetCvars()
{
g_iCvarOxygen = g_hCvarOxygen.IntValue;
if( g_bLeft4Dead2 )
{
g_fCvarTimeF = g_hCvarTimeF.FloatValue;
g_fCvarRespawn = g_hCvarRespawn.FloatValue;
}
g_fCvarTimeG = g_hCvarTimeG.FloatValue;
g_fCvarTimeP = g_hCvarTimeP.FloatValue;
g_fCvarTimeO = g_hCvarTimeO.FloatValue;
g_iCvarTypes = g_hCvarTypes.IntValue;
}
void ConVarChanged_Allow(Handle convar, const char[] oldValue, const char[] newValue)
{
IsAllowed();
}
void IsAllowed()
{
bool bCvarAllow = g_hCvarAllow.BoolValue;
bool bAllowMode = IsAllowedGameMode();
GetCvars();
if( g_bCvarAllow == false && bCvarAllow == true && bAllowMode == true )
{
// Hook clients
for( int i = 1; i <= MaxClients; i++ )
{
if( IsClientInGame(i) )
{
SDKHook(i, SDKHook_WeaponSwitch, OnSwitch);
#if REFIRE_TIME
SDKHook(i, SDKHook_OnTakeDamage, OnPlayerDamage);
#endif
}
}
// Hook entities
int entity = -1;
while( (entity = FindEntityByClassname(entity, "physics_prop")) != INVALID_ENT_REFERENCE )
{
static char modelname[45];
GetEntPropString(entity, Prop_Data, "m_ModelName", modelname, sizeof(modelname));
if( strcmp(modelname, MODEL_OXYGEN) == 0 )
{
SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
}
}
// Events
if( g_bLeft4Dead2 )
HookEvent("weapon_drop_to_prop", Event_DropToProp);
HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_PostNoCopy);
// Find Scavenge gascans and their spawner
if( g_bLeft4Dead2 )
{
FindScavengeGas();
}
g_bCvarAllow = true;
}
else if( g_bCvarAllow == true && (bCvarAllow == false || bAllowMode == false) )
{
// Unhook clients
for( int i = 1; i <= MaxClients; i++ )
{
if( IsClientInGame(i) )
{
SDKUnhook(i, SDKHook_WeaponSwitch, OnSwitch);
#if REFIRE_TIME
SDKUnhook(i, SDKHook_OnTakeDamage, OnPlayerDamage);
#endif
}
}
// Unhook entities
int entity = -1;
while( (entity = FindEntityByClassname(entity, "physics_prop")) != INVALID_ENT_REFERENCE )
{
static char modelname[45];
GetEntPropString(entity, Prop_Data, "m_ModelName", modelname, sizeof(modelname));
if( strcmp(modelname, MODEL_OXYGEN) == 0 )
{
SDKUnhook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
}
}
// Events
if( g_bLeft4Dead2 )
UnhookEvent("weapon_drop_to_prop", Event_DropToProp);
UnhookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
UnhookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
UnhookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_PostNoCopy);
g_bCvarAllow = false;
}
}
int g_iCurrentMode;
bool IsAllowedGameMode()
{
if( g_hCvarMPGameMode == null )
return false;
int iCvarModesTog = g_hCvarModesTog.IntValue;
if( iCvarModesTog != 0 )
{
if( g_bMapStarted == false )
return false;
g_iCurrentMode = 0;
int entity = CreateEntityByName("info_gamemode");
if( IsValidEntity(entity) )
{
DispatchSpawn(entity);
HookSingleEntityOutput(entity, "OnCoop", OnGamemode, true);
HookSingleEntityOutput(entity, "OnSurvival", OnGamemode, true);
HookSingleEntityOutput(entity, "OnVersus", OnGamemode, true);
HookSingleEntityOutput(entity, "OnScavenge", OnGamemode, true);
ActivateEntity(entity);
AcceptEntityInput(entity, "PostSpawnActivate");
if( IsValidEntity(entity) ) // Because sometimes "PostSpawnActivate" seems to 3 the ent.
RemoveEdict(entity); // Because multiple plugins creating at once, avoid too many duplicate ents in the same frame
}
if( g_iCurrentMode == 0 )
return false;
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;
}
void OnGamemode(const char[] output, int caller, int activator, float delay)
{
if( strcmp(output, "OnCoop") == 0 )
g_iCurrentMode = 1;
else if( strcmp(output, "OnSurvival") == 0 )
g_iCurrentMode = 2;
else if( strcmp(output, "OnVersus") == 0 )
g_iCurrentMode = 4;
else if( strcmp(output, "OnScavenge") == 0 )
g_iCurrentMode = 8;
}
// ====================================================================================================
// EVENTS
// ====================================================================================================
public void OnClientPutInServer(int client)
{
if( g_bCvarAllow )
{
SDKHook(client, SDKHook_WeaponSwitch, OnSwitch);
#if REFIRE_TIME
SDKHook(client, SDKHook_OnTakeDamage, OnPlayerDamage);
#endif
}
}
public void OnClientDisconnect(int client)
{
delete g_hTimerReflame[client];
}
// ====================
// Re-ignite the held throwable if player ran into fire, since this makes the flames on the held object disappear
// ====================
Action OnPlayerDamage(int client, int &attacker, int &inflictor, float &damage, int &damagetype)
{
if( (damagetype & DMG_BURN|DMG_SLOWBURN) && GetClientTeam(client) == 2 )
{
// Verify holding object on fire
if( g_bLeft4Dead2 ?
g_iHolding2[client] && EntRefToEntIndex(g_iHolding2[client]) != INVALID_ENT_REFERENCE :
g_iHolding1[client] && EntRefToEntIndex(g_iHolding1[client]) != INVALID_ENT_REFERENCE )
{
int weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if( weapon != -1 )
{
char classname[32];
GetEdictClassname(weapon, classname, sizeof(classname));
if(
strcmp(classname[7], "gascan") == 0 ||
strcmp(classname[7], "oxygentank") == 0 ||
strcmp(classname[7], "propanetank") == 0 ||
(g_bLeft4Dead2 && strcmp(classname[7], "fireworkcrate") == 0)
)
{
delete g_hTimerReflame[client];
g_hTimerReflame[client] = CreateTimer(REFIRE_TIME, TimerReflame, GetClientUserId(client));
}
}
}
}
return Plugin_Continue;
}
Action TimerReflame(Handle timer, int client)
{
if( (client = GetClientOfUserId(client)) && IsClientInGame(client) )
{
g_hTimerReflame[client] = null;
int weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if( weapon != -1 )
{
char classname[32];
GetEdictClassname(weapon, classname, sizeof(classname));
if(
strcmp(classname[7], "gascan") == 0 ||
strcmp(classname[7], "oxygentank") == 0 ||
strcmp(classname[7], "propanetank") == 0 ||
(g_bLeft4Dead2 && strcmp(classname[7], "fireworkcrate") == 0)
)
{
OnUseGrab(weapon, client);
}
}
}
return Plugin_Continue;
}
// ====================
// Watch for flame creation and oxygen tank
// ====================
public void OnEntityCreated(int entity, const char[] classname)
{
if( !g_bCvarAllow ) return;
if( strcmp(classname, "entityflame") == 0 )
{
if( g_bLeft4Dead2 )
{
// Prevent multiple timers firing when ignited in hands
if( !g_bBlockGrab )
{
SDKHook(entity, SDKHook_Spawn, OnSpawnFire);
}
}
else
{
OnSpawnFire(entity);
}
}
else if( strcmp(classname, "physics_prop") == 0 )
{
if( g_bRemovingItem )
{
RemoveEntity(entity);
return;
}
else if( !g_bLeft4Dead2 )
{
g_iDroppingItem = EntIndexToEntRef(entity);
}
SDKHook(entity, SDKHook_SpawnPost, OnSpawnAir);
}
else if( g_bLeft4Dead2 && strcmp(classname, "weapon_gascan") == 0 )
{
#if DEBUGGING
PrintToChatAll("IS: weapon_gascan SPAWNED %d", entity);
#endif
CreateTimer(0.1, TimerDelayedSpawn, EntIndexToEntRef(entity));
}
}
// Delay before finding matching spawner. Next frame required for getting vPos, but too early because the gascan takes time to fall into position so it would be near enough to spawner
Action TimerDelayedSpawn(Handle timer, int entity)
{
entity = EntRefToEntIndex(entity);
if( entity != INVALID_ENT_REFERENCE )
{
#if DEBUGGING
PrintToChatAll("IS: TimerDelayedSpawn FIND %d", entity);
#endif
FindScavengeGas(entity);
}
return Plugin_Continue;
}
// ====================
// OXYGEN TANK
// ====================
// Watch Oxygen Tanks for damage
// With no life they whistle for 2.0 seconds then explode, but if picked up this cancels the explosion
// This fixes that
// ====================
void OnSpawnAir(int entity)
{
static char modelname[45];
GetEntPropString(entity, Prop_Data, "m_ModelName", modelname, sizeof(modelname));
if( strcmp(modelname, MODEL_OXYGEN) == 0 )
{
g_iSpawned = entity;
SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
}
}
Action OnTakeDamage(int entity, int &attacker, int &inflictor, float &damage, int &damagetype)
{
// Taken more damage than health, it's going to explode!
if( GetEntProp(entity, Prop_Data, "m_iHealth") - RoundToFloor(damage) <= 0.0 )
{
SDKUnhook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
g_fFireTime[entity] = GetGameTime() + g_fCvarTimeO;
// Block picking up, or watch for when picked up
if( g_iCvarOxygen == 0 ) SDKHook(entity, SDKHook_Use, OnUseOxygenBlock);
else SDKHook(entity, SDKHook_Use, OnUseOxygenGrab);
}
return Plugin_Continue;
}
Action OnUseOxygenGrab(int entity, int client)
{
// Must wait a frame to get the new held entity index.
// When picking up a prop_physics Oxygen Tank (and other prop_physics), it changes to weapon_oxygentank (etc) when held.
// Not passing entity ref because it won't exist, we simply need the index to get damage/detonation time.
DataPack dPack = new DataPack();
dPack.WriteCell(GetClientUserId(client));
dPack.WriteCell(entity);
RequestFrame(OnNextFrameOxygen, dPack);
return Plugin_Continue;
}
void OnNextFrameOxygen(DataPack dPack)
{
dPack.Reset();
int client = dPack.ReadCell();
int entity = dPack.ReadCell();
delete dPack;
if( (client = GetClientOfUserId(client)) && IsClientInGame(client) )
{
int weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
char classname[64];
GetEdictClassname(weapon, classname, sizeof(classname));
if( strcmp(classname, "weapon_oxygentank") ==0 )
{
g_fFireTime[weapon] = g_fFireTime[entity];
g_iOxygen[client] = EntIndexToEntRef(weapon);
CreateTimer(0.1, TimerTest, EntIndexToEntRef(weapon), TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
}
}
Action OnUseOxygenBlock(int entity, int client)
{
return Plugin_Handled;
}
// ====================
// ENTITY FLAME
// ====================
// Watch for entityflame entities spawning
// ====================
void OnSpawnFire(int entity)
{
// Only on next frame is the owner populated
RequestFrame(OnNextFrameSpawnFire, EntIndexToEntRef(entity));
}
void OnNextFrameSpawnFire(int entity)
{
entity = EntRefToEntIndex(entity);
if( entity == INVALID_ENT_REFERENCE || !IsValidEntity(entity) ) return;
// Is being held by someone?
int attached = GetEntPropEnt(entity, Prop_Send, "m_hEntAttached");
// Flames can attach to clients etc, we want to verify it's attached to target classnames
if( attached > MaxClients )
{
static char sTemp[45];
GetEdictClassname(attached, sTemp, sizeof(sTemp));
// Gascan - L4D2 uses the weapon_gascan entity, L4D1 uses prop_physics, but we'll check both anyway
if( strcmp(sTemp[7], "gascan") == 0 )
{
SetEntPropFloat(entity, Prop_Data, "m_flLifetime", GetGameTime() + g_fCvarTimeG);
if( g_iFlamed )
{
g_fFireTime[entity] = g_fFireTime[g_iFlamed];
g_fFireTime[attached] = g_fFireTime[g_iFlamed];
g_iFlamed = 0;
} else {
g_fFireTime[entity] = GetGameTime() + g_fCvarTimeG;
g_fFireTime[attached] = GetGameTime() + g_fCvarTimeG;
}
SDKHook(attached, SDKHook_OnTakeDamage, OnPropTakeDamage);
#if DEBUGGING
PrintToChatAll("TAKING DMG %d", attached);
#endif
CreateTimer(0.1, TimerTest, EntIndexToEntRef(attached), TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
if( g_iCvarTypes & 1 ) SDKHook(attached, SDKHook_Use, OnUseGrab);
else SDKHook(attached, SDKHook_Use, OnUseBlock);
}
else if( (strcmp(sTemp, "prop_physics") == 0 || strcmp(sTemp, "physics_prop") == 0) )
{
float time;
GetEntPropString(attached, Prop_Data, "m_ModelName", sTemp, sizeof(sTemp));
bool oxygen;
if( strcmp(sTemp, MODEL_GASCAN) == 0 )
{
time = g_fCvarTimeG;
if( g_iCvarTypes & 1 ) SDKHook(attached, SDKHook_Use, OnUseGrab);
else SDKHook(attached, SDKHook_Use, OnUseBlock);
}
else if( strcmp(sTemp, MODEL_OXYGEN) == 0 )
{
time = g_fCvarTimeO;
if( g_iCvarTypes & 2 ) SDKHook(attached, SDKHook_Use, OnUseGrab);
else SDKHook(attached, SDKHook_Use, OnUseBlock);
oxygen = true;
}
else if( strcmp(sTemp, MODEL_PROPANE) == 0 )
{
time = g_fCvarTimeP;
if( g_iCvarTypes & 4 ) SDKHook(attached, SDKHook_Use, OnUseGrab);
else SDKHook(attached, SDKHook_Use, OnUseBlock);
}
else if( g_bLeft4Dead2 && strcmp(sTemp, MODEL_CRATE) == 0 )
{
time = g_fCvarTimeF;
if( g_iCvarTypes & 8 ) SDKHook(attached, SDKHook_Use, OnUseGrab);
else SDKHook(attached, SDKHook_Use, OnUseBlock);
}
// Set burning duration
SetEntPropFloat(entity, Prop_Data, "m_flLifetime", GetGameTime() + time);
if( g_iFlamed )
{
g_fFireTime[entity] = g_fFireTime[g_iFlamed];
g_fFireTime[attached] = g_fFireTime[g_iFlamed];
g_iFlamed = 0;
} else {
g_fFireTime[entity] = GetGameTime() + time;
g_fFireTime[attached] = GetGameTime() + time;
}
if( oxygen )
SDKHook(attached, SDKHook_OnTakeDamage, OxygenTakeDamage);
else
SDKHook(attached, SDKHook_OnTakeDamage, OnPropTakeDamage);
CreateTimer(0.1, TimerTest, EntIndexToEntRef(attached), TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
}
}
// ====================
// Cvar setting to block picking up objects on fire
// ====================
Action OnUseBlock(int entity, int client)
{
// Sometimes the game makes it not on fire, lets verify or unhook.
int flame = GetEntPropEnt(entity, Prop_Send, "m_hEffectEntity");
if( flame != -1 && IsValidEntity(flame) )
{
static char classname[16];
GetEdictClassname(entity, classname, sizeof(classname));
if( strcmp(classname, "entityflame") == 0 )
{
return Plugin_Handled;
}
}
// Unhook, not valid
SDKUnhook(entity, SDKHook_Use, OnUseBlock);
return Plugin_Continue;
}
void OnUseGrab(int entity, int client)
{
// Explode?
float time = g_fFireTime[entity];
if( time < GetGameTime() )
{
DetonateExplosive(client, entity);
return;
}
// Pickup
// Get modelname
static char modelname[45];
GetEntPropString(entity, Prop_Data, "m_ModelName", modelname, sizeof(modelname));
// ==========
// L4D1 requires frame delay, because the entity is not yet equipped and we have no entity index
// ==========
if( !g_bLeft4Dead2 )
{
int index;
// Change from prop_physics to held classnames, weapon_gascan doesn't change, except in L4D1
if( strcmp(modelname, MODEL_OXYGEN) == 0 ) index = 1;
else if( strcmp(modelname, MODEL_PROPANE) == 0 ) index = 2;
else index = 3;
DataPack dPack = new DataPack();
dPack.WriteCell(GetClientUserId(client));
dPack.WriteCell(index);
dPack.WriteFloat(time);
RequestFrame(OnGrabFrame, dPack);
return;
}
// ==========
// L4D2 is different
// ==========
// Get classname
static char classname[32];
// Change from prop_physics to held classnames, weapon_gascan doesn't change, except in L4D1
if( g_bLeft4Dead2 && strcmp(modelname, MODEL_CRATE) == 0 ) classname = "weapon_fireworkcrate";
else if( strcmp(modelname, MODEL_OXYGEN) == 0 ) classname = "weapon_oxygentank";
else if( strcmp(modelname, MODEL_PROPANE) == 0 ) classname = "weapon_propanetank";
else classname = "weapon_gascan";
// Copy skin
int skin = GetEntProp(entity, Prop_Send, "m_nSkin");
// Delete picked up
RemoveEntity(entity);
// Create new, this is so the flame lifetime continues
int weapon = CreateEntityByName(classname);
DispatchSpawn(weapon);
SetEntProp(weapon, Prop_Send, "m_nSkin", skin);
EquipPlayerWeapon(client, weapon);
g_bBlockGrab = true;
AcceptEntityInput(weapon, "Ignite");
g_bBlockGrab = false;
int flame = GetEntPropEnt(weapon, Prop_Send, "m_hEffectEntity");
SetEntPropFloat(flame, Prop_Data, "m_flLifetime", time);
g_iFlamed = weapon;
g_fFireTime[weapon] = time;
g_iScavenge[weapon] = g_iScavenge[entity];
g_iScavenge[entity] = 0;
CreateTimer(0.1, TimerTest, EntIndexToEntRef(weapon), TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
g_iHolding2[client] = EntIndexToEntRef(weapon);
}
// ====================
// L4D1: Picking up object that's on fire
// ====================
void OnGrabFrame(DataPack dPack)
{
dPack.Reset();
int client = dPack.ReadCell();
int index = dPack.ReadCell();
float time = dPack.ReadFloat();
delete dPack;
if( (client = GetClientOfUserId(client)) && IsClientInGame(client) )
{
int entity = GetPlayerWeaponSlot(client, 5);
if( entity == -1 ) return;
// Copy skin
int skin = GetEntProp(entity, Prop_Send, "m_nSkin");
g_bRemovingItem = true;
RemovePlayerItem(client, entity);
g_bRemovingItem = false;
RemoveEntity(entity);
// Create new, this is so the flame lifetime continues
char classname[20];
switch( index )
{
case 1: classname = "weapon_oxygentank";
case 2: classname = "weapon_propanetank";
case 3: classname = "weapon_gascan";
}
int weapon = CreateEntityByName(classname);
DispatchSpawn(weapon);
ActivateEntity(weapon);
EquipPlayerWeapon(client, weapon);
AcceptEntityInput(weapon, "Ignite");
int flame = GetEntPropEnt(weapon, Prop_Send, "m_hEffectEntity");
SetEntPropFloat(flame, Prop_Data, "m_flLifetime", time);
SetEntProp(weapon, Prop_Send, "m_nSkin", skin);
g_fFireTime[weapon] = time;
CreateTimer(0.1, TimerTest, EntIndexToEntRef(weapon), TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
if( g_bLeft4Dead2 ) g_iHolding2[client] = EntIndexToEntRef(weapon);
else g_iHolding1[client] = weapon;
if( g_bLeft4Dead2 && classname[7] == 'g' )
{
g_iScavenge[weapon] = g_iScavenge[entity];
g_iScavenge[entity] = 0;
}
}
}
// ====================
// Block prop damage to allow flames
// ====================
Action OxygenTakeDamage(int entity, int &attacker, int &inflictor, float &damage, int &damagetype)
{
if( attacker > MaxClients )
{
static char classname[12];
GetEdictClassname(attacker, classname, sizeof(classname));
if( strcmp(classname, "entityflame") == 0 )
{
// Allow whistle effect for last 2 seconds by setting health to 1 and removing damage block
int flame = GetEntPropEnt(entity, Prop_Send, "m_hEffectEntity");
if( GetEntPropFloat(flame, Prop_Data, "m_flLifetime") - GetGameTime() > 2.0 )
{
return Plugin_Handled;
}
else
{
SetEntProp(entity, Prop_Data, "m_iHealth", 2);
SDKUnhook(entity, SDKHook_OnTakeDamage, OxygenTakeDamage);
}
}
}
return Plugin_Continue;
}
Action OnPropTakeDamage(int entity, int &attacker, int &inflictor, float &damage, int &damagetype)
{
if( attacker > MaxClients )
{
static char classname[12];
GetEdictClassname(attacker, classname, sizeof(classname));
if( strcmp(classname, "entityflame") == 0 )
{
return Plugin_Handled;
}
}
return Plugin_Continue;
}
// ====================
// Watch time until detonate
// ====================
Action TimerTest(Handle timer, int entity)
{
entity = EntRefToEntIndex(entity);
if( entity != INVALID_ENT_REFERENCE )
{
if( g_fFireTime[entity] > GetGameTime() )
{
return Plugin_Continue;
} else {
int client = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
DetonateExplosive(client, entity);
return Plugin_Stop;