-
Notifications
You must be signed in to change notification settings - Fork 2
/
l4d2_laser_spawn.sp
1133 lines (942 loc) · 31.7 KB
/
l4d2_laser_spawn.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] Laser Box Spawner
* Copyright (C) 2022 Silvers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define PLUGIN_VERSION "1.5"
/*======================================================================================
Plugin Info:
* Name : [L4D2] Laser Box Spawner
* Author : SilverShot
* Descrp : Spawns the laser sight upgrades box.
* Link : https://forums.alliedmods.net/showthread.php?t=223012
* Plugins : https://sourcemod.net/plugins.php?exact=exact&sortby=title&search=1&author=Silvers
========================================================================================
Change Log:
1.5 (11-Dec-2022)
- Changes to fix compile warnings on SourceMod 1.11.
1.4 (10-May-2020)
- Extra checks to prevent "IsAllowedGameMode" throwing errors.
- Various changes to tidy up code.
1.3 (01-Apr-2020)
- Fixed "IsAllowedGameMode" from throwing errors when the "_tog" cvar was changed before MapStart.
1.2 (05-May-2018)
- Converted plugin source to the latest syntax utilizing methodmaps. Requires SourceMod 1.8 or newer.
1.1 (11-Aug-2013)
- Fixed the Laser Box to not fall through the world on some maps.
1.0 (09-Aug-2013)
- Initial release.
========================================================================================
Thanks:
This plugin was made using source code from the following plugins.
If I have used your code and not credited you, please let me know.
* "Zuko & McFlurry" for "[L4D2] Weapon/Zombie Spawner" - Modified SetTeleportEndPoint function.
https://forums.alliedmods.net/showthread.php?t=109659
======================================================================================*/
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#define CVAR_FLAGS FCVAR_NOTIFY
#define CHAT_TAG "\x04[\x05Laser Box\x04] \x01"
#define CONFIG_SPAWNS "data/l4d2_laser_spawn.cfg"
#define MAX_SPAWNS 32
#define MODEL_LASER "models/w_models/Weapons/w_laser_sights.mdl"
Menu g_hMenuAng, g_hMenuPos;
ConVar g_hCvarAllow, g_hCvarMPGameMode, g_hCvarModes, g_hCvarModesOff, g_hCvarModesTog, g_hCvarRandom;
int g_iCvarRandom, g_iPlayerSpawn, g_iRoundStart, g_iSpawnCount, g_iSpawns[MAX_SPAWNS][2];
bool g_bCvarAllow, g_bMapStarted, g_bLoaded;
// ====================================================================================================
// PLUGIN INFO / START / END
// ====================================================================================================
public Plugin myinfo =
{
name = "[L4D2] Laser Box Spawner",
author = "SilverShot",
description = "Spawns the laser sight upgrades box.",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=223012"
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
EngineVersion test = GetEngineVersion();
if( test != Engine_Left4Dead2 )
{
strcopy(error, err_max, "Plugin only supports Left 4 Dead 2.");
return APLRes_SilentFailure;
}
return APLRes_Success;
}
public void OnPluginStart()
{
g_hCvarAllow = CreateConVar( "l4d2_laser_spawn_allow", "1", "0=Plugin off, 1=Plugin on.", CVAR_FLAGS );
g_hCvarModes = CreateConVar( "l4d2_laser_spawn_modes", "", "Turn on the plugin in these game modes, separate by commas (no spaces). (Empty = all).", CVAR_FLAGS );
g_hCvarModesOff = CreateConVar( "l4d2_laser_spawn_modes_off", "", "Turn off the plugin in these game modes, separate by commas (no spaces). (Empty = none).", CVAR_FLAGS );
g_hCvarModesTog = CreateConVar( "l4d2_laser_spawn_modes_tog", "0", "Turn on the plugin in these game modes. 0=All, 1=Coop, 2=Survival, 4=Versus, 8=Scavenge. Add numbers together.", CVAR_FLAGS );
g_hCvarRandom = CreateConVar( "l4d2_laser_spawn_random", "-1", "-1=All, 0=None. Otherwise randomly select this many Laser Boxes to spawn from the maps config.", CVAR_FLAGS );
CreateConVar( "l4d2_laser_spawn_version", PLUGIN_VERSION, "Laser Spawner plugin version.", FCVAR_NOTIFY|FCVAR_DONTRECORD);
AutoExecConfig(true, "l4d2_laser_spawn");
g_hCvarMPGameMode = FindConVar("mp_gamemode");
g_hCvarMPGameMode.AddChangeHook(ConVarChanged_Allow);
g_hCvarAllow.AddChangeHook(ConVarChanged_Allow);
g_hCvarModes.AddChangeHook(ConVarChanged_Allow);
g_hCvarModesOff.AddChangeHook(ConVarChanged_Allow);
g_hCvarModesTog.AddChangeHook(ConVarChanged_Allow);
g_hCvarRandom.AddChangeHook(ConVarChanged_Cvars);
RegAdminCmd("sm_laser_spawn", CmdSpawnerTemp, ADMFLAG_ROOT, "Spawns a temporary Laser Box at your crosshair.");
RegAdminCmd("sm_laser_spawn_save", CmdSpawnerSave, ADMFLAG_ROOT, "Spawns an Laser Box at your crosshair and saves to config.");
RegAdminCmd("sm_laser_spawn_del", CmdSpawnerDel, ADMFLAG_ROOT, "Removes the Laser Box you are pointing at and deletes from the config if saved.");
RegAdminCmd("sm_laser_spawn_clear", CmdSpawnerClear, ADMFLAG_ROOT, "Removes all Laser Boxes spawned by this plugin from the current map.");
RegAdminCmd("sm_laser_spawn_wipe", CmdSpawnerWipe, ADMFLAG_ROOT, "Removes all Laser Boxes from the current map and deletes them from the config.");
RegAdminCmd("sm_laser_spawn_glow", CmdSpawnerGlow, ADMFLAG_ROOT, "Toggle to enable glow on all Laser Boxes to see where they are placed.");
RegAdminCmd("sm_laser_spawn_list", CmdSpawnerList, ADMFLAG_ROOT, "Display a list Laser Box positions and the total number of.");
RegAdminCmd("sm_laser_spawn_tele", CmdSpawnerTele, ADMFLAG_ROOT, "Teleport to an Laser Box (Usage: sm_laser_spawn_tele <index: 1 to MAX_SPAWNS (32)>).");
RegAdminCmd("sm_laser_spawn_ang", CmdSpawnerAng, ADMFLAG_ROOT, "Displays a menu to adjust the Laser Box angles your crosshair is over.");
RegAdminCmd("sm_laser_spawn_pos", CmdSpawnerPos, ADMFLAG_ROOT, "Displays a menu to adjust the Laser Box origin your crosshair is over.");
}
public void OnPluginEnd()
{
ResetPlugin();
}
public void OnMapStart()
{
g_bMapStarted = true;
PrecacheModel(MODEL_LASER, true);
}
public void OnMapEnd()
{
g_bMapStarted = false;
ResetPlugin(false);
}
// ====================================================================================================
// CVARS
// ====================================================================================================
public void OnConfigsExecuted()
{
IsAllowed();
}
void ConVarChanged_Allow(Handle convar, const char[] oldValue, const char[] newValue)
{
IsAllowed();
}
void ConVarChanged_Cvars(Handle convar, const char[] oldValue, const char[] newValue)
{
GetCvars();
}
void GetCvars()
{
g_iCvarRandom = g_hCvarRandom.IntValue;
}
void IsAllowed()
{
bool bCvarAllow = g_hCvarAllow.BoolValue;
bool bAllowMode = IsAllowedGameMode();
GetCvars();
if( g_bCvarAllow == false && bCvarAllow == true && bAllowMode == true )
{
LoadSpawns();
g_bCvarAllow = true;
HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_PostNoCopy);
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
}
else if( g_bCvarAllow == true && (bCvarAllow == false || bAllowMode == false) )
{
ResetPlugin();
g_bCvarAllow = false;
UnhookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_PostNoCopy);
UnhookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
UnhookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
}
}
int g_iCurrentMode;
bool IsAllowedGameMode()
{
if( g_hCvarMPGameMode == null )
return false;
int iCvarModesTog = g_hCvarModesTog.IntValue;
if( iCvarModesTog != 0 )
{
if( g_bMapStarted == false )
return false;
g_iCurrentMode = 0;
int entity = CreateEntityByName("info_gamemode");
if( IsValidEntity(entity) )
{
DispatchSpawn(entity);
HookSingleEntityOutput(entity, "OnCoop", OnGamemode, true);
HookSingleEntityOutput(entity, "OnSurvival", OnGamemode, true);
HookSingleEntityOutput(entity, "OnVersus", OnGamemode, true);
HookSingleEntityOutput(entity, "OnScavenge", OnGamemode, true);
ActivateEntity(entity);
AcceptEntityInput(entity, "PostSpawnActivate");
if( IsValidEntity(entity) ) // Because sometimes "PostSpawnActivate" seems to kill the ent.
RemoveEdict(entity); // Because multiple plugins creating at once, avoid too many duplicate ents in the same frame
}
if( g_iCurrentMode == 0 )
return false;
if( !(iCvarModesTog & g_iCurrentMode) )
return false;
}
char sGameModes[64], sGameMode[64];
g_hCvarMPGameMode.GetString(sGameMode, sizeof(sGameMode));
Format(sGameMode, sizeof(sGameMode), ",%s,", sGameMode);
g_hCvarModes.GetString(sGameModes, sizeof(sGameModes));
if( sGameModes[0] )
{
Format(sGameModes, sizeof(sGameModes), ",%s,", sGameModes);
if( StrContains(sGameModes, sGameMode, false) == -1 )
return false;
}
g_hCvarModesOff.GetString(sGameModes, sizeof(sGameModes));
if( sGameModes[0] )
{
Format(sGameModes, sizeof(sGameModes), ",%s,", sGameModes);
if( StrContains(sGameModes, sGameMode, false) != -1 )
return false;
}
return true;
}
void OnGamemode(const char[] output, int caller, int activator, float delay)
{
if( strcmp(output, "OnCoop") == 0 )
g_iCurrentMode = 1;
else if( strcmp(output, "OnSurvival") == 0 )
g_iCurrentMode = 2;
else if( strcmp(output, "OnVersus") == 0 )
g_iCurrentMode = 4;
else if( strcmp(output, "OnScavenge") == 0 )
g_iCurrentMode = 8;
}
// ====================================================================================================
// EVENTS
// ====================================================================================================
void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
ResetPlugin(false);
}
void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
if( g_iPlayerSpawn == 1 && g_iRoundStart == 0 )
CreateTimer(1.0, TimerStart, _, TIMER_FLAG_NO_MAPCHANGE);
g_iRoundStart = 1;
}
void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
if( g_iPlayerSpawn == 0 && g_iRoundStart == 1 )
CreateTimer(1.0, TimerStart, _, TIMER_FLAG_NO_MAPCHANGE);
g_iPlayerSpawn = 1;
}
Action TimerStart(Handle timer)
{
ResetPlugin();
LoadSpawns();
return Plugin_Continue;
}
// ====================================================================================================
// LOAD SPAWNS
// ====================================================================================================
void LoadSpawns()
{
if( g_bLoaded || g_iCvarRandom == 0 ) return;
g_bLoaded = true;
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, sizeof(sPath), CONFIG_SPAWNS);
if( !FileExists(sPath) )
return;
// Load config
KeyValues hFile = new KeyValues("spawns");
if( !hFile.ImportFromFile(sPath) )
{
delete hFile;
return;
}
// Check for current map in the config
char sMap[64];
GetCurrentMap(sMap, sizeof(sMap));
if( !hFile.JumpToKey(sMap) )
{
delete hFile;
return;
}
// Retrieve how many Laser Boxes to display
int iCount = hFile.GetNum("num", 0);
if( iCount == 0 )
{
delete hFile;
return;
}
// Spawn only a select few Laser Boxes?
int iIndexes[MAX_SPAWNS+1];
if( iCount > MAX_SPAWNS )
iCount = MAX_SPAWNS;
// Spawn saved Laser Boxes or create random
int iRandom = g_iCvarRandom;
if( iRandom == -1 || iRandom > iCount)
iRandom = iCount;
if( iRandom != -1 )
{
for( int i = 1; i <= iCount; i++ )
iIndexes[i-1] = i;
SortIntegers(iIndexes, iCount, Sort_Random);
iCount = iRandom;
}
// Get the Laser Box origins and spawn
char sTemp[4];
float vPos[3], vAng[3];
int index;
for( int i = 1; i <= iCount; i++ )
{
if( iRandom != -1 ) index = iIndexes[i-1];
else index = i;
IntToString(index, sTemp, sizeof(sTemp));
if( hFile.JumpToKey(sTemp) )
{
hFile.GetVector("ang", vAng);
hFile.GetVector("pos", vPos);
if( vPos[0] == 0.0 && vPos[0] == 0.0 && vPos[0] == 0.0 ) // Should never happen.
LogError("Error: 0,0,0 origin. Iteration=%d. Index=%d. Random=%d. Count=%d.", i, index, iRandom, iCount);
else
CreateSpawn(vPos, vAng, index);
hFile.GoBack();
}
}
delete hFile;
}
// ====================================================================================================
// CREATE SPAWN
// ====================================================================================================
void CreateSpawn(const float vOrigin[3], const float vAngles[3], int index = 0)
{
if( g_iSpawnCount >= MAX_SPAWNS )
return;
int iSpawnIndex = -1;
for( int i = 0; i < MAX_SPAWNS; i++ )
{
if( g_iSpawns[i][0] == 0 )
{
iSpawnIndex = i;
break;
}
}
if( iSpawnIndex == -1 )
return;
int entity = CreateEntityByName("upgrade_laser_sight");
if( entity == -1 )
ThrowError("Failed to create laser sight upgrade box.");
g_iSpawns[iSpawnIndex][0] = EntIndexToEntRef(entity);
g_iSpawns[iSpawnIndex][1] = index;
SetEntityModel(entity, MODEL_LASER);
TeleportEntity(entity, vOrigin, vAngles, NULL_VECTOR);
DispatchSpawn(entity);
g_iSpawnCount++;
}
// ====================================================================================================
// COMMANDS
// ====================================================================================================
// sm_laser_spawn
// ====================================================================================================
Action CmdSpawnerTemp(int client, int args)
{
if( !client )
{
ReplyToCommand(client, "[Laser Spawner] Command can only be used %s", IsDedicatedServer() ? "in game on a dedicated server." : "in chat on a Listen server.");
return Plugin_Handled;
}
else if( g_iSpawnCount >= MAX_SPAWNS )
{
PrintToChat(client, "%sError: Cannot add anymore Laser Boxes. Used: (\x05%d/%d\x01).", CHAT_TAG, g_iSpawnCount, MAX_SPAWNS);
return Plugin_Handled;
}
float vPos[3], vAng[3];
if( !SetTeleportEndPoint(client, vPos, vAng) )
{
PrintToChat(client, "%sCannot place Laser Box, please try again.", CHAT_TAG);
return Plugin_Handled;
}
CreateSpawn(vPos, vAng, 0);
return Plugin_Handled;
}
// ====================================================================================================
// sm_laser_spawn_save
// ====================================================================================================
Action CmdSpawnerSave(int client, int args)
{
if( !client )
{
ReplyToCommand(client, "[Laser Spawner] Command can only be used %s", IsDedicatedServer() ? "in game on a dedicated server." : "in chat on a Listen server.");
return Plugin_Handled;
}
else if( g_iSpawnCount >= MAX_SPAWNS )
{
PrintToChat(client, "%sError: Cannot add anymore Laser Boxes. Used: (\x05%d/%d\x01).", CHAT_TAG, g_iSpawnCount, MAX_SPAWNS);
return Plugin_Handled;
}
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, sizeof(sPath), CONFIG_SPAWNS);
if( !FileExists(sPath) )
{
File hCfg = OpenFile(sPath, "w");
hCfg.WriteLine("");
delete hCfg;
}
// Load config
KeyValues hFile = new KeyValues("spawns");
if( !hFile.ImportFromFile(sPath) )
{
PrintToChat(client, "%sError: Cannot read the Laser Box config, assuming empty file. (\x05%s\x01).", CHAT_TAG, sPath);
}
// Check for current map in the config
char sMap[64];
GetCurrentMap(sMap, sizeof(sMap));
if( !hFile.JumpToKey(sMap, true) )
{
PrintToChat(client, "%sError: Failed to add map to Laser Box spawn config.", CHAT_TAG);
delete hFile;
return Plugin_Handled;
}
// Retrieve how many Laser Boxes are saved
int iCount = hFile.GetNum("num", 0);
if( iCount >= MAX_SPAWNS )
{
PrintToChat(client, "%sError: Cannot add anymore Laser Boxes. Used: (\x05%d/%d\x01).", CHAT_TAG, iCount, MAX_SPAWNS);
delete hFile;
return Plugin_Handled;
}
// Save count
iCount++;
hFile.SetNum("num", iCount);
char sTemp[4];
IntToString(iCount, sTemp, sizeof(sTemp));
if( hFile.JumpToKey(sTemp, true) )
{
// Set player position as Laser Box spawn location
float vPos[3], vAng[3];
if( !SetTeleportEndPoint(client, vPos, vAng) )
{
PrintToChat(client, "%sCannot place Laser Box, please try again.", CHAT_TAG);
delete hFile;
return Plugin_Handled;
}
// Save angle / origin
hFile.SetVector("ang", vAng);
hFile.SetVector("pos", vPos);
CreateSpawn(vPos, vAng, iCount);
// Save cfg
hFile.Rewind();
hFile.ExportToFile(sPath);
PrintToChat(client, "%s(\x05%d/%d\x01) - Saved at pos:[\x05%f %f %f\x01] ang:[\x05%f %f %f\x01]", CHAT_TAG, iCount, MAX_SPAWNS, vPos[0], vPos[1], vPos[2], vAng[0], vAng[1], vAng[2]);
}
else
PrintToChat(client, "%s(\x05%d/%d\x01) - Failed to save Laser Box.", CHAT_TAG, iCount, MAX_SPAWNS);
delete hFile;
return Plugin_Handled;
}
// ====================================================================================================
// sm_laser_spawn_del
// ====================================================================================================
Action CmdSpawnerDel(int client, int args)
{
if( !g_bCvarAllow )
{
ReplyToCommand(client, "[Laser Spawner] Plugin turned off.");
return Plugin_Handled;
}
if( !client )
{
ReplyToCommand(client, "[Laser Spawner] Command can only be used %s", IsDedicatedServer() ? "in game on a dedicated server." : "in chat on a Listen server.");
return Plugin_Handled;
}
int entity = GetClientAimTarget(client, false);
if( entity == -1 ) return Plugin_Handled;
entity = EntIndexToEntRef(entity);
int cfgindex, index = -1;
for( int i = 0; i < MAX_SPAWNS; i++ )
{
if( g_iSpawns[i][0] == entity )
{
index = i;
break;
}
}
if( index == -1 )
return Plugin_Handled;
cfgindex = g_iSpawns[index][1];
if( cfgindex == 0 )
{
RemoveSpawn(index);
return Plugin_Handled;
}
for( int i = 0; i < MAX_SPAWNS; i++ )
{
if( g_iSpawns[i][1] > cfgindex )
g_iSpawns[i][1]--;
}
g_iSpawnCount--;
// Load config
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, sizeof(sPath), CONFIG_SPAWNS);
if( !FileExists(sPath) )
{
PrintToChat(client, "%sError: Cannot find the Laser Box config (\x05%s\x01).", CHAT_TAG, CONFIG_SPAWNS);
return Plugin_Handled;
}
KeyValues hFile = new KeyValues("spawns");
if( !hFile.ImportFromFile(sPath) )
{
PrintToChat(client, "%sError: Cannot load the Laser Box config (\x05%s\x01).", CHAT_TAG, sPath);
delete hFile;
return Plugin_Handled;
}
// Check for current map in the config
char sMap[64];
GetCurrentMap(sMap, sizeof(sMap));
if( !hFile.JumpToKey(sMap) )
{
PrintToChat(client, "%sError: Current map not in the Laser Box config.", CHAT_TAG);
delete hFile;
return Plugin_Handled;
}
// Retrieve how many Laser Boxes
int iCount = hFile.GetNum("num", 0);
if( iCount == 0 )
{
delete hFile;
return Plugin_Handled;
}
bool bMove;
char sTemp[4];
// Move the other entries down
for( int i = cfgindex; i <= iCount; i++ )
{
IntToString(i, sTemp, sizeof(sTemp));
if( hFile.JumpToKey(sTemp) )
{
if( !bMove )
{
bMove = true;
hFile.DeleteThis();
RemoveSpawn(index);
}
else
{
IntToString(i-1, sTemp, sizeof(sTemp));
hFile.SetSectionName(sTemp);
}
}
hFile.Rewind();
hFile.JumpToKey(sMap);
}
if( bMove )
{
iCount--;
hFile.SetNum("num", iCount);
// Save to file
hFile.Rewind();
hFile.ExportToFile(sPath);
PrintToChat(client, "%s(\x05%d/%d\x01) - Laser Box removed from config.", CHAT_TAG, iCount, MAX_SPAWNS);
}
else
PrintToChat(client, "%s(\x05%d/%d\x01) - Failed to remove Laser Box from config.", CHAT_TAG, iCount, MAX_SPAWNS);
delete hFile;
return Plugin_Handled;
}
// ====================================================================================================
// sm_laser_spawn_clear
// ====================================================================================================
Action CmdSpawnerClear(int client, int args)
{
if( !client )
{
ReplyToCommand(client, "[Laser Spawner] Command can only be used %s", IsDedicatedServer() ? "in game on a dedicated server." : "in chat on a Listen server.");
return Plugin_Handled;
}
ResetPlugin();
PrintToChat(client, "%s(0/%d) - All Laser Boxes removed from the map.", CHAT_TAG, MAX_SPAWNS);
return Plugin_Handled;
}
// ====================================================================================================
// sm_laser_spawn_wipe
// ====================================================================================================
Action CmdSpawnerWipe(int client, int args)
{
if( !client )
{
ReplyToCommand(client, "[Laser Spawner] Command can only be used %s", IsDedicatedServer() ? "in game on a dedicated server." : "in chat on a Listen server.");
return Plugin_Handled;
}
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, sizeof(sPath), CONFIG_SPAWNS);
if( !FileExists(sPath) )
{
PrintToChat(client, "%sError: Cannot find the Laser Box config (\x05%s\x01).", CHAT_TAG, sPath);
return Plugin_Handled;
}
// Load config
KeyValues hFile = new KeyValues("spawns");
if( !hFile.ImportFromFile(sPath) )
{
PrintToChat(client, "%sError: Cannot load the Laser Box config (\x05%s\x01).", CHAT_TAG, sPath);
delete hFile;
return Plugin_Handled;
}
// Check for current map in the config
char sMap[64];
GetCurrentMap(sMap, sizeof(sMap));
if( !hFile.JumpToKey(sMap, false) )
{
PrintToChat(client, "%sError: Current map not in the Laser Box config.", CHAT_TAG);
delete hFile;
return Plugin_Handled;
}
hFile.DeleteThis();
ResetPlugin();
// Save to file
hFile.Rewind();
hFile.ExportToFile(sPath);
delete hFile;
PrintToChat(client, "%s(0/%d) - All Laser Boxes removed from config, add with \x05sm_laser_spawn_save\x01.", CHAT_TAG, MAX_SPAWNS);
return Plugin_Handled;
}
// ====================================================================================================
// sm_laser_spawn_glow
// ====================================================================================================
Action CmdSpawnerGlow(int client, int args)
{
static bool glow;
glow = !glow;
PrintToChat(client, "%sGlow has been turned %s", CHAT_TAG, glow ? "on" : "off");
VendorGlow(glow);
return Plugin_Handled;
}
void VendorGlow(int glow)
{
int ent;
for( int i = 0; i < MAX_SPAWNS; i++ )
{
ent = g_iSpawns[i][0];
if( IsValidEntRef(ent) )
{
SetEntProp(ent, Prop_Send, "m_iGlowType", 3);
SetEntProp(ent, Prop_Send, "m_glowColorOverride", 65535);
SetEntProp(ent, Prop_Send, "m_nGlowRange", glow ? 0 : 50);
ChangeEdictState(ent, FindSendPropInfo("prop_dynamic", "m_nGlowRange"));
}
}
}
// ====================================================================================================
// sm_laser_spawn_list
// ====================================================================================================
Action CmdSpawnerList(int client, int args)
{
float vPos[3];
int count;
for( int i = 0; i < MAX_SPAWNS; i++ )
{
if( IsValidEntRef(g_iSpawns[i][0]) )
{
count++;
GetEntPropVector(g_iSpawns[i][0], Prop_Data, "m_vecOrigin", vPos);
PrintToChat(client, "%s%d) %f %f %f", CHAT_TAG, i+1, vPos[0], vPos[1], vPos[2]);
}
}
PrintToChat(client, "%sTotal: %d.", CHAT_TAG, count);
return Plugin_Handled;
}
// ====================================================================================================
// sm_laser_spawn_tele
// ====================================================================================================
Action CmdSpawnerTele(int client, int args)
{
if( args == 1 )
{
char arg[4];
GetCmdArg(1, arg, sizeof(arg));
int index = StringToInt(arg) - 1;
if( index > -1 && index < MAX_SPAWNS && IsValidEntRef(g_iSpawns[index][0]) )
{
float vPos[3];
GetEntPropVector(g_iSpawns[index][0], Prop_Data, "m_vecOrigin", vPos);
vPos[2] += 20.0;
TeleportEntity(client, vPos, NULL_VECTOR, NULL_VECTOR);
PrintToChat(client, "%sTeleported to %d.", CHAT_TAG, index + 1);
return Plugin_Handled;
}
PrintToChat(client, "%sCould not find index for teleportation.", CHAT_TAG);
}
else
PrintToChat(client, "%sUsage: sm_laser_spawn_tele <index 1-%d>.", CHAT_TAG, MAX_SPAWNS);
return Plugin_Handled;
}
// ====================================================================================================
// MENU ANGLE
// ====================================================================================================
Action CmdSpawnerAng(int client, int args)
{
ShowMenuAng(client);
return Plugin_Handled;
}
void ShowMenuAng(int client)
{
CreateMenus();
g_hMenuAng.Display(client, MENU_TIME_FOREVER);
}
int AngMenuHandler(Menu menu, MenuAction action, int client, int index)
{
if( action == MenuAction_Select )
{
if( index == 6 )
SaveData(client);
else
SetAngle(client, index);
ShowMenuAng(client);
}
return 0;
}
void SetAngle(int client, int index)
{
int aim = GetClientAimTarget(client, false);
if( aim != -1 )
{
float vAng[3];
int entity;
aim = EntIndexToEntRef(aim);
for( int i = 0; i < MAX_SPAWNS; i++ )
{
entity = g_iSpawns[i][0];
if( entity == aim )
{
GetEntPropVector(entity, Prop_Send, "m_angRotation", vAng);
switch( index )
{
case 0: vAng[0] += 5.0;
case 1: vAng[1] += 5.0;
case 2: vAng[2] += 5.0;
case 3: vAng[0] -= 5.0;
case 4: vAng[1] -= 5.0;
case 5: vAng[2] -= 5.0;
}
TeleportEntity(entity, NULL_VECTOR, vAng, NULL_VECTOR);
PrintToChat(client, "%sNew angles: %f %f %f", CHAT_TAG, vAng[0], vAng[1], vAng[2]);
break;
}
}
}
}
// ====================================================================================================
// MENU ORIGIN
// ====================================================================================================
Action CmdSpawnerPos(int client, int args)
{
ShowMenuPos(client);
return Plugin_Handled;
}
void ShowMenuPos(int client)
{
CreateMenus();
g_hMenuPos.Display(client, MENU_TIME_FOREVER);
}
int PosMenuHandler(Menu menu, MenuAction action, int client, int index)
{
if( action == MenuAction_Select )
{
if( index == 6 )
SaveData(client);
else
SetOrigin(client, index);
ShowMenuPos(client);
}
return 0;
}
void SetOrigin(int client, int index)
{
int aim = GetClientAimTarget(client, false);
if( aim != -1 )
{
float vPos[3];
int entity;
aim = EntIndexToEntRef(aim);
for( int i = 0; i < MAX_SPAWNS; i++ )
{
entity = g_iSpawns[i][0];
if( entity == aim )
{
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vPos);
switch( index )
{
case 0: vPos[0] += 0.5;
case 1: vPos[1] += 0.5;
case 2: vPos[2] += 0.5;
case 3: vPos[0] -= 0.5;
case 4: vPos[1] -= 0.5;
case 5: vPos[2] -= 0.5;
}
TeleportEntity(entity, vPos, NULL_VECTOR, NULL_VECTOR);
PrintToChat(client, "%sNew origin: %f %f %f", CHAT_TAG, vPos[0], vPos[1], vPos[2]);
break;
}
}
}
}
void SaveData(int client)
{
int entity, index;
int aim = GetClientAimTarget(client, false);
if( aim == -1 )
return;
aim = EntIndexToEntRef(aim);
for( int i = 0; i < MAX_SPAWNS; i++ )
{
entity = g_iSpawns[i][0];
if( entity == aim )
{
index = g_iSpawns[i][1];
break;
}
}
if( index == 0 )
return;
// Load config
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, sizeof(sPath), CONFIG_SPAWNS);
if( !FileExists(sPath) )
{
PrintToChat(client, "%sError: Cannot find the Laser Spawner config (\x05%s\x01).", CHAT_TAG, CONFIG_SPAWNS);
return;
}
KeyValues hFile = new KeyValues("spawns");
if( !hFile.ImportFromFile(sPath) )
{
PrintToChat(client, "%sError: Cannot load the Laser Spawner config (\x05%s\x01).", CHAT_TAG, sPath);
delete hFile;
return;
}
// Check for current map in the config
char sMap[64];
GetCurrentMap(sMap, sizeof(sMap));
if( !hFile.JumpToKey(sMap) )
{