-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathl4d2_lethal.sp
1131 lines (980 loc) · 34 KB
/
l4d2_lethal.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma newdecls required
#pragma semicolon 1
/*******************************************************
*
* L4D2: Lethal Weapon
*
* Author: ztar
* Edited: M249-M4A1
* http://forums.alliedmods.net/showthread.php?p=1121995
*
********************************************************
* CHANGELOG:
*
* - Added several ConVars to customize effects
* - Enable/disable sounds
* - Enable/disable use of extra ammo
* - Enable/disable some effects (to be discreet)
* - Enable/disable charging while crouched and moving
*
* - Renamed ConVars and CFG to be more uniform
* - Fixed some grammar and spelling issues
* - Removed text gauge as it was kinda annoying
* - Made it easier to change sounds (#define)
* - Updated some sounds
* - Fixed bug where Survivors would be launched away
* and killed unless "l4d2_lw_ff" is enabled
* - Fixed bug where if you were limited to 1 lethal
* charged shot, you fired, then the limit was
* removed, you wouldn't be able to charge again
* - Added screen shake
*
*******************************************************/
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#define PLUGIN_VERSION "2.1.13"
/*
Modify by Zakikun
2.1.13
- Added "l4d2_lw_adminonly" convar to control whether only enable lethal shoot for admin
- Added "lethal_weapon" flag to specify which admin can use lethal shoot
Fork by Dragokas
2.1.12
- Added "l4d2_lw_firelifetime" convar to control how many time should flame exist after sniper shooting.
2.1.11
- Added "l4d2_lw_useammocount" convar to set the number of ammo player spend on each lethal shoot (999 - by default).
2.1.10
- Converted to a new syntax and methodmaps
2.1.9
- Added checking for game requirements (L4d1 / L4d2).
- Added natives Lethal_SetAllowedClient(), Lethal_SetAllowedClientsAll(), Lethal_FriendlyFire().
- Added "sm_satellite_friendlyfire" ConVar to control FriendlyFire of indirect damage (explosion and fire).
- Ammo / clip offsets are corrected for L4D1.
- Now lethal sniper shoot spend all ammo.
- Fixed exploit on infinite super sniper-shoots when your bullets are not reset if you do a fast switch on pistol just right after shoot.
2.1.8
- Added IsClientInGame() check to StopSound.
2.1.7
- Added count of proper statistics for sniper super-shoot (thanks to SilverShot)
- Replaced deprecated FindSendPropOffs() and FindDataMapOffs()
2.1.6
- Added IsValidClient() check to Smash function.
2.1.5
- Added some fixes from Ludastar.
2.1.4
- Added another one check
- Added Russian translation
2.1.3
- ReleaseLock[client] = 0 is moved to a bit earlier stage for Event_Infected_Hurt and Event_Player_Hurt to prevent recurse calling bug (server crash).
2.1.2
- Added some client checkings
- Fixed bug when molotov is displayed but no longer available for player after super-shoot done
*/
#define CVAR_FLAGS FCVAR_SPONLY|FCVAR_NOTIFY
#define MOLOTOV 0
#define EXPLODE 1
/*
Datamap m_iAmmo
offset to add
+12: M4A1, AK74, Desert Rifle, also SG552 - ammo_assaultrifle_max
+20: both SMGs, also the MP5 - ammo_smg_max
+28: both Pump Shotguns - ammo_shotgun_max
+32: both autoshotguns - ammo_autoshotgun_max
+36: Hunting Rifle - ammo_huntingrifle_max
+40: Military Sniper, AWP, Scout - ammo_sniperrifle_max
+68: Grenade Launcher - ammo_grenadelauncher_max
*/
const HUNTING_RIFLE_OFFSET_IAMMO = 36;
const MILITARY_SNIPER_OFFSET_IAMMO = 40;
int ChargeLock[65];
int ReleaseLock[65];
// int CurrentWeapon;
// int ClipSize;
int ChargeEndTime[65];
Handle ClientTimer[65];
int g_sprite;
float myPos[3], trsPos[3], trsPos002[3];
/* Sound */
#define CHARGESOUND "ambient/spacial_loops/lights_flicker.wav"
#define CHARGEDUPSOUND "level/startwam.wav"
#define AWPSHOT "weapons/awp/gunfire/awp1.wav"
#define EXPLOSIONSOUND "animation/bombing_run_01.wav"
/* Sprite */
#define SPRITE_BEAM "materials/sprites/laserbeam.vmt"
ConVar l4d2_lw_lethalweapon;
ConVar l4d2_lw_lethaldamage;
ConVar l4d2_lw_lethalforce;
ConVar l4d2_lw_chargetime;
ConVar l4d2_lw_shootonce;
ConVar l4d2_lw_ff;
ConVar l4d2_lw_scout;
ConVar l4d2_lw_awp;
ConVar l4d2_lw_huntingrifle;
ConVar l4d2_lw_g3sg1;
ConVar l4d2_lw_flash;
ConVar l4d2_lw_chargingsound;
ConVar l4d2_lw_chargedsound;
ConVar l4d2_lw_moveandcharge;
ConVar l4d2_lw_chargeparticle;
ConVar l4d2_lw_useammo;
ConVar l4d2_lw_useammocount;
ConVar l4d2_lw_shake;
ConVar l4d2_lw_shake_intensity;
ConVar l4d2_lw_shake_shooteronly;
ConVar l4d2_lw_laseroffset;
ConVar l4d2_lw_friendlyfire;
ConVar l4d2_lw_firelifetime;
ConVar l4d2_lw_adminonly;
ConVar hConVar_FireLifetime;
bool g_bDamageAlly = true;
bool g_bHooked[MAXPLAYERS+1];
bool g_bBlockBlastDamage = false;
bool g_bBlockFireDamage = false;
// bool g_bLeft4Dead2 = false;
bool g_iOnlyAllowedClient[MAXPLAYERS+1];
int g_iCurWeapon[MAXPLAYERS+1];
int g_iFireLifetime = 15;
// int g_iAmmoOffset;
int g_iLethalUsed[MAXPLAYERS+1];
public Plugin myinfo =
{
name = "充能武器",
author = "ztar (Fork by Dragokas, modify by Zakikun)",
description = "Sniper rifles super shoot",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=121711"
}
/******************************************************
* Natives
*******************************************************/
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
EngineVersion test = GetEngineVersion();
if (test != Engine_Left4Dead && test != Engine_Left4Dead2)
{
strcopy(error, err_max, "Plugin only supports Left 4 Dead 1 and Left 4 Dead 2.");
return APLRes_SilentFailure;
}
// g_bLeft4Dead2 = (test == Engine_Left4Dead2);
CreateNative("Lethal_SetAllowedClient", NATIVE_Lethal_SetAllowedClient);
CreateNative("Lethal_SetAllowedClientsAll", NATIVE_Lethal_SetAllowedClientsAll);
CreateNative("Lethal_FriendlyFire", NATIVE_Lethal_FriendlyFire);
RegPluginLibrary("lethal_helpers");
return APLRes_Success;
}
public int NATIVE_Lethal_SetAllowedClient(Handle plugin, int numParams)
{
if(numParams < 2)
ThrowNativeError(SP_ERROR_PARAM, "Invalid numParams");
int client = GetNativeCell(1);
bool allow = GetNativeCell(2);
bool old = g_iOnlyAllowedClient[client];
g_iOnlyAllowedClient[client] = allow;
return view_as<int>(old);
}
public int NATIVE_Lethal_SetAllowedClientsAll(Handle plugin, int numParams)
{
bool allow = GetNativeCell(1);
for(int i = 1; i <= MaxClients; ++i)
g_iOnlyAllowedClient[i] = allow;
return 0;
}
public int NATIVE_Lethal_FriendlyFire(Handle plugin, int numParams)
{
if(numParams < 2)
ThrowNativeError(SP_ERROR_PARAM, "Invalid numParams");
bool allow = GetNativeCell(1);
bool old = g_bDamageAlly;
g_bDamageAlly = allow;
return view_as<int>(old);
}
bool UseAllowed(int client)
{
if (!g_iOnlyAllowedClient[client])
return false;
if (l4d2_lw_adminonly.BoolValue && !HasAccess(client))
return false;
return true; // g_iOnlyAllowedClient == 0 => allow for @all
}
/******************************************************
* When plugin started
*******************************************************/
public void OnPluginStart()
{
LoadTranslations("Lethal_AR.phrases");
// ConVars
l4d2_lw_lethalweapon = CreateConVar("l4d2_lw_lethalweapon","1", "是否开启插件.0=关闭.1=开启.2=开启简易模式", CVAR_FLAGS, true, 0.0, true, 3.0);
l4d2_lw_lethaldamage = CreateConVar("l4d2_lw_lethaldamage","3000.0", "充能基础伤害", CVAR_FLAGS, true, 0.0);
l4d2_lw_lethalforce = CreateConVar("l4d2_lw_lethalforce","500.0", "充能推力", CVAR_FLAGS, true, 0.0);
l4d2_lw_chargetime = CreateConVar("l4d2_lw_chargetime","7", "充能时间", CVAR_FLAGS, true, 0.01);
l4d2_lw_shootonce = CreateConVar("l4d2_lw_shootonce","0", "每回合使用上限", CVAR_FLAGS, true, 0.0);
l4d2_lw_ff = CreateConVar("l4d2_lw_ff","0", "允许对队友造成伤害", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_friendlyfire = CreateConVar("l4d2_lw_friendlyfire", "1", "允许爆炸和燃烧对队友造成伤害", FCVAR_NOTIFY, true, 0.0, true, 1.0);
l4d2_lw_scout = CreateConVar("l4d2_lw_scout","0", "允许使用Scout进行充能", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_awp = CreateConVar("l4d2_lw_awp","1", "允许使用AWP进行充能", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_huntingrifle = CreateConVar("l4d2_lw_huntingrifle","0", "允许使用15发猎枪进行充能", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_g3sg1 = CreateConVar("l4d2_lw_g3sg1","0", "允许使用30发猎枪进行充能", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_laseroffset = CreateConVar("l4d2_lw_laseroffset", "36", "射击光束偏移", FCVAR_NOTIFY, true, 0.0);
// Additional ConVars
l4d2_lw_flash = CreateConVar("l4d2_lw_flash", "1", "是否开启闪光效果", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_chargingsound = CreateConVar("l4d2_lw_chargingsound", "1", "是否开启充能声音", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_chargedsound = CreateConVar("l4d2_lw_chargedsound", "1", "是否开启充能完成声音", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_moveandcharge = CreateConVar("l4d2_lw_moveandcharge", "1", "是否允许充能时移动", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_chargeparticle = CreateConVar("l4d2_lw_chargeparticle", "1", "是否开启充能粒子效果", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_useammo = CreateConVar("l4d2_lw_useammo", "1", "是否需要消耗额外弹药", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_useammocount = CreateConVar("l4d2_lw_useammocount", "180", "消耗额外弹药数量", CVAR_FLAGS, true, 0.0);
l4d2_lw_shake = CreateConVar("l4d2_lw_shake", "1", "是否开启屏幕摇晃", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_shake_intensity = CreateConVar("l4d2_lw_shake_intensity", "50.0", "屏幕摇晃强度", CVAR_FLAGS, true, 0.0);
l4d2_lw_shake_shooteronly = CreateConVar("l4d2_lw_shake_shooteronly", "0", "是否只有射击者屏幕摇晃", CVAR_FLAGS, true, 0.0, true, 1.0);
l4d2_lw_firelifetime = CreateConVar("l4d2_lw_firelifetime", "1", "燃烧持续时间", CVAR_FLAGS, true, 0.0);
l4d2_lw_adminonly = CreateConVar("l4d2_lw_adminonly", "0", "是否管理员专用", CVAR_FLAGS, true, 0.0, true, 1.0);
hConVar_FireLifetime = FindConVar("inferno_flame_lifetime");
// g_iAmmoOffset = FindSendPropInfo("CTerrorPlayer", "m_iAmmo");
// Hooks
HookEvent("player_spawn", Event_Player_Spawn);
HookEvent("weapon_fire", Event_Weapon_Fire);
HookEvent("bullet_impact", Event_Bullet_Impact);
HookEvent("player_incapacitated", Event_Player_Incap, EventHookMode_Pre);
HookEvent("player_hurt", Event_Player_Hurt, EventHookMode_Pre);
HookEvent("player_death", Event_Player_Hurt, EventHookMode_Pre);
HookEvent("infected_death", Event_Infected_Hurt, EventHookMode_Pre);
HookEvent("infected_hurt", Event_Infected_Hurt, EventHookMode_Pre);
HookEvent("round_start", Event_Round_Start, EventHookMode_PostNoCopy);
HookEvent("finale_win", Event_Round_End, EventHookMode_PostNoCopy);
HookEvent("mission_lost", Event_Round_End, EventHookMode_PostNoCopy);
HookEvent("map_transition", Event_Round_End, EventHookMode_PostNoCopy);
HookEvent("round_end", Event_Round_End, EventHookMode_Pre);
// Weapon stuff
// CurrentWeapon = FindSendPropInfo ("CTerrorPlayer", "m_hActiveWeapon");
// ClipSize = FindSendPropInfo("CBaseCombatWeapon", "m_iClip1");
//InitCharge();
AutoExecConfig(true, "l4d2_lethal_weapon");
l4d2_lw_friendlyfire.AddChangeHook(ConVarChanged_Cvars);
hConVar_FireLifetime.AddChangeHook(ConVarChanged_Cvars);
GetCvars();
}
public void ConVarChanged_Cvars(ConVar convar, const char[] oldValue, const char[] newValue)
{
GetCvars();
}
void GetCvars()
{
g_bDamageAlly = l4d2_lw_friendlyfire.BoolValue;
g_iFireLifetime = hConVar_FireLifetime.IntValue;
}
public void OnMapStart()
{
InitPrecache();
int i;
for (i = 1; i <= MaxClients; i++)
{
ChargeEndTime[i] = 0;
ReleaseLock[i] = 0;
ChargeLock[i] = 0;
ClientTimer[i] = INVALID_HANDLE;
}
}
/*
void InitCharge()
{
// Initalize charge parameter
int i;
for (i = 1; i <= MaxClients; i++)
{
ChargeEndTime[i] = 0;
ReleaseLock[i] = 0;
ChargeLock[i] = 0;
ClientTimer[i] = INVALID_HANDLE;
}
for (i = 1; i <= MaxClients; i++)
{
if (IsValidEntity(i) && IsClientInGame(i))
{
if (GetClientTeam(i) == 2 && !IsFakeClient(i))
ClientTimer[i] = CreateTimer(0.5, ChargeTimer, i, TIMER_REPEAT);
}
}
}
*/
void InitPrecache()
{
/* Precache models */
PrecacheModel("models/props_junk/propanecanister001a.mdl", true);
PrecacheModel("models/props_junk/gascan001a.mdl", true);
/* Precache sounds */
PrecacheSound(CHARGESOUND, true);
PrecacheSound(CHARGEDUPSOUND, true);
PrecacheSound(AWPSHOT, true);
PrecacheSound(EXPLOSIONSOUND, true);
/* Precache particles */
PrecacheParticle("gas_explosion_main");
PrecacheParticle("electrical_arc_01_cp0");
PrecacheParticle("electrical_arc_01_system");
g_sprite = PrecacheModel(SPRITE_BEAM);
}
public void OnClientPutInServer(int client)
{
if (GetClientTeam(client) != 3)
Set_SDKHook(client);
}
public Action Event_Round_Start(Event event, const char[] name, bool dontBroadcast)
{
g_bBlockBlastDamage = false;
g_bBlockFireDamage = false;
}
public Action Event_Round_End(Event event, char[] event_name, bool dontBroadcast)
{
/* Timer end */
for (int i = 1; i <= MaxClients; i++)
{
if (ClientTimer[i] != INVALID_HANDLE)
{
delete ClientTimer[i];
ClientTimer[i] = INVALID_HANDLE;
}
if (IsValidEntity(i) && IsClientInGame(i))
{
ChargeEndTime[i] = 0;
ReleaseLock[i] = 0;
ChargeLock[i] = 0;
}
g_bHooked[i] = false;
g_iLethalUsed[i] = 0;
}
}
void Set_SDKHook(int client)
{
if (!g_bHooked[client])
{
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
g_bHooked[client] = true;
}
}
/*
void Remove_SDKHook(int client)
{
if (g_bHooked[client])
{
SDKUnhook(client, SDKHook_OnTakeDamage, OnTakeDamage);
g_bHooked[client] = false;
}
}
*/
public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3])
{
if (g_bBlockBlastDamage || g_bBlockFireDamage)
{
if (inflictor == attacker && attacker > MaxClients) // not impersonated entity
{
// DMG_BLAST
// DMG_BURN | DMG_PREVENT_PHYSICS_FORCE
// DMG_DIRECT | DMG_PREVENT_PHYSICS_FORCE
if ((g_bBlockBlastDamage && (damagetype & DMG_BLAST == 64)) || (g_bBlockFireDamage && (damagetype & DMG_BURN == 8)))
{
if (victim > 0 && victim <= MaxClients && GetClientTeam(victim) == 2)
{
damage = 0.0;
return Plugin_Continue; // block friendly fire on propanetank blast or fire
}
}
}
}
return Plugin_Continue;
}
public Action Event_Player_Spawn(Event event, const char[] name, bool dontBroadcast)
{
/* Timer start */
int client = GetClientOfUserId(event.GetInt("userid"));
if (client > 0 && client <= MaxClients)
{
if (IsValidEntity(client) && IsClientInGame(client))
{
if (GetClientTeam(client) == 2)
{
if (ClientTimer[client] != INVALID_HANDLE)
delete ClientTimer[client];
ChargeLock[client] = 0;
ClientTimer[client] = CreateTimer(0.5, ChargeTimer, client, TIMER_REPEAT);
}
}
}
}
public Action Event_Player_Incap(Event event, const char[] name, bool dontBroadcast)
{
/* Reset client condition */
int client = GetClientOfUserId(event.GetInt("userid"));
if (client != 0)
{
ReleaseLock[client] = 0;
ChargeEndTime[client] = RoundToCeil(GetGameTime()) + l4d2_lw_chargetime.IntValue;
}
}
public Action Event_Bullet_Impact(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (client != 0 && ReleaseLock[client])
{
float TargetPosition[3];
TargetPosition[0] = event.GetFloat("x");
TargetPosition[1] = event.GetFloat("y");
TargetPosition[2] = event.GetFloat("z");
/* Explode effect */
ExplodeMain(TargetPosition, client);
}
return Plugin_Continue;
}
public Action Event_Infected_Hurt(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("attacker"));
if (client != 0 && ReleaseLock[client])
{
/* Reset Lethal Weapon lock */
ReleaseLock[client] = 0;
int health = event.GetInt("health");
int damage = l4d2_lw_lethaldamage.IntValue;
float TargetPosition[3];
int target = GetClientAimTarget(client, false);
if (target < 0)
{
return Plugin_Continue;
}
GetEntityAbsOrigin(target, TargetPosition);
/* Smash target */
if (l4d2_lw_lethalweapon.IntValue != 2)
Smash(client, target, l4d2_lw_lethalforce.FloatValue, 1.5, 2.0);
if ((health - damage) < 0)
damage = health;
/* Deal lethal damage */
// SetEntProp(target, Prop_Data, "m_iHealth", health - damage);
DamageEntity(client, target, damage);
// health = GetEntProp(target, Prop_Data, "m_iHealth");
/* Explode effect */
EmitSoundToAll(EXPLOSIONSOUND, target);
ExplodeMain(TargetPosition, client);
}
return Plugin_Continue;
}
void DamageEntity(int client, int target, int damage, int inflictor = 0)
{
/*
char sTemp[16];
int entity = CreateEntityByName("point_hurt");
Format(sTemp, sizeof(sTemp), "ext%d%d", EntIndexToEntRef(entity), client);
DispatchKeyValue(target, "targetname", sTemp);
DispatchKeyValue(entity, "DamageTarget", sTemp);
DispatchKeyValue(entity, "DamageType", "8");
IntToString(damage, sTemp, sizeof(sTemp));
DispatchKeyValue(entity, "Damage", sTemp);
DispatchSpawn(entity);
AcceptEntityInput(entity, "Hurt", client);
RemoveEdict(entity);
*/
SDKHooks_TakeDamage(target, inflictor, client, float(damage), DMG_BURN|DMG_SHOCK|DMG_ENERGYBEAM);
}
public Action Event_Player_Hurt(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("attacker"));
int target = GetClientOfUserId(event.GetInt("userid"));
int dtype = event.GetInt("type");
if (client != 0 && target != 0 && ReleaseLock[client] && dtype != 268435464)
{
/* Reset Lethal Weapon lock */
ReleaseLock[client] = 0;
int health = event.GetInt("health");
int damage = l4d2_lw_lethaldamage.IntValue;
// decl Float:AttackPosition[3];
float TargetPosition[3];
// GetClientAbsOrigin(client, AttackPosition);
GetClientAbsOrigin(target, TargetPosition);
/* Explode effect */
EmitSoundToAll(EXPLOSIONSOUND, target);
ExplodeMain(TargetPosition, client);
/* Smash target */
if (l4d2_lw_lethalweapon.IntValue != 2)
Smash(client, target, l4d2_lw_lethalforce.FloatValue, 1.5, 2.0);
if ((health - damage) < 0)
damage = health;
/* Deal lethal damage */
if ((GetClientTeam(client) != GetClientTeam(target)) || l4d2_lw_ff.IntValue) {
// SetEntProp(target, Prop_Data, "m_iHealth", health - damage);
DamageEntity(client, target, damage);
}
}
return Plugin_Continue;
}
public Action Event_Weapon_Fire(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
ChargeEndTime[client] = RoundToCeil(GetGameTime()) + l4d2_lw_chargetime.IntValue;
if (client != 0 && ReleaseLock[client])
{
if (!g_bDamageAlly)
{
g_bBlockBlastDamage = true;
g_bBlockFireDamage = true;
CreateTimer(0.5, Timer_AllowBlastDamage, _, TIMER_FLAG_NO_MAPCHANGE);
CreateTimer(float(g_iFireLifetime) + 1.0, Timer_AllowFireDamage, _, TIMER_FLAG_NO_MAPCHANGE);
}
// g_iCurWeapon[client] = GetEntDataEnt2(client, CurrentWeapon);
g_iCurWeapon[client] = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
g_iLethalUsed[client] += 1;
/* Flash screen */
if (l4d2_lw_flash.IntValue)
{
ScreenFade(client, 200, 200, 255, 255, 100, 1);
}
if (l4d2_lw_shake.IntValue)
{
ScreenShake(client);
}
/* Laser effect */
GetTracePosition(client);
CreateLaserEffect(0, 0, 200, 230, 2.0, 1.00);
/* Emit sound */
EmitSoundToAll(
AWPSHOT, client,
SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL,
125, -1, NULL_VECTOR, NULL_VECTOR, true, 0.0);
/* Reset client condition */
CreateTimer(0.2, ReleaseTimer, client);
if (g_iLethalUsed[client] >= l4d2_lw_shootonce.IntValue)
{
ChargeLock[client] = 1;
//PrintHintText(client, "Lethal Weapon can only be fired once per round");
}
else
{
// Enable shooting more than once per round again
ChargeLock[client] = 0;
}
}
}
public Action Timer_AllowBlastDamage(Handle timer)
{
g_bBlockBlastDamage = false;
}
public Action Timer_AllowFireDamage(Handle timer)
{
g_bBlockFireDamage = false;
}
public Action ReleaseTimer(Handle timer, any client)
{
/* Set ammo after using */
if (l4d2_lw_useammo.IntValue)
{
char weapon[32];
GetClientWeapon(client, weapon, 32);
int iAmmoSpend = GetConVarInt(l4d2_lw_useammocount);
int iAmmoLeft, iAmmoOffsetToAdd;
int iAmmoClip = GetEntProp(g_iCurWeapon[client], Prop_Send, "m_iClip1", 0);
/*
if (g_bLeft4Dead2)
{
if (StrEqual(weapon, "weapon_hunting_rifle"))
{
iAmmoOffsetToAdd = HUNTING_RIFLE_OFFSET_IAMMO;
}
else if (StrEqual(weapon, "weapon_sniper_military") || StrEqual(weapon, "weapon_sniper_awp") || StrEqual(weapon, "weapon_sniper_scout"))
{
iAmmoOffsetToAdd = MILITARY_SNIPER_OFFSET_IAMMO;
}
}
else
{
iAmmoOffsetToAdd = 8;
}
iAmmoLeft = GetEntData(client, g_iAmmoOffset + iAmmoOffsetToAdd);
iAmmoLeft -= iAmmoSpend;
if (iAmmoLeft < 0) iAmmoLeft = 0;
SetEntData(client, g_iAmmoOffset + iAmmoOffsetToAdd, iAmmoLeft);
*/
iAmmoOffsetToAdd = GetEntProp(g_iCurWeapon[client], Prop_Send, "m_iPrimaryAmmoType");
iAmmoLeft = GetEntProp(client, Prop_Send, "m_iAmmo", _, iAmmoOffsetToAdd);
iAmmoLeft -= iAmmoSpend;
if (iAmmoLeft < 0) iAmmoLeft = 0;
SetEntProp(client, Prop_Send, "m_iAmmo", iAmmoLeft, _, iAmmoOffsetToAdd);
/* Set clip size */
if ((g_iCurWeapon[client]) != 0)
{
if (IsValidEntity(g_iCurWeapon[client]))
{
SetEntProp(g_iCurWeapon[client], Prop_Send, "m_iClip1", iAmmoClip + 1);
}
}
}
/* Reset flags */
ReleaseLock[client] = 0;
ChargeEndTime[client] = RoundToCeil(GetGameTime()) + GetConVarInt(l4d2_lw_chargetime);
}
public Action ChargeTimer(Handle timer, any client)
{
// Make sure we remove the lock if this ConVar is later disabled
if (l4d2_lw_shootonce.IntValue < g_iLethalUsed[client])
{
ChargeLock[client] = 0;
}
if (IsClientInGame(client))
StopSound(client, SNDCHAN_AUTO, CHARGESOUND);
if (!l4d2_lw_lethalweapon.IntValue || ChargeLock[client])
return Plugin_Continue;
if (!IsClientInGame(client) || !IsValidEntity(client))
{
ClientTimer[client] = INVALID_HANDLE;
return Plugin_Stop;
}
/* Get data */
int gt = RoundToCeil(GetGameTime());
int ct = l4d2_lw_chargetime.IntValue;
int buttons = GetClientButtons(client);
// int WeaponClass = GetEntDataEnt2(client, CurrentWeapon);
int WeaponClass = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if(WeaponClass < MaxClients || !IsValidEntity(WeaponClass))
return Plugin_Continue;
char weapon[32];
GetClientWeapon(client, weapon, 32);
int iAmmoSpend = GetConVarInt(l4d2_lw_useammocount);
int iAmmoLeft, iAmmoOffsetToAdd;
/*
if (g_bLeft4Dead2)
{
if (StrEqual(weapon, "weapon_hunting_rifle"))
{
iAmmoOffsetToAdd = HUNTING_RIFLE_OFFSET_IAMMO;
}
else if (StrEqual(weapon, "weapon_sniper_military") || StrEqual(weapon, "weapon_sniper_awp") || StrEqual(weapon, "weapon_sniper_scout"))
{
iAmmoOffsetToAdd = MILITARY_SNIPER_OFFSET_IAMMO;
}
}
else
{
iAmmoOffsetToAdd = 8;
}
iAmmoLeft = GetEntData(client, g_iAmmoOffset + iAmmoOffsetToAdd);
if (iAmmoLeft < iAmmoSpend)
iAmmoSpend = iAmmoLeft;
*/
iAmmoOffsetToAdd = GetEntProp(WeaponClass, Prop_Send, "m_iPrimaryAmmoType");
if(iAmmoOffsetToAdd <= 0 || iAmmoOffsetToAdd >= 32)
return Plugin_Continue;
iAmmoLeft = GetEntProp(client, Prop_Send, "m_iAmmo", _, iAmmoOffsetToAdd);
/* These weapons allow you to start charging */
/* Now allowed: Hunting Rifle, G3SG1, Scout, AWP */
if (!(StrEqual(weapon, "weapon_sniper_military") && l4d2_lw_g3sg1.IntValue) &&
!(StrEqual(weapon, "weapon_sniper_awp") && l4d2_lw_awp.IntValue) &&
!(StrEqual(weapon, "weapon_sniper_scout") && l4d2_lw_scout.IntValue) &&
!(StrEqual(weapon, "weapon_hunting_rifle") && l4d2_lw_huntingrifle.IntValue))
{
StopSound(client, SNDCHAN_AUTO, CHARGESOUND);
ReleaseLock[client] = 0;
ChargeEndTime[client] = gt + ct;
return Plugin_Continue;
}
if (!UseAllowed(client))
{
StopSound(client, SNDCHAN_AUTO, CHARGESOUND);
ReleaseLock[client] = 0;
ChargeEndTime[client] = gt + ct;
return Plugin_Continue;
}
// Base case to be overridden, just in case someone messes with the ConVar
int inCharge = ((GetEntityFlags(client) & FL_DUCKING) &&
(GetEntityFlags(client) & FL_ONGROUND) &&
!(buttons & IN_ATTACK) &&
!(buttons & IN_ATTACK2));
if (l4d2_lw_moveandcharge.IntValue < 1)
{
/* Ducked, not moving, not attacking, not incapacitated */
inCharge = ((GetEntityFlags(client) & FL_DUCKING) &&
(GetEntityFlags(client) & FL_ONGROUND) &&
!(buttons & IN_FORWARD) &&
!(buttons & IN_MOVERIGHT) &&
!(buttons & IN_MOVELEFT) &&
!(buttons & IN_BACK) &&
!(buttons & IN_ATTACK) &&
!(buttons & IN_ATTACK2));
}
else
{
/* Ducked, moving, not attacking, not incapacitated */
inCharge = ((GetEntityFlags(client) & FL_DUCKING) &&
(GetEntityFlags(client) & FL_ONGROUND) &&
!(buttons & IN_ATTACK) &&
!(buttons & IN_ATTACK2));
}
/* If in charging, display charge bar */
// if (inCharge && GetEntData(WeaponClass, ClipSize) && iAmmoLeft>=iAmmoSpend && iAmmoLeft != 0)
if (inCharge && GetEntProp(WeaponClass, Prop_Send, "m_iClip1") && iAmmoLeft>=iAmmoSpend && iAmmoLeft != 0)
{
if (ChargeEndTime[client] < gt)
{
/* Charge end, ready to fire */
PrintCenterText(client, "☠☠☠☠☠☠ %t ☠☠☠☠☠☠", "SHOOT"); // СТРЕЛЯЙ
if (ReleaseLock[client] != 1)
{
float pos[3];
GetClientAbsOrigin(client, pos);
if (l4d2_lw_chargedsound.IntValue)
{
EmitSoundToAll(CHARGEDUPSOUND, client);
}
if (l4d2_lw_chargeparticle.IntValue)
{
ShowParticle(pos, "electrical_arc_01_system", 5.0);
}
}
ReleaseLock[client] = 1;
}
else
{
/* Not charged yet. Display charge gauge */
int i, j;
char ChargeBar[50];
char Gauge1[2] = "|";
char Gauge2[2] = " ";
float GaugeNum = (float(ct) - (float(ChargeEndTime[client] - gt))) * (100.0/float(ct))/2.0;
ReleaseLock[client] = 0;
if(GaugeNum > 50.0)
GaugeNum = 50.0;
for(i=0; i<GaugeNum; i++)
ChargeBar[i] = Gauge1[0];
for(j=i; j<50; j++)
ChargeBar[j] = Gauge2[0];
if (GaugeNum >= 15)
{
/* Gauge meter is 30% or more */
float pos[3];
GetClientAbsOrigin(client, pos);
pos[2] += 45;
if (l4d2_lw_chargeparticle.IntValue)
{
ShowParticle(pos, "electrical_arc_01_cp0", 5.0);
}
if (l4d2_lw_chargingsound.IntValue)
{
EmitSoundToAll(CHARGESOUND, client);
}
}
/* Display gauge */
PrintCenterText(client, "★★★ %t ★★★\n0%% %s %3.0f%%", "Charging...", ChargeBar, GaugeNum*2); // Заряжается...
}
}
else
{
/* Not matching condition */
StopSound(client, SNDCHAN_AUTO, CHARGESOUND);
ReleaseLock[client] = 0;
ChargeEndTime[client] = gt + ct;
}
return Plugin_Continue;
}
void ExplodeMain(float pos[3], int attacker)
{
hConVar_FireLifetime.SetInt(l4d2_lw_firelifetime.IntValue, true, false);
/* Main effect when hit */
if (l4d2_lw_chargeparticle.IntValue)
{
ShowParticle(pos, "electrical_arc_01_system", l4d2_lw_firelifetime.FloatValue);
}
LittleFlower(pos, EXPLODE, attacker);
if (l4d2_lw_lethalweapon.IntValue == 1)
{
ShowParticle(pos, "gas_explosion_main", l4d2_lw_firelifetime.FloatValue);
LittleFlower(pos, MOLOTOV, attacker);
}
CreateTimer(l4d2_lw_firelifetime.FloatValue + 0.5, Timer_RestoreLifeTime);
}
Action Timer_RestoreLifeTime(Handle timer)
{
hConVar_FireLifetime.RestoreDefault(true, false);
}
void ShowParticle(float pos[3], char[] particlename, float time)
{
/* Show particle effect you like */
int particle = CreateEntityByName("info_particle_system");
if (IsValidEntity(particle) || IsValidEdict(particle))
{
char sBuffer[32];
sBuffer[0] = 0;
TeleportEntity(particle, pos, NULL_VECTOR, NULL_VECTOR);
DispatchKeyValue(particle, "effect_name", particlename);
DispatchKeyValue(particle, "targetname", "particle");
DispatchSpawn(particle);
ActivateEntity(particle);
AcceptEntityInput(particle, "start");
// CreateTimer(time, DeleteParticles, particle);
Format(sBuffer, sizeof(sBuffer), "OnUser1 !self:Kill::%f:-1", time);
SetVariantString(sBuffer);
AcceptEntityInput(particle, "AddOutput");
AcceptEntityInput(particle, "FireUser1");
}
}
void PrecacheParticle(char[] particlename)
{
/* Precache particle */
int particle = CreateEntityByName("info_particle_system");
if (IsValidEntity(particle) || IsValidEdict(particle))
{
DispatchKeyValue(particle, "effect_name", particlename);
DispatchKeyValue(particle, "targetname", "particle");
DispatchSpawn(particle);
ActivateEntity(particle);
AcceptEntityInput(particle, "start");
// CreateTimer(0.01, DeleteParticles, particle);
SetVariantString("OnUser1 !self:Kill::0.01:-1");
AcceptEntityInput(particle, "AddOutput");
AcceptEntityInput(particle, "FireUser1");
}
}
/*
public Action:DeleteParticles(Handle:timer, any:particle)
{
if (IsValidEntity(particle))
{
new String:classname[64];
GetEdictClassname(particle, classname, sizeof(classname));
if (StrEqual(classname, "info_particle_system", false))
RemoveEdict(particle);
}
}
*/
void LittleFlower(float pos[3], int type, int attacker)
{
/* Cause fire(type=0) or explosion(type=1) */
int entity = CreateEntityByName("prop_physics");
if (IsValidEntity(entity))
{
pos[2] += 10.0;
if (type == 0)
/* fire */
DispatchKeyValue(entity, "model", "models/props_junk/gascan001a.mdl");
else
/* explode */
DispatchKeyValue(entity, "model", "models/props_junk/propanecanister001a.mdl");
DispatchSpawn(entity);
// SetEntData(entity, GetEntSendPropOffs(entity, "m_CollisionGroup"), 1, 1, true);
SetEntProp(entity, Prop_Send, "m_CollisionGroup", 1);
TeleportEntity(entity, pos, NULL_VECTOR, NULL_VECTOR);
AcceptEntityInput(entity, "break", attacker, entity);
}
}
void GetEntityAbsOrigin(int entity, float origin[3])
{
/* Get target posision */