-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathl4dgunmenu.sp
1339 lines (1175 loc) · 44.4 KB
/
l4dgunmenu.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
/*
* [L4D2] GunMenu by SwiftReal
* original plugin: TankBuster 2
* original author: teddyruxpin
*/
#include <sourcemod>
#include <sdktools>
#include <entity>
#define PLUGIN_VERSION "1.0"
#define DELAY_EQUIPDEFIB 0.5
#define CVAR_FLAGS FCVAR_PLUGIN|FCVAR_NOTIFY
new Handle:h_MaxGive[10]
new Handle:h_ReviveOrKit
new Handle:h_AutoDefib
new Handle:h_SpecialAmmo
new Handle:h_LaserSight
new Handle:h_InfiniteChainsaw
new Handle:timer_equipdefib
new max_give[10] //array for storing initial quota of each item
new give_quota0[MAXPLAYERS+1] //quota left (each player) for item 1
new give_quota1[MAXPLAYERS+1] //quota left (each player) for item 2
new give_quota2[MAXPLAYERS+1] //quota left (each player) for item 3
new give_quota3[MAXPLAYERS+1] //quota left (each player) for item 4
new give_quota4[MAXPLAYERS+1] //quota left (each player) for item 5
new give_quota5[MAXPLAYERS+1] //quota left (each player) for item 6
new give_quota6[MAXPLAYERS+1] //quota left (each player) for item 7
new give_quota7[MAXPLAYERS+1] //quota left (each player) for item 8
new give_quota8[MAXPLAYERS+1] //quota left (each player) for item 9
new give_quota9[MAXPLAYERS+1] //quota left (each player) for item 10
new String:g_MapName[128]
new String:g_TitleOptionZero[50]
new bool:g_bRoundEnded = false
new Float:vecLocationCheckpoint[3] = { 0.0, 0.0, 0.0 }
new Float:vecLocationStart[3] = { 0.0, 0.0, 0.0 }
public Plugin:myinfo =
{
name = "[L4D2] GunMenu",
author = "SwiftReal",
description = "Allows clients to get weapons and items from a gunmenu.",
version = PLUGIN_VERSION,
url = "N/A"
}
public OnPluginStart()
{
// Require Left 4 Dead 2
decl String:sGameName[50]
GetGameFolderName(sGameName, sizeof(sGameName))
if(!StrEqual(sGameName, "left4dead2", false))
SetFailState("Only compatible with Left 4 Dead 2");
//Gun menu cvars
RegConsoleCmd("sm_gunmenu", ClientGunMenu, "Open up a gunmenu")
RegConsoleCmd("sm_gm", ClientGunMenu, "Open up a gunmenu")
//plugin version
CreateConVar("gunmenu_version", PLUGIN_VERSION, "GunMenu version", CVAR_FLAGS|FCVAR_SPONLY|FCVAR_REPLICATED)
SetConVarString(FindConVar("gunmenu_version"), PLUGIN_VERSION)
//Gun menu quota cvars for each player
h_ReviveOrKit = CreateConVar("sm_gm_reviveorkit", "1", "Set 1st menu option to do what exactly? ( 1 = revive player 2 = give healthkit 0 = both possible )", CVAR_FLAGS, true, 0.0, true, 2.0)
h_AutoDefib = CreateConVar("sm_gm_defibrillator_autoequip", "1", "If 1, player will always have at least a defibrillator", CVAR_FLAGS, true, 0.0, true, 1.0)
h_SpecialAmmo = CreateConVar("sm_gm_equip_specialammo", "0", "Equip each weapon with incendiary ammo, explosive ammo or neither? ( 1 = incendiary ammo 2 = explosive ammo 0 = disabled )", CVAR_FLAGS, true, 0.0, true, 2.0)
h_LaserSight = CreateConVar("sm_gm_equip_lasersight", "1", "If 1, each weapon will be equiped with laser sights", CVAR_FLAGS, true, 0.0, true, 1.0)
h_InfiniteChainsaw = CreateConVar("sm_gm_chainsaw_infinite_ammo", "1", "If 1, each chainsaw will have infinite fuel supply", CVAR_FLAGS, true, 0.0, true, 1.0)
h_MaxGive[0] = CreateConVar("sm_gm_max_reviveorkit", "1", "Quota given to each player for to selfrevive or obtain 100 health in each round ( -1 = unlimited 0 = disabled )", CVAR_FLAGS)
h_MaxGive[1] = CreateConVar("sm_gm_max_sgpack", "5", "Quota given to each player for obtaining a shotgun pack in each round ( -1 = unlimited 0 = disabled )", CVAR_FLAGS)
h_MaxGive[2] = CreateConVar("sm_gm_max_smgpack", "5", "Quota given to each player for obtaining an smg pack in each round ( -1 = unlimited 0 = disabled )", CVAR_FLAGS)
h_MaxGive[3] = CreateConVar("sm_gm_max_riflepack", "5", "Quota given to each player for obtaining a rifle pack and melee in each round ( -1 = unlimited 0 = disabled )", CVAR_FLAGS)
h_MaxGive[4] = CreateConVar("sm_gm_max_sniperpack", "5", "Quota given to each player for obtaining a sniper pack in each round ( -1 = unlimited 0 = disabled )", CVAR_FLAGS)
h_MaxGive[5] = CreateConVar("sm_gm_max_magnummelee", "-1", "Quota given to each player for obtaining a magnum and melee in each round ( -1 = unlimited 0 = disabled )", CVAR_FLAGS)
h_MaxGive[6] = CreateConVar("sm_gm_max_defibrillator", "10", "Quota given to each player for obtaining a defibrillator in each round ( -1 = unlimited 0 = disabled )", CVAR_FLAGS)
h_MaxGive[7] = CreateConVar("sm_gm_max_fireworkcrate", "5", "Quota given to each player for obtaining a firework crate in each round ( -1 = unlimited 0 = disabled )", CVAR_FLAGS)
h_MaxGive[8] = CreateConVar("sm_gm_max_propanetank", "5", "Quota given to each player for obtaining a propane tank in each round ( -1 = unlimited 0 = disabled )", CVAR_FLAGS)
h_MaxGive[9] = CreateConVar("sm_gm_max_minigun", "3", "Quota given to each player for spawning a heavy machine gun in each round ( -1 = unlimited 0 = disabled )", CVAR_FLAGS)
//Hook Events
HookEvent("round_start", Event_RoundStart)
HookEvent("round_end", Event_RoundEnd)
HookEvent("player_incapacitated", Event_PlayerIncapacitated)
HookEvent("weapon_drop", Event_WeaponDrop)
HookEvent("player_ledge_grab", Event_PlayerLedgeGrab)
//Precache Models
PrecacheModel("models/v_models/v_rif_sg552.mdl", true)
PrecacheModel("models/w_models/weapons/w_rifle_sg552.mdl", true)
PrecacheModel("models/v_models/v_snip_awp.mdl", true)
PrecacheModel("models/w_models/weapons/w_sniper_awp.mdl", true)
PrecacheModel("models/v_models/v_snip_scout.mdl", true)
PrecacheModel("models/w_models/weapons/w_sniper_scout.mdl", true)
PrecacheModel("models/v_models/v_smg_mp5.mdl", true)
PrecacheModel("models/w_models/weapons/w_smg_mp5.mdl", true)
PrecacheModel("models/w_models/weapons/50cal.mdl", true)
PrecacheModel("models/v_models/v_knife_t.mdl", true)
PrecacheModel("models/w_models/weapons/w_knife_t.mdl", true)
//Execute or create cfg
AutoExecConfig(true, "l4d2gunmenu")
}
public OnMapStart()
{
GetCurrentMap(g_MapName, sizeof(g_MapName))
FindSafeAreas()
}
public OnMapEnd()
{
if(timer_equipdefib != INVALID_HANDLE)
{
KillTimer(timer_equipdefib)
timer_equipdefib = INVALID_HANDLE
}
}
public FindSafeAreas()
{
new iEntityCount = GetEntityCount()
new String:sEdictClassname[128]
new Float:vecLocation[3]
for (new i = 0; i <= iEntityCount; i++)
{
if(IsValidEntity(i))
{
GetEdictClassname(i, sEdictClassname, sizeof(sEdictClassname))
if(StrContains(sEdictClassname, "info_survivor_position", false) != -1)
{
GetEntPropVector(i, Prop_Send, "m_vecOrigin", vecLocation)
vecLocationStart = vecLocation
continue
}
if(StrContains(sEdictClassname, "prop_door_rotating_checkpoint", false) != -1)
{
GetEntPropVector(i, Prop_Send, "m_vecOrigin", vecLocation)
if(GetEntProp(i, Prop_Send, "m_bLocked") == 1)
vecLocationStart = vecLocation
else
vecLocationCheckpoint = vecLocation
}
}
}
if(vecLocationCheckpoint[0] + vecLocationCheckpoint[1] + vecLocationCheckpoint[2] == 0.0)
vecLocationCheckpoint = vecLocationStart
}
bool:AllowedToSpawnItems(client)
{
new Float:vecPlayer[3]
GetClientAbsOrigin(client, vecPlayer)
// is player far enough from safehouse doors?
if(GetVectorDistance(vecLocationStart, vecPlayer, false) > 700 && GetVectorDistance(vecLocationCheckpoint, vecPlayer, false) > 700)
{
// is player not in an elevator?
if(GetEntProp(client, Prop_Send, "m_hElevator") == -1)
{
// is player far enough from the recue vehicle?
if(StrEqual(g_MapName, "c1m4_atrium", false))
{
decl Float:vecVehicle1[3] = { -4787.0, -3558.0, 113.0 }
if(GetVectorDistance(vecVehicle1, vecPlayer, false) > 400)
return true
}
else if(StrEqual(g_MapName, "c2m5_concert", false))
{
decl Float:vecVehicle1[3] = { -3528.0, 2996.0, -21.0 }
decl Float:vecVehicle2[3] = { -1113.0, 2637.0, 63.0 }
if((GetVectorDistance(vecVehicle1, vecPlayer, false) > 250) && (GetVectorDistance(vecVehicle2, vecPlayer, false) > 250))
return true
}
else if(StrEqual(g_MapName, "c3m4_plantation", false))
{
decl Float:vecVehicle1[3] = { 1664.0, 4668.0, 49.0 }
if(GetVectorDistance(vecVehicle1, vecPlayer, false) > 400)
return true
}
else if(StrEqual(g_MapName, "c4m5_milltown_escape", false))
{
decl Float:vecVehicle1[3] = { -7198.0, 7693.0, 189.0 }
decl Float:vecRadio[3] = { -5836.0, 7496.0, 463.0 }
if((GetVectorDistance(vecVehicle1, vecPlayer, false) > 400) && (GetVectorDistance(vecRadio, vecPlayer, false) > 50))
return true
}
else if(StrEqual(g_MapName, "c5m5_bridge", false))
{
decl Float:vecVehicle1[3] = { 7368.0, 3828.0, 266.0 }
if(GetVectorDistance(vecVehicle1, vecPlayer, false) > 400)
return true
}
else if(StrEqual(g_MapName, "c6m3_port", false))
{
decl Float:vecVehicle1[3] = { 3.0, -2996.0, 21.0 }
if(GetVectorDistance(vecVehicle1, vecPlayer, false) > 400)
return true
}
else
{
return true
}
}
}
return false
}
public Event_PlayerIncapacitated(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"))
if(!client) return
if(IsFakeClient(client)) return
if(give_quota0[client] != 0 && !g_bRoundEnded && GetConVarInt(h_ReviveOrKit) != 2)
CreateTimer(3.0, Timer_TipReviveSelf, client, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE)
}
public Event_PlayerLedgeGrab(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"))
if(!client) return
if(IsFakeClient(client)) return
if(give_quota0[client] != 0 && !g_bRoundEnded && GetConVarInt(h_ReviveOrKit) != 2)
CreateTimer(3.0, Timer_TipReviveSelf, client, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE)
}
public Action:Timer_TipReviveSelf(Handle:timer, any:client)
{
if(!IsClientConnected(client))
return Plugin_Stop
if(!IsClientInGame(client))
return Plugin_Stop
if(GetClientTeam(client)!=2)
return Plugin_Stop
if((IsPlayerIncapacitated(client) || IsPlayerGrabbingLedge(client)) && IsAlive(client))
{
if(IsLeft4Dead(client))
PrintHintText(client, "You are left 4 dead. Type !gm to revive yourself.")
}
else
{
return Plugin_Stop
}
return Plugin_Continue
}
stock bool:IsPlayerIncapacitated(client)
{
if(!GetEntProp(client, Prop_Send, "m_isIncapacitated"))
return false
return true
}
stock bool:IsPlayerGrabbingLedge(client)
{
if(!GetEntProp(client, Prop_Send, "m_isHangingFromLedge"))
return false
return true
}
stock bool:IsAlive(client)
{
if(!GetEntProp(client, Prop_Send, "m_lifeState"))
return true
return false
}
stock bool:IsLeft4Dead(client)
{
new Float:flClientOrigin[3]
GetClientAbsOrigin(client, flClientOrigin)
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i))
{
if(IsClientInGame(i))
{
if(GetClientTeam(i)==2 && !IsFakeClient(i) && !IsPlayerIncapacitated(i) && !IsPlayerGrabbingLedge(i) && IsAlive(i))
{
decl Float:flReviverOrigin[3]
GetClientAbsOrigin(i, flReviverOrigin)
if(GetVectorDistance(flClientOrigin , flReviverOrigin, false) < 800)
return false
}
}
}
}
return true
}
public Event_WeaponDrop(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"))
if(client == 0)
return
if(GetClientTeam(client) != 2)
return
if(!IsAlive(client))
return
new weaponId = GetEventInt(event, "propid")
if(!IsValidEntity(weaponId) || weaponId == 0)
return
decl String:weaponClassname[100]
GetEdictClassname(weaponId, weaponClassname, sizeof(weaponClassname))
/**
* no: gnome,cola_bottles,fireworkcrate,gascan,propanetank,oxygentank,first_aid_kit,adrenaline,pain_pills,weapon_grenade_launcher,melee,vomitjar,molotov,
* give pipe_bomb,incendiary_ammo,explosive_ammo
* yes: pistol,pistol_magnum,autoshotgun,shotgun_chrome,pumpshotgun,shotgun_spas,smg,smg_silenced,smg_mp5,rifle_sg552,rifle_ak47,rifle,rifle_desert,
* hunting_rifle,sniper_military,chainsaw,frying_pan,electric_guitar,katana,machete,tonfa,cricket_bat,crowbar,fireaxe,baseball_bat,knife,defibrillator
**/
if(
StrEqual(weaponClassname, "weapon_pistol") ||
StrEqual(weaponClassname, "weapon_pistol_magnum") ||
StrEqual(weaponClassname, "weapon_autoshotgun") ||
StrEqual(weaponClassname, "weapon_shotgun_chrome") ||
StrEqual(weaponClassname, "weapon_pumpshotgun") ||
StrEqual(weaponClassname, "weapon_shotgun_spas") ||
StrEqual(weaponClassname, "weapon_smg") ||
StrEqual(weaponClassname, "weapon_smg_silenced") ||
StrEqual(weaponClassname, "weapon_smg_mp5") ||
StrEqual(weaponClassname, "weapon_rifle_sg552") ||
StrEqual(weaponClassname, "weapon_rifle_ak47") ||
StrEqual(weaponClassname, "weapon_rifle") ||
StrEqual(weaponClassname, "weapon_rifle_desert") ||
StrEqual(weaponClassname, "weapon_hunting_rifle") ||
StrEqual(weaponClassname, "weapon_sniper_military") ||
StrEqual(weaponClassname, "weapon_chainsaw") ||
StrEqual(weaponClassname, "weapon_melee")
)
{
CreateTimer(20.0, Timer_KillWeapon, weaponId)
}
if(StrEqual(weaponClassname, "weapon_defibrillator"))
{
CreateTimer(5.0, Timer_KillWeapon, weaponId)
}
}
public Action:Timer_KillWeapon(Handle:timer, any:weaponId)
{
if(!IsValidEntity(weaponId) || weaponId == 0)
return Plugin_Handled
decl String:weaponClassname[100]
GetEdictClassname(weaponId, weaponClassname, sizeof(weaponClassname))
if(
StrEqual(weaponClassname, "weapon_pistol") ||
StrEqual(weaponClassname, "weapon_pistol_magnum") ||
StrEqual(weaponClassname, "weapon_autoshotgun") ||
StrEqual(weaponClassname, "weapon_shotgun_chrome") ||
StrEqual(weaponClassname, "weapon_pumpshotgun") ||
StrEqual(weaponClassname, "weapon_shotgun_spas") ||
StrEqual(weaponClassname, "weapon_smg") ||
StrEqual(weaponClassname, "weapon_smg_silenced") ||
StrEqual(weaponClassname, "weapon_smg_mp5") ||
StrEqual(weaponClassname, "weapon_rifle_sg552") ||
StrEqual(weaponClassname, "weapon_rifle_ak47") ||
StrEqual(weaponClassname, "weapon_rifle") ||
StrEqual(weaponClassname, "weapon_rifle_desert") ||
StrEqual(weaponClassname, "weapon_hunting_rifle") ||
StrEqual(weaponClassname, "weapon_sniper_military") ||
StrEqual(weaponClassname, "weapon_chainsaw") ||
StrEqual(weaponClassname, "weapon_melee") ||
StrEqual(weaponClassname, "weapon_defibrillator")
)
{
if(GetEntProp(weaponId, Prop_Send, "m_hOwner") == -1)
AcceptEntityInput(weaponId, "Kill")
}
return Plugin_Handled
}
public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
g_bRoundEnded = false
//Get inital quotas from cvars
max_give[0] = GetConVarInt(h_MaxGive[0])
max_give[1] = GetConVarInt(h_MaxGive[1])
max_give[2] = GetConVarInt(h_MaxGive[2])
max_give[3] = GetConVarInt(h_MaxGive[3])
max_give[4] = GetConVarInt(h_MaxGive[4])
max_give[5] = GetConVarInt(h_MaxGive[5])
max_give[6] = GetConVarInt(h_MaxGive[6])
max_give[7] = GetConVarInt(h_MaxGive[7])
max_give[8] = GetConVarInt(h_MaxGive[8])
max_give[9] = GetConVarInt(h_MaxGive[9])
//Sets inital quotas for every player
for (new client = 1; client <= MaxClients; client++)
{
give_quota0[client] = max_give[0]
give_quota1[client] = max_give[1]
give_quota2[client] = max_give[2]
give_quota3[client] = max_give[3]
give_quota4[client] = max_give[4]
give_quota5[client] = max_give[5]
give_quota6[client] = max_give[6]
give_quota7[client] = max_give[7]
give_quota8[client] = max_give[8]
give_quota9[client] = max_give[9]
}
if(GetConVarBool(h_AutoDefib))
{
if(timer_equipdefib == INVALID_HANDLE)
timer_equipdefib = CreateTimer(DELAY_EQUIPDEFIB, Timer_EquipDefib, _, TIMER_REPEAT)
}
}
public Action:Timer_EquipDefib(Handle:timer)
{
for (new client = 1; client <= MaxClients; client++)
{
if(IsClientConnected(client))
{
if(IsClientInGame(client))
{
if(!IsFakeClient(client) && GetClientTeam(client) == 2 && IsAlive(client) && !IsPlayerIncapacitated(client) && AllowedToSpawnItems(client))
{
if(!IsValidEdict(GetPlayerWeaponSlot(client, 3)))
BypassAndExecuteCommand(client, "give", "defibrillator")
}
}
}
}
return Plugin_Continue
}
BypassAndExecuteCommand(client, String: strCommand[], String: strParam1[])
{
new flags = GetCommandFlags(strCommand)
SetCommandFlags(strCommand, flags & ~FCVAR_CHEAT)
FakeClientCommand(client, "%s %s", strCommand, strParam1)
SetCommandFlags(strCommand, flags)
}
stock SetEntityTempHealth(client, hp)
{
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", GetGameTime())
new Float:newOverheal = hp * 1.0; // prevent tag mismatch
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", newOverheal)
}
public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
g_bRoundEnded = true
}
public OnClientPutInServer(client)
{
//Get inital quotas from cvars
max_give[0] = GetConVarInt(h_MaxGive[0])
max_give[1] = GetConVarInt(h_MaxGive[1])
max_give[2] = GetConVarInt(h_MaxGive[2])
max_give[3] = GetConVarInt(h_MaxGive[3])
max_give[4] = GetConVarInt(h_MaxGive[4])
max_give[5] = GetConVarInt(h_MaxGive[5])
max_give[6] = GetConVarInt(h_MaxGive[6])
max_give[7] = GetConVarInt(h_MaxGive[7])
max_give[8] = GetConVarInt(h_MaxGive[8])
max_give[9] = GetConVarInt(h_MaxGive[9])
//Sets inital quotas for the player just joined
give_quota0[client] = max_give[0]
give_quota1[client] = max_give[1]
give_quota2[client] = max_give[2]
give_quota3[client] = max_give[3]
give_quota4[client] = max_give[4]
give_quota5[client] = max_give[5]
give_quota6[client] = max_give[6]
give_quota7[client] = max_give[7]
give_quota8[client] = max_give[8]
give_quota9[client] = max_give[9]
}
public Action:ClientGunMenu(client, args)
{
if(g_bRoundEnded)
{
PrintToChat(client, "\x01[\x04GunMenu\x01] Round ended. No access.")
return Plugin_Handled
}
if(IsAlive(client) && GetClientTeam(client) == 2)
{
GunMenu(client)
decl String:PlayerName[128]
GetClientName(client, PlayerName, sizeof(PlayerName))
PrintToChat(client, "\x01[\x04GunMenu\x01] %s, you can also rapidly press reload twice to open the gunmenu", PlayerName)
}
return Plugin_Handled
}
public Action:GunMenu(client)
{
new iReviveOrKit = GetConVarInt(h_ReviveOrKit)
switch (iReviveOrKit)
{
case 0:
{
g_TitleOptionZero = "Revive or Healthkit"
}
case 1:
{
g_TitleOptionZero = "Revive Self"
}
case 2:
{
g_TitleOptionZero = "Healthkit"
}
}
new Handle:menu = CreateMenu(GunMenuHandler)
SetMenuTitle(menu, "GunMenu Options")
AddMenuItem(menu, "option0", g_TitleOptionZero)
AddMenuItem(menu, "option1", "Shotgun Pack")
AddMenuItem(menu, "option2", "Smg Pack")
AddMenuItem(menu, "option3", "Rifle Pack")
AddMenuItem(menu, "option4", "Sniper Pack")
AddMenuItem(menu, "option5", "Melee")
AddMenuItem(menu, "option6", "Defibrillator")
AddMenuItem(menu, "option7", "Firework Crate")
AddMenuItem(menu, "option8", "Propane Tank")
AddMenuItem(menu, "option9", "Spawn Machine Gun")
SetMenuExitButton(menu, true)
DisplayMenu(menu, client, 6)
//DisplayMenu(menu, client, MENU_TIME_FOREVER)
//return Plugin_Handled
}
public GunMenuHandler(Handle:menu, MenuAction:action, client, itemNum)
{
//Strip the CHEAT flag off of the "give" command
new giveFlags = GetCommandFlags("give")
SetCommandFlags("give", giveFlags & ~FCVAR_CHEAT)
//Strip the CHEAT flag off of the "upgrade_add" command
new upgradeFlags = GetCommandFlags("upgrade_add")
SetCommandFlags("upgrade_add", upgradeFlags & ~FCVAR_CHEAT)
new iReviveOrKit = GetConVarInt(h_ReviveOrKit)
new iSpecialAmmoType = GetConVarInt(h_SpecialAmmo)
new bool:bLaserSight = GetConVarBool(h_LaserSight)
if(action == MenuAction_Select)
{
switch (itemNum)
{
case 0: // Revive or Healthkit or both
{
if( (give_quota0[client] > 0 || give_quota0[client] < 0) && IsAlive(client) && !g_bRoundEnded )
{
if((IsPlayerIncapacitated(client) || IsPlayerGrabbingLedge(client)) && iReviveOrKit <= 1)
{
if(!IsLeft4Dead(client))
{
PrintToChat(client, "\x01[\x04GunMenu\x01] You can only revive yourself when left 4 dead!", g_TitleOptionZero)
}
else
{
FakeClientCommand(client, "give health")
decl String:GameMode[30]
GetConVarString(FindConVar("mp_gamemode"), GameMode, sizeof(GameMode))
if(StrEqual(GameMode, "mutation3", false))
{
SetEntityHealth(client, 1)
SetEntityTempHealth(client, 99)
}
else
{
new survivor_revive_health = GetConVarInt(FindConVar("survivor_revive_health"))
SetEntityHealth(client, survivor_revive_health)
SetEntityTempHealth(client, 0)
}
//Decrease remaining quota of that player by 1
give_quota0[client]--
}
}
else if(!IsPlayerIncapacitated(client) && !IsPlayerGrabbingLedge(client) && (iReviveOrKit == 0 || iReviveOrKit == 2))
{
FakeClientCommand(client, "give first_aid_kit")
//Decrease remaining quota of that player by 1
give_quota0[client]--
}
else if(IsPlayerIncapacitated(client) && iReviveOrKit == 2)
{
PrintToChat(client, "\x01[\x04GunMenu\x01] You can not obtain a healthkit when incapacitated", g_TitleOptionZero)
}
else if(!IsPlayerIncapacitated(client) && iReviveOrKit == 1)
{
PrintToChat(client, "\x01[\x04GunMenu\x01] You can only be revived when incapacitated", g_TitleOptionZero)
}
//Notify remaining quota
if(give_quota0[client] >= 0)
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04%s\x01: %dx left this round", g_TitleOptionZero, give_quota0[client])
}
else
{
if(g_bRoundEnded)
{
PrintToChat(client, "\x01[\x04GunMenu\x01] Round ended. No access.")
}
else
{
//No more quota left
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04%s\x01: None available", g_TitleOptionZero)
}
}
}
case 1: // Shotgun Pack
{
if(StrEqual(g_MapName, "c1m1_hotel", false))
{
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04Shotgun Packs\x01: Not available this round")
}
else
{
if( (give_quota1[client] > 0 || give_quota1[client] < 0 || GetUserFlagBits(client) != 0) && IsAlive(client) && !IsPlayerIncapacitated(client) && !g_bRoundEnded )
{
//Give the player a Shotgun Pack
//Give Auto Shotgun
FakeClientCommand(client, "give autoshotgun")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Give Shotgun Spas
FakeClientCommand(client, "give shotgun_spas")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Give Pump Shotgun
FakeClientCommand(client, "give pumpshotgun")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Give Shotgun Chrome
FakeClientCommand(client, "give shotgun_chrome")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Decrease remaining quota of that player by 1
if(GetUserFlagBits(client) == 0)
give_quota1[client]--
//Notify remaining quota
if(give_quota1[client] >= 0 && GetUserFlagBits(client) == 0)
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04Shotgun Packs\x01: %dx left this round",give_quota1[client])
}
else
{
if(g_bRoundEnded)
{
PrintToChat(client, "\x01[\x04GunMenu\x01] Round ended. No access.")
}
else if(IsPlayerIncapacitated(client))
{
PrintToChat(client, "\x01[\x04GunMenu\x01] You're incapacitated. No access.")
}
else
{
//No more quota left
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04Shotgun Packs\x01: None available")
}
}
}
}
case 2: // SMG Pack
{
if(StrEqual(g_MapName, "c1m1_hotel", false))
{
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04SMG Packs\x01: Not available this round")
}
else
{
if( (give_quota2[client] > 0 || give_quota2[client] < 0 || GetUserFlagBits(client) != 0) && IsAlive(client) && !IsPlayerIncapacitated(client) && !g_bRoundEnded )
{
//Give the player an SMG Pack
//Give SMG MP5
FakeClientCommand(client, "give smg_mp5")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Give SMG
FakeClientCommand(client, "give smg")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Give SMG Silenced
FakeClientCommand(client, "give smg_silenced")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Decrease remaining quota of that player by 1
if(GetUserFlagBits(client) == 0)
give_quota2[client]--
//Notify remaining quota
if(give_quota2[client] >= 0 && GetUserFlagBits(client) == 0)
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04SMG Packs\x01: %dx left this round",give_quota2[client])
}
else
{
if(g_bRoundEnded)
{
PrintToChat(client, "\x01[\x04GunMenu\x01] Round ended. No access.")
}
else if(IsPlayerIncapacitated(client))
{
PrintToChat(client, "\x01[\x04GunMenu\x01] You're incapacitated. No access.")
}
else
{
//No more quota left
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04SMG Packs\x01: None available")
}
}
}
}
case 3: // Rifle Pack
{
if(StrEqual(g_MapName, "c1m1_hotel", false))
{
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04Rifle Packs\x01: Not available this round")
}
else
{
if( (give_quota3[client] >= 0 || give_quota3[client] < 0 || GetUserFlagBits(client) != 0) && IsAlive(client) && !IsPlayerIncapacitated(client) && !g_bRoundEnded )
{
//Give the player a Rifle Pack
//Give Rifle AK47
FakeClientCommand(client, "give rifle_ak47")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Give Rifle (colt m4a1)
FakeClientCommand(client, "give rifle")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Give Rifle SG552
FakeClientCommand(client, "give rifle_sg552")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Give Rifle Desert
FakeClientCommand(client, "give rifle_desert")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Decrease remaining quota of that player by 1
if(GetUserFlagBits(client) == 0)
give_quota3[client]--
//Notify remaining quota
if(give_quota3[client] >= 0 && GetUserFlagBits(client) == 0)
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04Rifle Packs\x01: %dx left this round",give_quota3[client])
}
else
{
if(g_bRoundEnded)
{
PrintToChat(client, "\x01[\x04GunMenu\x01] Round ended. No access.")
}
else if(IsPlayerIncapacitated(client))
{
PrintToChat(client, "\x01[\x04GunMenu\x01] You're incapacitated. No access.")
}
else
{
//No more quota left
PrintToChat(client, "\x01[\x04GunMenu\x01] x04Rifle Packs\x01: None available")
}
}
}
}
case 4: // Sniper Pack
{
if(StrEqual(g_MapName, "c1m1_hotel", false))
{
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04Sniper Packs\x01: Not available this round")
}
else
{
if( (give_quota4[client] >= 0 || give_quota4[client] < 0 || GetUserFlagBits(client) != 0) && IsAlive(client) && !IsPlayerIncapacitated(client) && !g_bRoundEnded )
{
//Give the player a Sniper Pack
//Give Sniper AWP
FakeClientCommand(client, "give sniper_awp")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Give Sniper Military
FakeClientCommand(client, "give sniper_military")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Give Sniper Hunting Rifle
FakeClientCommand(client, "give hunting_rifle")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Give Sniper Scout
FakeClientCommand(client, "give sniper_scout")
if(iSpecialAmmoType == 1)
FakeClientCommand(client, "upgrade_add incendiary_ammo")
else if(iSpecialAmmoType == 2)
FakeClientCommand(client, "upgrade_add explosive_ammo")
if(bLaserSight)
FakeClientCommand(client, "upgrade_add laser_sight")
FakeClientCommand(client, "give ammo")
//Decrease remaining quota of that player by 1
if(GetUserFlagBits(client) == 0)
give_quota4[client]--
//Notify remaining quota
if(give_quota4[client] >= 0 && GetUserFlagBits(client) == 0)
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04Sniper Packs\x01: %dx left this round",give_quota4[client])
}
else
{
if(g_bRoundEnded)
{
PrintToChat(client, "\x01[\x04GunMenu\x01] Round ended. No access.")
}
else if(IsPlayerIncapacitated(client))
{
PrintToChat(client, "\x01[\x04GunMenu\x01] You're incapacitated. No access.")
}
else
{
//No more quota left
PrintToChat(client, "\x01[\x04GunMenu\x01] x04Sniper Packs\x01: None available")
}
}
}
}
case 5: // Magnum and Melee
{
if( (give_quota5[client] > 0 || give_quota5[client] < 0 || GetUserFlagBits(client) != 0) && IsAlive(client) && !IsPlayerIncapacitated(client) && !g_bRoundEnded )
{
//Give the player a Magnum and Melee
GiveMelee(client)
//Decrease remaining quota of that player by 1
if(GetUserFlagBits(client) == 0)
give_quota5[client]--
//Notify remaining quota
if(give_quota5[client] >= 0 && GetUserFlagBits(client) == 0)
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04Magnum and Melee\x01: %dx left this round",give_quota5[client])
}
else
{
//No more quota left
PrintToChat(client, "\x01[\x04GunMenu\x01] \x04Magnum and Melee\x01: None available")