-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsm_trigger_multiple_commands.sp
More file actions
3215 lines (2719 loc) · 93.6 KB
/
sm_trigger_multiple_commands.sp
File metadata and controls
3215 lines (2719 loc) · 93.6 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
/*
* Trigger Multiple Commands
* Copyright (C) 2025 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.13"
#define DEBUG_LOGGING false
/*=======================================================================================
Plugin Info:
* Name : [ANY] Trigger Multiple Commands
* Author : SilverShot
* Descrp : Create trigger_multiple boxes which execute commands when entered by players.
* Link : https://forums.alliedmods.net/showthread.php?t=224121
* Plugins : https://sourcemod.net/plugins.php?exact=exact&sortby=title&search=1&author=Silvers
========================================================================================
Change Log:
1.13 (01-Jul-2025)
- Truncated menu entries to prevent overflowing the menu text and not displaying "previous", "next" and "exit" options.
1.12 (21-May-2025)
- Fixed delayed commands triggering after a round restart or map change. Thanks to "Tighty-Whitey" for reporting.
1.11 (15-Dec-2024)
- Fixed delayed commands not always working. Thanks to "PVNDV" for fixing.
1.10 (16-May-2024)
- Added the "Bots or Players activate" option to the edit menu.
- Added option to fire triggers on certain events: player spawn/player death/team change/player connect/ player disconnect.
- This will execute the trigger if any players are inside the trigger area and the trigger is set to fire for these events.
- The trigger will still go through all the other options before finally executing, if everything else passed.
- Thanks to "replay_84" for reporting issues and testing.
1.9 (20-Dec-2023)
- Added option to fire triggers "Once per player", under the refire options menu. Requested by "replay_84".
1.8 (01-Oct-2023)
- Added a new menu option which allows requiring all players to be present to activate. Requested by "replay_84".
- Added a debug option (requires recompile) to log various data when activating a trigger to determine where it fails.
- Changed command "sm_trigger_dupe" to allow specifying an index to duplicate that trigger.
- Duplicated triggers now copy the size of the trigger instead of setting to the default size.
- Now when the plugin is late loaded, triggers will detect players inside and fire after being created if the criteria was met.
- Lots of thanks to "replay_84" for tons of testing and reporting back.
1.7 (02-Sep-2022)
- Fixed client not connected errors. Thanks to "jjambo789" for reporting.
1.6 (03-Jun-2022)
- Fixed client not connected errors. Thanks to "ZBzibing" for reporting.
1.5 (20-Apr-2021)
- Fixed compile errors on SourceMod 1.11.
1.4 (10-May-2020)
- Fixed cvar config "sm_trigger.cfg" not being created.
- Fixed previous version updates breaking the Show/Hide trigger beams.
- Thanks to "Tonblader" for reporting.
1.3 (10-May-2020)
- Various changes to tidy up code.
- Various optimizations and fixes.
1.2 (05-May-2018)
- Converted plugin source to the latest syntax utilizing methodmaps. Requires SourceMod 1.8 or newer.
1.1y (05-Sep-2016)
- Update by "YoNer":
- Added code that parses the command and replaces {me} with the clients ID.
- This makes server commands execute commands on the player that activated the trigger.
1.1 (25-Aug-2013)
- Added command "sm_trigger_dupe" to create a trigger where you are and take the settings from another trigger.
- Doubled the maximum string length for commands (to 128 chars).
- Fixed the plugin not loading trigger boxes in Team Fortress 2.
1.0 (20-Aug-2013)
- Initial release.
======================================================================================*/
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#define CVAR_FLAGS FCVAR_NOTIFY
#define CHAT_TAG "\x03[Trigger Commands] \x05"
#define CONFIG_DATA "data/sm_trigger.cfg"
#define MAX_ENTITIES 64
#define CMD_MAX_LENGTH 512
#define MAX_TEAM_LENGTH 32
#define BEAM_TIME 0.3
#define REFIRE_COUNT 1
#define REFIRE_TIME 3.0
#define DELAY_TIME 0.0
#define FIRE_CHANCE 100
int g_iTeamOne = 2;
int g_iTeamTwo = 3;
char g_sTeamOne[MAX_TEAM_LENGTH] = "1";
char g_sTeamTwo[MAX_TEAM_LENGTH] = "2";
Handle g_hTimerBeam;
ConVar g_hCvarAllow, g_hCvarBeam, g_hCvarColor, g_hCvarHalo, g_hCvarModel, g_hCvarRefire;
Menu g_hMenuAll, g_hMenuAuth, g_hMenuBExec, g_hMenuBots, g_hMenuChance, g_hMenuDelay, g_hMenuEdit, g_hMenuExec, g_hMenuLeave, g_hMenuTrig, g_hMenuPos, g_hMenuRefire, g_hMenuTeam, g_hMenuTime, g_hMenuType, g_hMenuVMaxs, g_hMenuVMins;
int g_iColors[4], g_iCvarRefire, g_iEngine, g_iHaloMaterial, g_iLaserMaterial, g_iPlayerSpawn, g_iRoundStart, g_iSelectedTrig;
bool g_bLateLoad, g_bCvarAllow, g_bLoaded;
Handle g_hTimerEnable[MAX_ENTITIES];
int g_iChance[MAX_ENTITIES], g_iCmdData[MAX_ENTITIES], g_iCmdTrig[MAX_ENTITIES], g_iInside[2049][MAXPLAYERS+1], g_iMenuEdit[MAXPLAYERS+1], g_iMenuSelected[MAXPLAYERS+1], g_iRefirePlayer[MAX_ENTITIES][MAXPLAYERS+1], g_iRefireCount[MAX_ENTITIES], g_iTriggers[MAX_ENTITIES];
bool g_bStopEnd[MAX_ENTITIES];
char g_sCommand[MAX_ENTITIES][CMD_MAX_LENGTH], g_sMaterialBeam[PLATFORM_MAX_PATH], g_sMaterialHalo[PLATFORM_MAX_PATH], g_sModelBox[PLATFORM_MAX_PATH];
float g_fDelayTime[MAX_ENTITIES], g_fRefireTime[MAX_ENTITIES];
ArrayList g_hDelayedTimers;
enum
{
ENGINE_ANY,
ENGINE_CSGO,
ENGINE_CSS,
ENGINE_L4D,
ENGINE_L4D2,
ENGINE_TF2,
ENGINE_DODS,
ENGINE_HL2MP,
ENGINE_INS,
ENGINE_ZPS,
ENGINE_AOC,
ENGINE_DM,
ENGINE_FF,
ENGINE_GES,
ENGINE_HID,
ENGINE_NTS,
ENGINE_ND,
ENGINE_STLS
}
enum
{
ALLOW_TEAM_1 = (1 << 0),
ALLOW_TEAM_2 = (1 << 1),
ALLOW_TEAMS = (1 << 2),
ALLOW_ALIVE = (1 << 3),
ALLOW_DEAD = (1 << 4),
ALLOW_SPEC = (1 << 5),
ALLOW_ALL = (1 << 6),
ALLOW_BOTS = (1 << 7),
ALLOW_REAL = (1 << 8),
EXEC_CLIENT = (1 << 9),
EXEC_ALL = (1 << 10),
EXEC_TEAM_1 = (1 << 11),
EXEC_TEAM_2 = (1 << 12),
EXEC_TEAMS = (1 << 13),
EXEC_ALIVE = (1 << 14),
EXEC_DEAD = (1 << 15),
EXEC_BOTS = (1 << 16),
EXEC_REAL = (1 << 17),
LEAVE_NO = (1 << 18),
LEAVE_YES = (1 << 19),
COMMAND_SERVER = (1 << 20),
COMMAND_CLIENT = (1 << 21),
COMMAND_FAKE = (1 << 22),
FLAGS_ANY = (1 << 23),
FLAGS_ADMIN = (1 << 24),
FLAGS_CHEAT = (1 << 25),
FLAGS_ADMINCHEAT = (1 << 26),
ALL_TRIGGER_ALIVE = (1 << 27),
ALL_TRIGGER_T1 = (1 << 28),
ALL_TRIGGER_T2 = (1 << 29)
}
enum
{
TRIGGER_TEAM = (1 << 0),
TRIGGER_DEATH = (1 << 1),
TRIGGER_SPAWN = (1 << 2),
TRIGGER_CONNECT = (1 << 3),
TRIGGER_DISCON = (1 << 4)
}
// ====================================================================================================
// PLUGIN INFO / START / END
// ====================================================================================================
public Plugin myinfo =
{
name = "[ANY] Trigger Multiple Commands",
author = "SilverShot, mod by YoNer",
description = "Create trigger_multiple boxes which execute commands when entered by players.",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=224121"
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
g_bLateLoad = late;
char sGameName[16];
GetGameFolderName(sGameName, sizeof(sGameName));
if( strcmp(sGameName, "csgo", false) == 0 ) g_iEngine = ENGINE_CSGO;
else if( strcmp(sGameName, "cstrike", false) == 0 ) g_iEngine = ENGINE_CSS;
else if( strcmp(sGameName, "left4dead", false) == 0 ) g_iEngine = ENGINE_L4D;
else if( strcmp(sGameName, "left4dead2", false) == 0 ) g_iEngine = ENGINE_L4D2;
else if( strcmp(sGameName, "tf", false) == 0 ) g_iEngine = ENGINE_TF2;
else if( strcmp(sGameName, "dod", false) == 0 ) g_iEngine = ENGINE_DODS;
else if( strcmp(sGameName, "hl2mp", false) == 0 ) g_iEngine = ENGINE_HL2MP;
else if( strncmp(sGameName, "ins", 3, false) == 0 ) g_iEngine = ENGINE_INS;
else if( strcmp(sGameName, "zps", false) == 0 ) g_iEngine = ENGINE_ZPS;
else if( strcmp(sGameName, "aoc", false) == 0 ) g_iEngine = ENGINE_AOC;
else if( strcmp(sGameName, "mmdarkmessiah", false) == 0 ) g_iEngine = ENGINE_DM;
else if( strcmp(sGameName, "ff", false) == 0 ) g_iEngine = ENGINE_FF;
else if( strcmp(sGameName, "gesource", false) == 0 ) g_iEngine = ENGINE_GES;
else if( strcmp(sGameName, "hidden", false) == 0 ) g_iEngine = ENGINE_HID;
else if( strcmp(sGameName, "nts", false) == 0 ) g_iEngine = ENGINE_NTS;
else if( strcmp(sGameName, "nucleardawn", false) == 0 ) g_iEngine = ENGINE_ND;
else if( strcmp(sGameName, "sgtls", false) == 0 ) g_iEngine = ENGINE_STLS;
/* Too much missing to convert yet
g_iEngine = ENGINE_ANY;
EngineVersion test = GetEngineVersion();
switch( test )
{
case (Engine_CSGO): g_iEngine = ENGINE_CSGO;
case (Engine_CSS): g_iEngine = ENGINE_CSS;
case (Engine_Left4Dead): g_iEngine = ENGINE_L4D;
case (Engine_Left4Dead2): g_iEngine = ENGINE_L4D2;
case (Engine_TF2): g_iEngine = ENGINE_TF2;
case (Engine_DODS): g_iEngine = ENGINE_DODS;
case (Engine_HL2DM): g_iEngine = ENGINE_HL2MP;
case (Engine_Insurgency): g_iEngine = ENGINE_INS;
// case (Engine_Z): g_iEngine = ENGINE_ZPS;
// case (Engine_): g_iEngine = ENGINE_AOC;
case (Engine_DarkMessiah): g_iEngine = ENGINE_DM;
// case (Engine_): g_iEngine = ENGINE_FF;
// case (): g_iEngine = ENGINE_GES;
// case (Engine_): g_iEngine = ENGINE_HID;
// case (Engine_): g_iEngine = ENGINE_NTS;
case (Engine_NuclearDawn): g_iEngine = ENGINE_ND;
// case (Engine_): g_iEngine = ENGINE_STLS;
}
// */
return APLRes_Success;
}
public void OnPluginStart()
{
// COMMANDS
#if DEBUG_LOGGING
RegAdminCmd("sm_trigger_bug", CmdTriggerBug, ADMFLAG_ROOT, "Reports to log that a bug occurred.");
#endif
RegAdminCmd("sm_trigger", CmdTriggerMenu, ADMFLAG_ROOT, "Displays a menu with options to edit and position triggers.");
RegAdminCmd("sm_trigger_add", CmdTriggerAdd, ADMFLAG_ROOT, "Add a command to the currently selected trigger. Usage: sm_trigger_add <command>");
RegAdminCmd("sm_trigger_dupe", CmdTriggerDupe, ADMFLAG_ROOT, "Create a trigger where you are standing and duplicate the settings from another trigger. Optional: [index] to duplicate specified trigger index.");
RegAdminCmd("sm_trigger_flags", CmdTriggerFlags, ADMFLAG_ROOT, "Usage: sm_trigger_flags <flags>. Displays the bit sum flags (from data config), eg: sm_trigger_flags 17039624");
RegAdminCmd("sm_trigger_reload", CmdTriggerReload, ADMFLAG_ROOT, "Resets the plugin, removing all triggers and reloading the maps data config.");
// CVARS
g_hCvarAllow = CreateConVar("sm_trigger_allow", "1", "0=Plugin off, 1=Plugin on.", CVAR_FLAGS);
g_hCvarColor = CreateConVar("sm_trigger_color", "255 0 0", "Color of the laser box when displaying the trigger. Three values between 0-255 separated by spaces. RGB Color255 - Red Green Blue.", CVAR_FLAGS);
g_hCvarBeam = CreateConVar("sm_trigger_mat_beam", "materials/sprites/laserbeam.vmt", "Used for the laser beam to display Trigger Boxes.", CVAR_FLAGS);
g_hCvarHalo = CreateConVar("sm_trigger_mat_halo", "materials/sprites/halo01.vmt", "Used for the laser beam to display Trigger Boxes.", CVAR_FLAGS);
g_hCvarModel = CreateConVar("sm_trigger_model", "models/props/cs_militia/silo_01.mdl", "The model to use for the bounding box, the larger the better, will be invisible and is used as the maximum size for a trigger box.", CVAR_FLAGS);
g_hCvarRefire = CreateConVar("sm_trigger_refire", "0", "How does the Activate Chance affect the Refire Count when the chance fails to activate? 0=Do not add to the Refire Count. 1=Add to the Refire Count on Chance fail.", CVAR_FLAGS);
AutoExecConfig(true, "sm_trigger");
CreateConVar("sm_trigger_version", PLUGIN_VERSION, "Trigger Multiple Commands plugin version.", FCVAR_NOTIFY|FCVAR_DONTRECORD);
g_hCvarAllow.AddChangeHook(ConVarChanged_Allow);
g_hCvarColor.AddChangeHook(ConVarChanged_Cvars);
g_hCvarModel.AddChangeHook(ConVarChanged_Cvars);
g_hCvarBeam.AddChangeHook(ConVarChanged_Cvars);
g_hCvarHalo.AddChangeHook(ConVarChanged_Cvars);
g_hCvarRefire.AddChangeHook(ConVarChanged_Cvars);
g_hDelayedTimers = new ArrayList();
char sTemp[64];
// Menu team names
switch( g_iEngine )
{
case ENGINE_CSGO, ENGINE_CSS:
{
g_sTeamOne = "Counter Terrorist";
g_sTeamTwo = "Terrorist";
}
case ENGINE_L4D, ENGINE_L4D2:
{
g_sTeamOne = "Survivor";
g_sTeamTwo = "Infected";
}
case ENGINE_TF2, ENGINE_FF:
{
g_sTeamOne = "Blu";
g_sTeamTwo = "Red";
}
case ENGINE_DODS:
{
g_sTeamOne = "Allies";
g_sTeamTwo = "Axis";
}
case ENGINE_HL2MP:
{
g_sTeamOne = "Rebels";
g_sTeamTwo = "Combine";
}
case ENGINE_INS:
{
g_sTeamOne = "Marines";
g_sTeamTwo = "Insurgents";
}
case ENGINE_ZPS:
{
g_sTeamOne = "Survivors";
g_sTeamTwo = "Zombies";
}
case ENGINE_AOC:
{
g_sTeamOne = "Agatha Knights";
g_sTeamTwo = "Mason Order";
}
case ENGINE_DM:
{
g_sTeamOne = "Humans";
g_sTeamTwo = "Undead";
}
case ENGINE_GES:
{
g_sTeamOne = "MI6";
g_sTeamTwo = "Janus";
}
case ENGINE_HID:
{
g_sTeamOne = "Hidden";
g_sTeamTwo = "IRIS";
}
case ENGINE_NTS:
{
g_sTeamOne = "NSF";
g_sTeamTwo = "Jinrai";
}
case ENGINE_ND:
{
g_sTeamOne = "Consortium";
g_sTeamTwo = "Empire";
}
case ENGINE_STLS:
{
g_sTeamOne = "Tauri";
g_sTeamTwo = "Goauld";
}
default:
{
g_sTeamOne = "One";
g_sTeamTwo = "Two";
}
}
// MENUS
g_hMenuEdit = new Menu(EditMenuHandler);
g_hMenuEdit.AddItem("", "Type Of Command To Exec");
g_hMenuEdit.AddItem("", "Command Flags (Admin/Cheat)");
g_hMenuEdit.AddItem("", "Who Can Activate");
g_hMenuEdit.AddItem("", "Required Players");
g_hMenuEdit.AddItem("", "Who Executes The Command");
g_hMenuEdit.AddItem("", "Bots or Players activate");
g_hMenuEdit.AddItem("", "Refire Count");
g_hMenuEdit.AddItem("", "Refire Time");
g_hMenuEdit.AddItem("", "Command Delay");
g_hMenuEdit.AddItem("", "Activate Chance");
g_hMenuEdit.AddItem("", "Leave Box");
g_hMenuEdit.AddItem("", "Trigger Event Options");
g_hMenuEdit.SetTitle("TMC: Edit Options");
g_hMenuEdit.ExitBackButton = true;
g_hMenuType = new Menu(DataMenuHandler);
g_hMenuType.AddItem("", "Server Command (executes the command on the server)");
g_hMenuType.AddItem("", "Client Command (executes the command client side)");
g_hMenuType.AddItem("", "Fake Client Command (executes the command on the server as if the client had sent)");
g_hMenuType.SetTitle("TMC: Command Type\nWhich type of command do you want to execute?");
g_hMenuType.ExitBackButton = true;
g_hMenuAuth = new Menu(DataMenuHandler);
g_hMenuAuth.AddItem("", "Standard");
g_hMenuAuth.AddItem("", "Remove Cheat Flags");
g_hMenuAuth.AddItem("", "Execute as Root Admin");
g_hMenuAuth.AddItem("", "Execute as Root Admin and Remove Cheat Flags");
g_hMenuAuth.SetTitle("TMC: Command Flags\nDo you want to remove the cheat flag and/or give the user Root admin rights when executing the command?");
g_hMenuAuth.ExitBackButton = true;
g_hMenuTeam = new Menu(DataMenuHandler);
g_hMenuTeam.AddItem("", "Alive Players");
Format(sTemp, sizeof(sTemp), "Team %s", g_sTeamOne);
g_hMenuTeam.AddItem("", sTemp);
Format(sTemp, sizeof(sTemp), "Team %s", g_sTeamTwo);
g_hMenuTeam.AddItem("", sTemp);
Format(sTemp, sizeof(sTemp), "Teams: %s + %s", g_sTeamOne, g_sTeamTwo);
g_hMenuTeam.AddItem("", sTemp);
g_hMenuTeam.AddItem("", "Dead Players");
g_hMenuTeam.AddItem("", "Spectators");
g_hMenuTeam.AddItem("", "All Players");
g_hMenuTeam.SetTitle("TMC: Who Activates the Trigger");
g_hMenuTeam.ExitBackButton = true;
g_hMenuAll = new Menu(DataMenuHandler);
g_hMenuAll.AddItem("", "Any alive player (not all)");
Format(sTemp, sizeof(sTemp), "All alive players (Teams: %s + %s)", g_sTeamOne, g_sTeamTwo);
g_hMenuAll.AddItem("", sTemp);
Format(sTemp, sizeof(sTemp), "All alive team %s", g_sTeamOne);
g_hMenuAll.AddItem("", sTemp);
Format(sTemp, sizeof(sTemp), "All alive team %s", g_sTeamTwo);
g_hMenuAll.AddItem("", sTemp);
g_hMenuAll.SetTitle("TMC: Require all players to be present in the trigger?");
g_hMenuAll.ExitBackButton = true;
g_hMenuBots = new Menu(DataMenuHandler);
g_hMenuBots.AddItem("", "All");
g_hMenuBots.AddItem("", "Only Humans");
g_hMenuBots.AddItem("", "Only Bots");
g_hMenuBots.SetTitle("TMC: Who Activates the Trigger");
g_hMenuBots.ExitBackButton = true;
g_hMenuExec = new Menu(DataMenuHandler);
g_hMenuExec.AddItem("", "Activator Only");
g_hMenuExec.AddItem("", "Everyone");
Format(sTemp, sizeof(sTemp), "Team %s", g_sTeamOne);
g_hMenuExec.AddItem("", sTemp);
Format(sTemp, sizeof(sTemp), "Team %s", g_sTeamTwo);
g_hMenuExec.AddItem("", sTemp);
Format(sTemp, sizeof(sTemp), "Teams: %s + %s", g_sTeamOne, g_sTeamTwo);
g_hMenuExec.AddItem("", sTemp);
g_hMenuExec.AddItem("", "Alive Players");
g_hMenuExec.AddItem("", "Dead Players");
g_hMenuExec.SetTitle("TMC: Command Execute\nDo you want the command to run on all players or only the activator?");
g_hMenuExec.ExitBackButton = true;
g_hMenuBExec = new Menu(DataMenuHandler);
g_hMenuBExec.AddItem("", "All");
g_hMenuBExec.AddItem("", "Only Humans");
g_hMenuBExec.AddItem("", "Only Bots");
g_hMenuBExec.SetTitle("TMC: Who To Execute On");
g_hMenuBExec.ExitBackButton = true;
g_hMenuRefire = new Menu(RefireMenuHandler);
g_hMenuRefire.AddItem("0", "Unlimited");
g_hMenuRefire.AddItem("-1", "Once Per Player");
g_hMenuRefire.AddItem("-", "- 1");
g_hMenuRefire.AddItem("+", "+ 1");
g_hMenuRefire.AddItem("1", "1");
g_hMenuRefire.AddItem("2", "2");
g_hMenuRefire.AddItem("3", "3");
g_hMenuRefire.AddItem("4", "4");
g_hMenuRefire.AddItem("5", "5");
g_hMenuRefire.AddItem("10", "10");
g_hMenuRefire.AddItem("15", "15");
g_hMenuRefire.AddItem("20", "20");
g_hMenuRefire.AddItem("25", "25");
g_hMenuRefire.AddItem("30", "30");
g_hMenuRefire.AddItem("50", "50");
g_hMenuRefire.SetTitle("TMC: Refire Count\nHow many times can the trigger be activated");
g_hMenuRefire.ExitBackButton = true;
g_hMenuTime = new Menu(TimeMenuHandler);
g_hMenuTime.AddItem("0.5", "0.5 (minimum)");
g_hMenuTime.AddItem("-", "- 1.0");
g_hMenuTime.AddItem("+", "+ 1.0");
g_hMenuTime.AddItem("1.0", "1.0");
g_hMenuTime.AddItem("1.5", "1.5");
g_hMenuTime.AddItem("2.0", "2.0");
g_hMenuTime.AddItem("5.0", "5.0");
g_hMenuTime.AddItem("10.0", "10.0");
g_hMenuTime.AddItem("15.0", "15.0");
g_hMenuTime.AddItem("20.0", "20.0");
g_hMenuTime.AddItem("25.0", "25.0");
g_hMenuTime.AddItem("30.0", "30.0");
g_hMenuTime.AddItem("45.0", "45.0");
g_hMenuTime.AddItem("60.0", "60.0");
g_hMenuTime.SetTitle("TMC: Refire Time\nHow soon after the trigger is activated to re-enable the trigger");
g_hMenuTime.ExitBackButton = true;
g_hMenuDelay = new Menu(DelayMenuHandler);
g_hMenuDelay.AddItem("0.0", "Instant - No delay");
g_hMenuDelay.AddItem("-", "- 1.0");
g_hMenuDelay.AddItem("+", "+ 1.0");
g_hMenuDelay.AddItem("0.5", "0.5");
g_hMenuDelay.AddItem("1.0", "1.0");
g_hMenuDelay.AddItem("2.0", "2.0");
g_hMenuDelay.AddItem("3.0", "3.0");
g_hMenuDelay.AddItem("5.0", "5.0");
g_hMenuDelay.AddItem("10.0", "10.0");
g_hMenuDelay.AddItem("15.0", "15.0");
g_hMenuDelay.AddItem("20.0", "20.0");
g_hMenuDelay.AddItem("25.0", "25.0");
g_hMenuDelay.AddItem("30.0", "30.0");
g_hMenuDelay.AddItem("45.0", "45.0");
g_hMenuDelay.SetTitle("TMC: Command Delay\nExecute the command instantly after triggering or set delay in seconds");
g_hMenuDelay.ExitBackButton = true;
g_hMenuChance = new Menu(ChanceMenuHandler);
g_hMenuChance.AddItem("100", "Always 100%");
g_hMenuChance.AddItem("95", "95%");
g_hMenuChance.AddItem("90", "90%");
g_hMenuChance.AddItem("80", "80%");
g_hMenuChance.AddItem("75", "75%");
g_hMenuChance.AddItem("50", "50%");
g_hMenuChance.AddItem("30", "30%");
g_hMenuChance.AddItem("25", "25%");
g_hMenuChance.AddItem("20", "20%");
g_hMenuChance.AddItem("15", "15%");
g_hMenuChance.AddItem("10", "10%");
g_hMenuChance.AddItem("5", "5%");
g_hMenuChance.AddItem("3", "3%");
g_hMenuChance.AddItem("1", "1%");
g_hMenuChance.SetTitle("TMC: Activate Chance\nDo you want this trigger to always fire or based on random chance?");
g_hMenuChance.ExitBackButton = true;
g_hMenuLeave = new Menu(DataMenuHandler);
g_hMenuLeave.AddItem("", "Yes");
g_hMenuLeave.AddItem("", "No");
g_hMenuLeave.SetTitle("TMC: Leave Box\nShould clients have to leave the trigger box before they can activate it again?");
g_hMenuLeave.ExitBackButton = true;
g_hMenuTrig = new Menu(DataMenuHandler);
g_hMenuTrig.AddItem("", "SAVE (save selected)");
g_hMenuTrig.AddItem("", "RESET (remove events)");
g_hMenuTrig.AddItem("", "Team change");
g_hMenuTrig.AddItem("", "Player death");
g_hMenuTrig.AddItem("", "Player Spawn");
g_hMenuTrig.AddItem("", "Player connect");
g_hMenuTrig.AddItem("", "Player disconnect");
g_hMenuTrig.SetTitle("TMC: Event Options, select those to include\nWhen should the trigger attempt to execute?\nNote: Will always attempt when someone enters the trigger box");
g_hMenuTrig.ExitBackButton = true;
g_hMenuVMaxs = new Menu(VMaxsMenuHandler);
g_hMenuVMaxs.AddItem("", "10 x 10 x 100");
g_hMenuVMaxs.AddItem("", "25 x 25 x 100");
g_hMenuVMaxs.AddItem("", "50 x 50 x 100");
g_hMenuVMaxs.AddItem("", "100 x 100 x 100");
g_hMenuVMaxs.AddItem("", "150 x 150 x 100");
g_hMenuVMaxs.AddItem("", "200 x 200 x 100");
g_hMenuVMaxs.AddItem("", "250 x 250 x 100");
g_hMenuVMaxs.SetTitle("TMC: VMaxs");
g_hMenuVMaxs.ExitBackButton = true;
g_hMenuVMins = new Menu(VMinsMenuHandler);
g_hMenuVMins.AddItem("", "-10 x -10 x 0");
g_hMenuVMins.AddItem("", "-25 x -25 x 0");
g_hMenuVMins.AddItem("", "-50 x -50 x 0");
g_hMenuVMins.AddItem("", "-100 x -100 x 0");
g_hMenuVMins.AddItem("", "-150 x -150 x 0");
g_hMenuVMins.AddItem("", "-200 x -200 x 0");
g_hMenuVMins.AddItem("", "-250 x -250 x 0");
g_hMenuVMins.SetTitle("TMC: VMins");
g_hMenuVMins.ExitBackButton = true;
g_hMenuPos = new Menu(PosMenuHandler);
g_hMenuPos.AddItem("", "X + 1.0");
g_hMenuPos.AddItem("", "Y + 1.0");
g_hMenuPos.AddItem("", "Z + 1.0");
g_hMenuPos.AddItem("", "X - 1.0");
g_hMenuPos.AddItem("", "Y - 1.0");
g_hMenuPos.AddItem("", "Z - 1.0");
g_hMenuPos.AddItem("", "SAVE");
g_hMenuPos.SetTitle("TMC: Origin");
g_hMenuPos.ExitBackButton = true;
}
public void OnPluginEnd()
{
ResetPlugin();
}
public void OnMapStart()
{
GetCvars();
if( g_sMaterialBeam[0] ) g_iLaserMaterial = PrecacheModel(g_sMaterialBeam);
if( g_sMaterialHalo[0] ) g_iHaloMaterial = PrecacheModel(g_sMaterialHalo);
if( g_sModelBox[0] ) PrecacheModel(g_sModelBox, true);
#if DEBUG_LOGGING
char sMap[64];
GetCurrentMap(sMap, sizeof(sMap));
LogData("===============");
LogData("Map Started: %s", sMap);
LogData("===============");
#endif
}
public void OnMapEnd()
{
ResetPlugin();
#if DEBUG_LOGGING
char sMap[64];
GetCurrentMap(sMap, sizeof(sMap));
LogData("Map Ended: %s", sMap);
#endif
}
public void OnClientPutInServer(int client)
{
RequestFrame(TriggerTest, TRIGGER_CONNECT);
#if DEBUG_LOGGING
LogData("TriggerTest: CONNECT (%d - %N)", client, client && IsClientInGame(client) ? client : 0);
#endif
}
public void OnClientDisconnect(int client)
{
#if DEBUG_LOGGING
int total;
for( int i = 1; i <= MaxClients; i++ )
{
if( IsClientConnected(i) && !IsFakeClient(i) ) total++;
}
LogData("[%d] DISCONNECT. %d (%N)", total, client, IsClientInGame(client) ? client : 0);
#endif
RequestFrame(TriggerTest, TRIGGER_DISCON);
}
#if DEBUG_LOGGING
public void OnClientConnected(int client)
{
int total;
for( int i = 1; i <= MaxClients; i++ )
{
if( IsClientConnected(i) && !IsFakeClient(i) ) total++;
}
LogData("[%d] CONNECT. %d (%N)", total, client, client);
}
#endif
void ResetPlugin()
{
g_iSelectedTrig = 0;
g_iRoundStart = 0;
g_iPlayerSpawn = 0;
g_bLoaded = false;
for( int i = 0; i <= MaxClients; i++ )
{
g_iMenuSelected[i] = 0;
g_iMenuEdit[i] = 0;
}
for( int i = 0; i <= 2048; i++ )
{
for( int x = 0; x <= MaxClients; x++ )
{
g_iInside[i][x] = 0;
}
}
for( int i = 0; i < MAX_ENTITIES; i++ )
{
for( int x = 0; x <= MaxClients; x++ )
{
g_iRefirePlayer[i][x] = 0;
}
g_sCommand[i][0] = 0;
g_bStopEnd[i] = false;
g_iChance[i] = FIRE_CHANCE;
g_iRefireCount[i] = REFIRE_COUNT;
g_fRefireTime[i] = REFIRE_TIME;
g_fDelayTime[i] = DELAY_TIME;
if( IsValidEntRef(g_iTriggers[i]) ) RemoveEntity(g_iTriggers[i]);
g_iTriggers[i] = 0;
delete g_hTimerEnable[i];
}
DeleteTimers();
}
// ====================================================================================================
// 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()
{
GetColor(g_hCvarColor);
g_hCvarModel.GetString(g_sModelBox, sizeof(g_sModelBox));
g_hCvarBeam.GetString(g_sMaterialBeam, sizeof(g_sMaterialBeam));
g_hCvarHalo.GetString(g_sMaterialHalo, sizeof(g_sMaterialHalo));
g_iCvarRefire = g_hCvarRefire.IntValue;
}
void GetColor(ConVar hCvar)
{
char sTemp[12];
hCvar.GetString(sTemp, sizeof(sTemp));
g_iColors[0] = 255;
g_iColors[1] = 255;
g_iColors[2] = 255;
g_iColors[3] = 255;
if( sTemp[0] == 0 )
return;
char sColors[3][4];
int color = ExplodeString(sTemp, " ", sColors, sizeof(sColors), sizeof(sColors[]));
if( color != 3 )
return;
g_iColors[0] = StringToInt(sColors[0]);
g_iColors[1] = StringToInt(sColors[1]);
g_iColors[2] = StringToInt(sColors[2]);
}
void IsAllowed()
{
bool bCvarAllow = g_hCvarAllow.BoolValue;
GetCvars();
if( g_bCvarAllow == false && bCvarAllow == true )
{
g_bCvarAllow = true;
EventHookMode flags;
#if !DEBUG_LOGGING
flags = EventHookMode_PostNoCopy;
#endif
HookEvent("player_spawn", Event_PlayerSpawn, flags);
HookEvent("player_death", Event_PlayerDeath, flags);
HookEvent("player_team", Event_PlayerTeam, flags);
if( g_iEngine == ENGINE_TF2 )
{
HookEvent("teamplay_round_start", Event_RoundStart, flags);
HookEvent("stats_resetround", Event_RoundEnd, flags);
HookEvent("teamplay_round_win", Event_RoundEnd, flags);
HookEvent("teamplay_win_panel", Event_RoundEnd, flags);
} else {
HookEvent("round_start", Event_RoundStart, flags);
HookEvent("round_end", Event_RoundEnd, flags);
}
LoadDataConfig();
}
else if( g_bCvarAllow == true && bCvarAllow == false )
{
ResetPlugin();
g_bCvarAllow = false;
EventHookMode flags;
#if !DEBUG_LOGGING
flags = EventHookMode_PostNoCopy;
#endif
UnhookEvent("player_spawn", Event_PlayerSpawn, flags);
UnhookEvent("player_death", Event_PlayerDeath, flags);
UnhookEvent("player_team", Event_PlayerTeam, flags);
if( g_iEngine == ENGINE_TF2 )
{
UnhookEvent("teamplay_round_start", Event_RoundStart, flags);
UnhookEvent("stats_resetround", Event_RoundEnd, flags);
UnhookEvent("teamplay_round_win", Event_RoundEnd, flags);
UnhookEvent("teamplay_win_panel", Event_RoundEnd, flags);
} else {
UnhookEvent("round_start", Event_RoundStart, flags);
UnhookEvent("round_end", Event_RoundEnd, flags);
}
}
}
void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
ResetPlugin();
}
void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
RequestFrame(TriggerTest, TRIGGER_DEATH);
#if DEBUG_LOGGING
int client = GetClientOfUserId(event.GetInt("userid"));
LogData("TriggerTest: DEATH (%d - %N)", client, client && IsClientInGame(client) ? client : 0);
#endif
}
void Event_PlayerTeam(Event event, const char[] name, bool dontBroadcast)
{
RequestFrame(TriggerTest, TRIGGER_TEAM);
#if DEBUG_LOGGING
int client = GetClientOfUserId(event.GetInt("userid"));
LogData("TriggerTest: TEAM (%d - %N)", client, client && IsClientInGame(client) ? client : 0);
#endif
}
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;
RequestFrame(TriggerTest, TRIGGER_SPAWN);
#if DEBUG_LOGGING
int client = GetClientOfUserId(event.GetInt("userid"));
LogData("TriggerTest: SPAWN (%d - %N)", client, client && IsClientInGame(client) ? client : 0);
#endif
}
Action TimerStart(Handle timer)
{
LoadDataConfig();
return Plugin_Continue;
}
// ====================================================================================================
// LOAD
// ====================================================================================================
void LoadDataConfig()
{
if( g_bLoaded == true ) return;
g_bLoaded = true;
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, sizeof(sPath), CONFIG_DATA);
if( !FileExists(sPath) ) return;
KeyValues hFile = new KeyValues("triggers");
hFile.SetEscapeSequences(true);
hFile.ImportFromFile(sPath);
char sMap[64];
GetCurrentMap(sMap, sizeof(sMap));
if( !hFile.JumpToKey(sMap) )
{
delete hFile;
return;
}
char sTemp[4];
float vPos[3], vMax[3], vMin[3];
for( int i = 0; i < MAX_ENTITIES; i++ )
{
IntToString(i+1, sTemp, sizeof(sTemp));
if( hFile.JumpToKey(sTemp, false) )
{
// TRIGGER BOXES
hFile.GetVector("vpos", vPos);
if( vPos[0] != 0.0 && vPos[1] != 0.0 && vPos[2] != 0.0 )
{
hFile.GetVector("vmin", vMin);
hFile.GetVector("vmax", vMax);
g_iChance[i] = hFile.GetNum("chance", FIRE_CHANCE);
g_iRefireCount[i] = hFile.GetNum("refire_count", REFIRE_COUNT);
g_fRefireTime[i] = hFile.GetFloat("refire_time", REFIRE_TIME);
g_fDelayTime[i] = hFile.GetFloat("delay_time", DELAY_TIME);
hFile.GetString("command", g_sCommand[i], CMD_MAX_LENGTH);
g_iCmdData[i] = hFile.GetNum("data", 1);
g_iCmdTrig[i] = hFile.GetNum("trigger", 0);
if( g_iCmdData[i] & LEAVE_NO != LEAVE_NO && g_iCmdData[i] & LEAVE_YES != LEAVE_YES )
{
g_iCmdData[i] = g_iCmdData[i] | LEAVE_YES;
}
CreateTriggerMultiple(i, vPos, vMax, vMin, true);
#if DEBUG_LOGGING
LogData("Created trigger: %d [%s]", i, g_sCommand[i]);
#endif
}
hFile.GoBack();
}
}
delete hFile;
}
// ====================================================================================================
// COMMAND - RELOAD
// ====================================================================================================
Action CmdTriggerReload(int client, int args)
{
g_bCvarAllow = false;
ResetPlugin();
GetCvars();
IsAllowed();
if( client ) PrintToChat(client, "%sPlugin reset.", CHAT_TAG);
else PrintToConsole(client, "[Trigger Commands] Plugin reset.");
return Plugin_Handled;
}
// ====================================================================================================
// COMMAND - FLAGS
// ====================================================================================================
Action CmdTriggerDupe(int client, int args)
{
if( client == 0 )
{
PrintToConsole(client, "[Trigger Commands] Command can only be used %s", IsDedicatedServer() ? "in game on a dedicated server." : "in chat on a Listen server.");
return Plugin_Handled;
}
if( args == 1 )
{
char temp[8];
GetCmdArg(1, temp, sizeof(temp));
int index = StringToInt(temp) - 1;
if( IsValidEntRef(g_iTriggers[index]) == true )
{
DupeTrigger(client, index);
ShowMainMenu(client);
}
else
{
PrintToChat(client, "%sInvalid trigger index '%d' to dupe.", CHAT_TAG, index + 1);
ShowMenuTrigList(client, 7);
}
}
else
{
ShowMenuTrigList(client, 7);
}
return Plugin_Handled;
}
// ====================================================================================================
// COMMAND - FLAGS