-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgasconfig.sp
More file actions
2049 lines (1744 loc) · 52.5 KB
/
gasconfig.sp
File metadata and controls
2049 lines (1744 loc) · 52.5 KB
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
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <adminmenu>
#include <weapons>
#define DEBUG 0
#define DEBUGLOG 0
#define PLUGIN_VERSION "1.0a" // Adaptation changes by FAILdows
#define L4D_TEAM_SPECTATE 1
#define L4D_TEAM_SURVIVORS 2
#define L4D_TEAM_INFECTED 3
#define MODELID_NICK 194
#define MODELID_ROCHELLE 195
#define MODELID_COACH 196
#define MODELID_ELLIS 197
#define MODELID_BILL 90
#define MODELID_ZOEY 91
#define MODELID_FRANCIS 92
#define MODELID_LOUIS 93
#define HIGHLIGHT_TIMER 6.0
#define COLOR_RED 999
#define COLOR_BLUE 200000000
#define COLOR_YELLOW 1238947
#define COLOR_WHITE 9999999
/*
* TODO:
* * Fix bug where it puts back the players gun if they're standing next to the gun spawn when loading the gas
*/
public Plugin:myinfo =
{
name = "Gas Configs",
author = "khan",
description = "Save and load gas configs",
version = PLUGIN_VERSION
}
#define IS_VALID_CLIENT(%1) (%1 > 0 && %1 <= MaxClients)
#define IS_SURVIVOR(%1) (GetClientTeam(%1) == 2)
#define IS_VALID_INGAME(%1) (IS_VALID_CLIENT(%1) && IsClientInGame(%1))
#define IS_VALID_SURVIVOR(%1) (IS_VALID_INGAME(%1) && IS_SURVIVOR(%1))
#define IS_SURVIVOR_ALIVE(%1) (IS_VALID_SURVIVOR(%1) && IsPlayerAlive(%1))
#define WEAPON_NOT_CARRIED 0 // Weapon is not with survivor
#define WEAPON_IS_CARRIED_BY_PLAYER 1 // Survivor is carrying weapon
#define WEAPON_IS_ACTIVE 2 // Survivor has weapon equipped
// new const String:WeaponSpawnNames[WeaponId][] = // Modified - SM 1.12
new const String:WeaponSpawnNames[WEPID_SIZE][] =
{
"weapon_none_spawn", "weapon_pistol_spawn", "weapon_smg_spawn", // 0
"weapon_pumpshotgun_spawn", "weapon_autoshotgun_spawn", "weapon_rifle_spawn", // 3
"weapon_hunting_rifle_spawn", "weapon_smg_silenced_spawn", "weapon_shotgun_chrome_spawn", // 6
"weapon_rifle_desert_spawn", "weapon_sniper_military_spawn", "weapon_shotgun_spas_spawn", // 9
"weapon_first_aid_kit_spawn", "weapon_molotov_spawn", "weapon_pipe_bomb_spawn", // 12
"weapon_pain_pills_spawn", "prop_physics", "prop_physics", // 15
"prop_physics", "", "weapon_chainsaw_spawn", // 18 weapon_melee_spawn
"weapon_grenade_launcher_spawn", "weapon_ammo_pack_spawn", "weapon_adrenaline_spawn", // 21
"weapon_defibrillator_spawn", "weapon_vomitjar_spawn", "weapon_rifle_ak47_spawn", // 24
"", "", "prop_physics", // 27
"weapon_upgradepack_incendiary_spawn", "weapon_upgradepack_explosive_spawn", "weapon_pistol_magnum_spawn", // 30
"weapon_smg_mp5_spawn", "weapon_rifle_sg552_spawn", "weapon_sniper_awp_spawn", // 33
"weapon_sniper_scout_spawn", "weapon_rifle_m60_spawn", "", // 36
"", "", "", // 39
"", "", "", // 42
"", "", "", // 45
"", "", "", // 48
"", "", "", // 51
"weapon_ammo_spawn", ""
}
new const String:FireworkModel[] = "models/props_junk/explosive_box001.mdl";
new const String:PropaneModel[] = "models/props_junk/propanecanister001a.mdl";
new String:g_sMapName[128];
new String:g_sDirPath[PLATFORM_MAX_PATH];
new String:g_sConfigFilePath[PLATFORM_MAX_PATH];
new g_iMaxSetups;
new Float:g_fHighlightTime;
new Handle:g_hSetupLimit = INVALID_HANDLE;
new Handle:g_hLegitCan = INVALID_HANDLE;
new Handle:g_hAdminMenu = INVALID_HANDLE;
new bool:g_bAdminMenu[MAXPLAYERS];
new g_iGasCount;
new bool:g_bListen[MAXPLAYERS];
new g_iListenStart[MAXPLAYERS];
new String:g_sDefaultConfig[128];
new bool:g_bRoundStart;
new bool:g_bLegitCans;
new g_iOwnerEntity;
new Handle:g_hDeletedEnts = INVALID_HANDLE;
#define NUM_MODEL_TYPES 5
new const String:ModelNames[NUM_MODEL_TYPES][128] =
{
"models/props_junk/gascan001a.mdl",
"models/props_junk/propanecanister001a.mdl",
"/props_junk/propanecanister001.mdl",
"models/props_junk/explosive_box001a.mdl",
"models/props_junk/explosive_box001.mdl"
}
new const String:ClassNames[NUM_MODEL_TYPES][128] =
{
"weapon_gascan",
"weapon_propanetank",
"weapon_propanetank",
"weapon_fireworkcrate",
"weapon_fireworkcrate"
}
#define NUM_CANS_TYPES 7
new String:UniqueClassNames[NUM_CANS_TYPES][128] =
{
"weapon_gascan",
"weapon_propanetank",
"weapon_fireworkcrate",
"upgrade_ammo_incendiary",
"upgrade_ammo_explosive",
"weapon_upgradepack_incendiary_spawn",
"weapon_upgradepack_explosive_spawn"
}
new bool:g_bMovingCans;
public OnPluginStart()
{
// Commands
RegConsoleCmd("sm_gasmenu", Command_GasMenu, "Loads the gas menu");
RegConsoleCmd("sm_gashere", Command_MoveGasToClient, "Moves all the gascans to the player");
// Add listeners for setting config names
AddCommandListener(Command_Say, "say");
AddCommandListener(Command_Say, "say_team");
// Hook Events
HookEvent("round_start", Event_RoundStart, EventHookMode_Pre);
HookEvent("round_end", Event_RoundEnd, EventHookMode_Pre);
HookEvent("survival_round_start", Event_SurvivalStart, EventHookMode_Pre);
// Convar gas setup limit
g_hSetupLimit = CreateConVar("l4d2_gasmenu_limit", "20", "Max number of gas setups to allow per map", 0, true, 0.0, true, 99.0);
g_hLegitCan = CreateConVar("l4d2_gasmenu_legitcan", "1", "Whether or not to spawn cans that have correct movement properties", 0, true, 0.0, true, 1.0);
HookConVarChange(g_hSetupLimit, OnSetupLimitChange);
HookConVarChange(g_hLegitCan, OnLegitCanChange);
g_iMaxSetups = GetConVarInt(g_hSetupLimit);
g_bLegitCans = GetConVarBool(g_hLegitCan);
g_hDeletedEnts = CreateTrie(); // Would be better if this was a HashSet type list since I don't actually care about the value but whatever..
Initialize();
L4D2Weapons_Init(); // this needs to be called on plugin load when using weapons.inc
}
Initialize()
{
for (new i = 0; i < MAXPLAYERS; i++)
{
g_bListen[i] = false;
}
g_bRoundStart = false;
g_bMovingCans = false;
SetListFile();
// Reset the g_iOwnerEntity when the plugin loads. Will happen on map switch which is when this needs to be cleared out...
g_iOwnerEntity = -1;
#if DEBUGLOG
LogMessage("GasConfig: Map Switched or plugin loaded");
#endif
}
public Action:Command_MoveGasToClient(client, args)
{
if (!IS_VALID_SURVIVOR(client))
{
PrintToChat(client, "You must be on the survivor team to use this command.");
return Plugin_Handled;
}
else if (g_bRoundStart)
{
PrintToChat(client, "You cannot use this command while the round is active.");
return Plugin_Handled;
}
MoveCansToClient(client);
return Plugin_Handled;
}
public Action:Command_GasMenu(client, args)
{
g_bAdminMenu[client] = false;
ShowGasConfigMenu(client);
return Plugin_Handled;
}
public OnSetupLimitChange(Handle:cvar, const String:oldVal[], const String:newVal[])
{
g_iMaxSetups = GetConVarInt(g_hSetupLimit);
}
public OnLegitCanChange(Handle:cvar, const String:oldVal[], const String:newVal[])
{
g_bLegitCans = GetConVarBool(g_hLegitCan);
}
//=================================
// Move gas cans to player
//=================================
MoveCansToClient(client)
{
if (g_bMovingCans)
{
PrintToChat(client, "\x04Cans are currently being moved. Wait a sec.");
return;
}
g_bMovingCans = true;
new Handle:hDataPack;
CreateDataTimer(0.1, Timer_MoveGas, hDataPack, TIMER_REPEAT);
FindAllGas(hDataPack, client);
ResetPack(hDataPack);
}
FindAllGas(Handle:hDataPack, client)
{
new entity = -1;
while ((entity = FindEntityByClassname(entity, "prop_physics")) != -1)
{
decl String:sModel[PLATFORM_MAX_PATH];
GetEntPropString(entity, Prop_Data, "m_ModelName", sModel, sizeof(sModel));
// if (StrContains(sModel, "gascan") != -1 || StrContains(sModel, FireworkModel) != -1) // Modified - just "gascan" will include wooden_barricade_gascans.mdl i.e. the blockade item in c11m3 construction site
if (StrContains(sModel, "gascan001a") != -1 || StrContains(sModel, FireworkModel) != -1)
{
WritePackCell(hDataPack, client);
WritePackCell(hDataPack, entity);
}
}
entity = -1;
while ((entity = FindEntityByClassname(entity, "weapon_gascan")) != -1)
{
if (IsValidEntity(entity))
{
WritePackCell(hDataPack, client);
WritePackCell(hDataPack, entity);
}
}
}
public Action:Timer_MoveGas(Handle:hTimer, Handle:hDataPack)
{
if (!IsPackReadable(hDataPack, 16))
{
KillTimer(hTimer);
g_bMovingCans = false;
return Plugin_Handled;
}
new client = ReadPackCell(hDataPack);
new iEnt = ReadPackCell(hDataPack);
new Float:vPos[3];
GetClientEyePosition(client, vPos);
if (IsValidEntity(iEnt))
{
new Float:vVel[3] = { 0.0, 0.0, 0.0}
TeleportEntity(iEnt, vPos, NULL_VECTOR, vVel); // Overwriting velocity b/c using NULL_VECTOR for the velocity causes gas cans to float in the air for some reason..
}
return Plugin_Continue;
}
//=================================
// Listen commands
//=================================
public Action:Command_Say(client, const String:command[], argc)
{
if (g_bListen[client])
{
g_bListen[client] = false;
if ((GetTime() - g_iListenStart[client]) >=10)
{
return Plugin_Continue;
}
decl String:text[128];
new startidx = 0;
new String:dest[128];
if (GetCmdArgString(text, sizeof(text)) < 1)
{
return Plugin_Continue;
}
if (text[strlen(text)-1] == '"')
{
text[strlen(text)-1] = '\0';
startidx = 1;
}
Format(dest, sizeof(dest), text[startidx]);
SaveGasSetupHandle(client, dest);
return Plugin_Handled;
}
return Plugin_Continue;
}
//=================================
// Helper Methods
//=================================
public CreateConfigDir()
{
new String:path[PLATFORM_MAX_PATH] = "addons/sourcemod/data/GasConfigs";
if (!DirExists(path))
{
// CreateDirectory(path, 3); // Modified - File permission should be 0755
CreateDirectory(path, 493);
}
StrCat(path, sizeof(path), "/");
StrCat(path, sizeof(path), g_sMapName);
if (!DirExists(path))
{
// CreateDirectory(path, 3); // Modified - File permission should be 0755
CreateDirectory(path, 493);
}
g_sDirPath = path;
}
public SetKVPath(String:fileName[128], String:sCfgPath[PLATFORM_MAX_PATH])
{
BuildPath(Path_SM, sCfgPath, sizeof(sCfgPath), "data/GasConfigs/%s/%s.cfg", g_sMapName, fileName);
}
public SetListFile()
{
// Create the GasConfigs directory if necessary
new String:path[PLATFORM_MAX_PATH] = "addons/sourcemod/data/GasConfigs";
if (!DirExists(path))
{
// CreateDirectory(path, 3); // Modified - File permission should be 0755
CreateDirectory(path, 493);
}
BuildPath(Path_SM, g_sConfigFilePath, sizeof(g_sConfigFilePath), "data/GasConfigs/CfgList.cfg");
}
public AddToCurrentlyBeingDeletedList(iEnt)
{
decl String:sEnt[64];
IntToString(iEnt, sEnt, sizeof(sEnt));
new val;
if (!GetTrieValue(g_hDeletedEnts, sEnt, val))
{
SetTrieValue(g_hDeletedEnts, sEnt, 1);
}
}
public RemoveItem(WeaponId:wID)
{
new iEnt;
// Find and kill any matching entities.
while ((iEnt = FindEntityByClassname(iEnt, WeaponNames[wID])) != -1)
{
if (!IsValidEdict(iEnt) || !IsValidEntity(iEnt)) {
continue;
}
AcceptEntityInput(iEnt, "kill");
AddToCurrentlyBeingDeletedList(iEnt);
}
// Kill the spawns for the weapon as well
if (StrEqual(WeaponSpawnNames[wID], "prop_physics", false))
{
// Gas, propane, and fireworks are all prop_physics. Need to verify that we're killing the correct entity by checking the model. Properly could just kill all prop_physics if we don't care about oxygen tanks...
KillItemByModel(wID);
}
else
{
// Look up all spawns for special ammo and kill them.
KillItemBySpawn(wID);
}
}
public KillItemByModel(WeaponId:wID)
{
new iEnt;
new String:sEntModel[128];
while ((iEnt = FindEntityByClassname(iEnt, WeaponSpawnNames[wID])) != -1)
{
if (!IsValidEdict(iEnt) || !IsValidEntity(iEnt)) {
continue;
}
GetEntPropString(iEnt, Prop_Data, "m_ModelName", sEntModel, sizeof(sEntModel));
if (StrContains(sEntModel, WeaponModels[wID], false) != -1)
{
if (bool:GetEntProp(iEnt, Prop_Send, "m_isCarryable", 1))
{
AcceptEntityInput(iEnt, "kill");
AddToCurrentlyBeingDeletedList(iEnt);
}
}
else if (wID == WeaponId:WEPID_FIREWORKS_BOX && StrEqual(sEntModel, FireworkModel, false)) // fireworks use a different model then what the weapons.inc lists... at least in concert survival.
{
if (bool:GetEntProp(iEnt, Prop_Send, "m_isCarryable", 1))
{
AcceptEntityInput(iEnt, "kill");
AddToCurrentlyBeingDeletedList(iEnt);
}
}
else if (wID == WeaponId:WEPID_PROPANE_TANK && StrEqual(sEntModel, PropaneModel, false))
{
if (bool:GetEntProp(iEnt, Prop_Send, "m_isCarryable", 1))
{
AcceptEntityInput(iEnt, "kill");
AddToCurrentlyBeingDeletedList(iEnt);
}
}
}
}
public KillItemBySpawn(WeaponId:wID)
{
new iEnt;
while ((iEnt = FindEntityByClassname(iEnt, WeaponSpawnNames[wID])) != -1)
{
if (!IsValidEdict(iEnt) || !IsValidEntity(iEnt)) {
continue;
}
AcceptEntityInput(iEnt, "kill");
AddToCurrentlyBeingDeletedList(iEnt);
}
}
public IsWeaponEquipped(weapon)
{
new state = GetEntProp(weapon, Prop_Data, "m_iState");
if (state == WEAPON_IS_ACTIVE)
{
return true;
}
return false;
}
public ChangeSpawnType(client, bool:bUseLegitCans)
{
if (bUseLegitCans)
{
SetConVarBool(g_hLegitCan, true);
PrintToChat(client, "\x04Will place cans with the correct movement settings.");
}
else
{
SetConVarBool(g_hLegitCan, false);
PrintToChat(client, "\x04Will use default incorrect movement settings when moving cans.");
}
g_bLegitCans = GetConVarBool(g_hLegitCan);
}
public Action:Timer_RetakePlayer(Handle:timer, any:client)
{
RetakePlayer(client);
}
RetakePlayer(client)
{
new model = GetEntProp(client, Prop_Send, "m_nModelIndex");
new String:bot[32];
switch (model)
{
case MODELID_NICK:
{
bot = "Nick";
}
case MODELID_ROCHELLE:
{
bot = "Rochelle";
}
case MODELID_COACH:
{
bot = "Coach";
}
case MODELID_ELLIS:
{
bot = "Ellis";
}
case MODELID_BILL:
{
bot = "Bill";
}
case MODELID_ZOEY:
{
bot = "Zoey";
}
case MODELID_LOUIS:
{
bot = "Louis";
}
case MODELID_FRANCIS:
{
bot = "Francis";
}
}
if (!StrEqual(bot, ""))
{
ChangePlayerTeam(client, L4D_TEAM_SPECTATE, "");
ChangePlayerTeam(client, L4D_TEAM_SURVIVORS, bot);
}
}
ChangePlayerTeam(client, team, const String:player[])
{
if(GetClientTeam(client) == team) return;
// For spectate or infected, simply move the player over
if(team != L4D_TEAM_SURVIVORS)
{
ChangeClientTeam(client, team);
return;
}
//for survivors its more tricky...
new String:command[] = "sb_takecontrol";
new flags = GetCommandFlags(command);
SetCommandFlags(command, flags & ~FCVAR_CHEAT);
new String:botNames[][128] = { "ellis", "nick", "coach", "rochelle", "zoey", "louis", "bill", "francis" };
new cTeam;
cTeam = GetClientTeam(client);
new String:dest[128];
new i = 0;
while(cTeam != L4D_TEAM_SURVIVORS && i < 8) // while player isn't on survivor, max retry of 8 times just in case...
{
// Check if they selected a specific survivor to play as
if (player[0] != EOS)
{
// Loook for specific survivor
dest = botNames[i];
if (strlen(player) < strlen(botNames[i]))
{
ReplaceString(dest, sizeof(dest), botNames[i][strlen(player)], "");
}
if (!StrEqual(dest, player, false))
{
// Not the bot that they want, continue looking
i++;
continue;
}
}
// Have player take over the bot
FakeClientCommand(client, "sb_takecontrol %s", botNames[i]);
cTeam = GetClientTeam(client);
i++; //this shouldn't be needed but just in case...
}
}
//=================================
// Save methods
//=================================
public StartListenForSave(client)
{
PrintToChat(client, "You have 10 seconds to type the config name in chat");
g_bListen[client] = true;
g_iListenStart[client] = GetTime();
}
public SaveGasSetupHandle(client, String:name[128])
{
GetCurrentMap(g_sMapName, sizeof(g_sMapName));
// Verify that the directory for this map exists
CreateConfigDir();
if (SaveGasSetup(client, name))
{
PrintToChatAll("\x05New gas config saved [\x04%s\x05]", name);
}
}
public SaveGasSetup(client, String:name[128])
{
if (!CheckListCount(client, name))
{
return false;
}
new String:sCfgPath[PLATFORM_MAX_PATH];
SetKVPath(name, sCfgPath);
// Find all the gas and save the setup
new Handle:kv = CreateKeyValues("GasConfig");
FindGas(kv);
KeyValuesToFile(kv, sCfgPath);
CloseHandle(kv);
return true;
}
public FindGas(Handle:kv)
{
g_iGasCount = 0;
new iEnt;
// Look for any gas cans that have been moved around the map
for (new i = 0; i < NUM_CANS_TYPES; i++)
{
while ((iEnt = FindEntityByClassname(iEnt, UniqueClassNames[i])) != -1)
{
if (!IsValidEdict(iEnt) || !IsValidEntity(iEnt)) {
continue;
}
ProcessGasCan(iEnt, UniqueClassNames[i], kv);
}
}
new String:sEntModel[128];
// Second loop for prop_physics objects since we need to look at the model name
while ((iEnt = FindEntityByClassname(iEnt, "prop_physics")) != -1)
{
if (!IsValidEdict(iEnt) || !IsValidEntity(iEnt)) {
continue;
}
GetEntPropString(iEnt, Prop_Data, "m_ModelName", sEntModel, sizeof(sEntModel));
for (new i = 0; i < NUM_MODEL_TYPES; i++)
{
if (StrEqual(sEntModel, ModelNames[i], false))
{
if (bool:GetEntProp(iEnt, Prop_Send, "m_isCarryable", 1))
{
ProcessGasCan(iEnt, ClassNames[i], kv);
continue;
}
}
}
}
}
public ProcessGasCan(iEnt, String:class[128], Handle:kv)
{
new Float:position[3];
new Float:angle[3];
GetEntPropVector(iEnt, Prop_Send, "m_vecOrigin", position);
GetEntPropVector(iEnt, Prop_Send, "m_angRotation", angle);
// Create unique key
new String:key[128] = "explosive";
new String:name[128];
IntToString(g_iGasCount, name, sizeof(name));
StrCat(key, sizeof(key), name);
// Add gascan as keyvalue
KvJumpToKey(kv, key, true);
KvSetString(kv, "class", class);
KvSetVector(kv, "position", position);
KvSetVector(kv, "angle", angle);
KvRewind(kv);
g_iGasCount++;
}
//===========================
// Load Methods
//===========================
public LoadGasSetupHandle(String:fileName[128], client)
{
GetCurrentMap(g_sMapName, sizeof(g_sMapName));
new String:sCfgPath[PLATFORM_MAX_PATH];
SetKVPath(fileName, sCfgPath);
if (!FileExists(sCfgPath))
{
#if DEBUG
PrintToChatAll("[LoadGasSetupHandle] File doesn't exist: %s", sCfgPath);
#endif
return;
}
LoadGasConfig(sCfgPath, client);
}
public LoadGasConfig(String:sCfgPath[PLATFORM_MAX_PATH], client)
{
new Handle:kv = CreateKeyValues("GasConfig");
if (!FileToKeyValues(kv, sCfgPath))
{
#if DEBUG
PrintToChatAll("[LoadGasConfig] Couldn't process file: %s", sCfgPath);
#endif
return;
}
if (!KvGotoFirstSubKey(kv))
{
#if DEBUG
PrintToChatAll("[LoadGasConfig] GotoFirstSubKey failed");
#endif
return;
}
// Reset our tracking of which entities are in the middle of being killed
ClearTrie(g_hDeletedEnts);
// Always remove existing special ammo and let the plugin re-place them in the "correct" location
RemoveNonGasSpawns();
// Reset the g_iOwnerEntity property value. Plugin will look it up.
//g_iOwnerEntity = -1;
// Initialize some stuff
new Handle:hGasList = CreateStack(6);
new Handle:hPropaneList = CreateStack(6);
new Handle:hFireworkList = CreateStack(6);
new numGas = 0;
new numPropane = 0;
new numFireworks = 0;
new String:buffer[255];
new String:class[64];
new Float:position[3];
new Float:angle[3];
// Look up the setup information from the config file
do
{
KvGetSectionName(kv, buffer, sizeof(buffer));
KvGetString(kv, "class", class, sizeof(class));
KvGetVector(kv, "position", position);
KvGetVector(kv, "angle", angle);
// Track the gas/propane/fireworks in a stack. Need special handling to spawn these out with the correct settings.
if (StrEqual(class, WeaponNames[WeaponId:WEPID_GASCAN]))
{
AddToStack(hGasList, position, angle);
numGas++;
}
else if (StrEqual(class, WeaponNames[WeaponId:WEPID_PROPANE_TANK]))
{
AddToStack(hPropaneList, position, angle);
numPropane++;
}
else if (StrEqual(class, WeaponNames[WeaponId:WEPID_FIREWORKS_BOX]))
{
AddToStack(hFireworkList, position, angle);
numFireworks++;
}
else
{
// Non-gas related items (ie. special ammo) can be spawned out right away
SpawnItem(class, position, angle);
}
} while (KvGotoNextKey(kv, false));
CloseHandle(kv);
/*
* Spawn gas cans, propane, fireworks into map by giving to player then forcing them to drop the can so that the gas cans move as they're supposed to (e.g. gas cans should move if a boomer explodes next to them)
* Note: if this is done within the first few seconds of a round then it will cause the players pills/kit to stick to them when they die and be unusable to others. Forcing the player to quickly spec/rejoin will fix this which is what the plugin does now.
*/
new bool:bRetakeSurvivor = false;
// First find a client to give the gas to if needed
if (client == -1)
{
new playerSurvivor = -1;
// Client didn't run this command - ie. beginning of round or map transition
for (new i = 0; i < MAXPLAYERS; i++)
{
if (IS_SURVIVOR_ALIVE(i))
{
if (IsFakeClient(i))
{
// Prefer using a bot survivor for this
client = i;
break;
}
else if (playerSurvivor == -1)
{
playerSurvivor = i;
}
}
}
if (client == -1 && playerSurvivor != -1)
{
// This is the start of the round and we're using a player. Need to make sure we force the player to retake control of the bot to avoid stupid issues..
client = playerSurvivor;
bRetakeSurvivor = true;
}
}
// Determine how to spawn out the gas
if (client == -1 || !UseLegitCanSetup())
{
#if DEBUGLOG
LogMessage("Spawning gas the old way");
#endif
/* Don't have a valid survivor or admin wanted to spawn it the old way. Spawn the gas normally. The movement of the gas will be off but whatever... */
// Remove the existing gas from the map
RemoveGasSpawns();
// Spawn out the gas to the correct location
while (!IsStackEmpty(hGasList))
{
PopStackAndSpawn(hGasList, WeaponId:WEPID_GASCAN);
}
while (!IsStackEmpty(hPropaneList))
{
PopStackAndSpawn(hPropaneList, WeaponId:WEPID_PROPANE_TANK);
}
while (!IsStackEmpty(hFireworkList))
{
PopStackAndSpawn(hFireworkList, WeaponId:WEPID_FIREWORKS_BOX);
}
}
else
{
/* Spawn out the gas in a way that will cause it to have the correct movement settings */
#if DEBUGLOG
LogMessage("Spawning gas cans with the correct movement settings");
#endif
/*
PrintToChatAll("Gas: %i - %i", NumSpawns(WeaponId:WEPID_GASCAN), numGas);
PrintToChatAll("Propane: %i - %i", NumSpawns(WeaponId:WEPID_PROPANE_TANK), numPropane);
PrintToChatAll("Fireworks: %i - %i", NumSpawns(WeaponId:WEPID_FIREWORKS_BOX), numFireworks);
*/
new bool:bNewCans = false;
if (NumSpawns(WeaponId:WEPID_GASCAN) != numGas ||
NumSpawns(WeaponId:WEPID_PROPANE_TANK) != numPropane ||
NumSpawns(WeaponId:WEPID_FIREWORKS_BOX) != numFireworks)
{
// Don't have enough cans on the map to use. Will need to spawn new cans which means special handling in order to spawn cans with the correct movements.
bNewCans = true;
#if DEBUGLOG
LogMessage(" Using new cans because numbers don't match up");
#endif
}
else if (g_iOwnerEntity == -1 && (numPropane > 0 || numFireworks > 0))
{
// Don't have a valid g_iOwnerEntity property for this map yet. Need to spawn a propane to find one.
// *TODO* Shouldn't need to remove the gascans if they're already correct
bNewCans = true;
#if DEBUGLOG
LogMessage(" Using new cans becuase g_iOwnerEntity is -1");
#endif
}
else
{
// Already have enough cans on the map. Just move them around instead of spawning new ones.
bNewCans = false;
}
if (bNewCans)
{
/* Give cans to players and force them to drop it to create a can with the correct movement properties */
#if DEBUGLOG
LogMessage("Spawning new gas cans");
#endif
// Get rid of any existing cans
RemoveGasSpawns();
new weapon = GetPlayerWeaponSlot(client, 0); // Need to use primary or secondary. Equiping pills or throwables won't work to create proper gascans...
if (weapon != -1)
{
/* Always use primary for now...
new secondary = GetPlayerWeaponSlot(client, 1);
if (secondary != -1 && IsWeaponEquipped(secondary))
{
bSecondary = true;
weapon = secondary;
} */
}
new iClip = 0;
new ammo = 0;
new iPrimType = -1;
new bool:bSpawnedSMG = false;
if (weapon == -1)
{
bSpawnedSMG = true;
// give player an smg temporarily because we need to re-equip a primary or secondary for this to work. When a map loads, the player will only have pistols and re-equiping those causes them to duplicate a bunch - at least the way I was doing things...
new index = CreateEntityByName("weapon_smg");
DispatchSpawn(index);
EquipPlayerWeapon(client, index);
weapon = index;
}
else
{
// Track how much ammo the player had
iClip = GetEntProp(weapon, Prop_Send, "m_iClip1");
iPrimType = GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoType");
ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, iPrimType);
}
for (new i = 0; i < numGas; i++)
{
GiveItem(client, "weapon_gascan");
// Force player to drop the gascan. Need to do this after every gas can otherwise the movement settings aren't correct. (ie. dropping gas by giving a new gascan isn't the same as dropping gascan from switching weapons).
EquipPlayerWeapon(client, weapon);
}
GiveItem(client, "weapon_propanetank");
if (bSpawnedSMG)
{
// Kill the SMG now that we're done spawning gas
AcceptEntityInput(weapon, "kill");
}
else
{
// Used the players gun, so we don't need to kill it but we do need to correct the ammo for it.
SetEntProp(weapon, Prop_Send, "m_iClip1", iClip, sizeof(iClip));
if (iPrimType != -1 && ammo > 0)
{
SetEntProp(client, Prop_Send, "m_iAmmo", ammo, _, iPrimType);
}
}
// Find the m_hOwnerEntity property of the propane that was spawned. Then kill the entity so that we can spawn in new propane and correctly set that property.
new iEnt;
while ((iEnt = FindEntityByClassname(iEnt, WeaponNames[WeaponId:WEPID_PROPANE_TANK])) != -1)
{
if (!IsValidEdict(iEnt) || !IsValidEntity(iEnt)) {
continue;
}
// retrieve the m_hOwnerEntity property...
g_iOwnerEntity = GetEntProp(iEnt, Prop_Send, "m_hOwnerEntity");
AcceptEntityInput(iEnt, "kill"); // kill it now that we have the owner entity...
}
}
if (bRetakeSurvivor)
{
/*
* Force the player used to create gas cans to join spectators and back to survivor in order to avoid having kit/pills stick to them when they die.
* This is only needed if the cans are loaded within the first few seconds of the round restarting. I'm assuming if the client was passed in (i.e. someone is manually loading a setup) that they aren't doing it within the first few seconds and we can skip this.
* Waiting a full second because this conflicts with the AutoSetup plugin if this runs before that's finished giving out weapons.
*/
CreateTimer(1.0, Timer_RetakePlayer, client);
}
// Move the gas cans into place
FindAndMoveGas(WeaponId:WEPID_GASCAN, hGasList);