-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathpugsetup.sp
2239 lines (1932 loc) · 72.4 KB
/
pugsetup.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
#include <clientprefs>
#include <cstrike>
#include <sdktools>
#include <sourcemod>
#include "include/logdebug.inc"
#include "include/pugsetup.inc"
#include "include/restorecvars.inc"
#include "pugsetup/util.sp"
#undef REQUIRE_EXTENSIONS
#include <SteamWorks>
#undef REQUIRE_PLUGIN
#include "include/updater.inc"
#define UPDATE_URL "http://dl.whiffcity.com/plugins/pugsetup/pugsetup.txt"
#define ALIAS_LENGTH 64
#define COMMAND_LENGTH 64
#define LIVE_TIMER_INTERVAL 0.3
#pragma semicolon 1
#pragma newdecls required
/***********************
* *
* Global variables *
* *
***********************/
/** ConVar handles **/
ConVar g_AdminFlagCvar;
ConVar g_AimMapListCvar;
ConVar g_AllowCustomReadyMessageCvar;
ConVar g_AnnounceCountdownCvar;
ConVar g_AutoRandomizeCaptainsCvar;
ConVar g_AutoSetupCvar;
ConVar g_AutoUpdateCvar;
ConVar g_CvarVersionCvar;
ConVar g_DemoNameFormatCvar;
ConVar g_DemoTimeFormatCvar;
ConVar g_DisplayMapVotesCvar;
ConVar g_DoVoteForKnifeRoundDecisionCvar;
ConVar g_EchoReadyMessagesCvar;
ConVar g_ExcludedMaps;
ConVar g_ExcludeSpectatorsCvar;
ConVar g_ExecDefaultConfigCvar;
ConVar g_ForceDefaultsCvar;
ConVar g_InstantRunoffVotingCvar;
ConVar g_KnifeConfigCvar;
ConVar g_LiveCfgCvar;
ConVar g_MapListCvar;
ConVar g_MapVoteTimeCvar;
ConVar g_MaxTeamSizeCvar;
ConVar g_MessagePrefixCvar;
ConVar g_MutualUnpauseCvar;
ConVar g_PausingEnabledCvar;
ConVar g_PostGameCfgCvar;
ConVar g_QuickRestartsCvar;
ConVar g_RandomizeMapOrderCvar;
ConVar g_RandomOptionInMapVoteCvar;
ConVar g_SetupEnabledCvar;
ConVar g_SnakeCaptainsCvar;
ConVar g_StartDelayCvar;
ConVar g_UseGameWarmupCvar;
ConVar g_WarmupCfgCvar;
ConVar g_WarmupMoneyOnSpawnCvar;
/** Setup menu options **/
bool g_DisplayMapType = true;
bool g_DisplayTeamType = true;
bool g_DisplayAutoLive = true;
bool g_DisplayKnifeRound = true;
bool g_DisplayTeamSize = true;
bool g_DisplayRecordDemo = true;
bool g_DisplayMapChange = false;
bool g_DisplayAimWarmup = true;
bool g_DisplayPlayout = false;
/** Setup info **/
int g_Leader = -1;
ArrayList g_MapList;
ArrayList g_PastMaps;
ArrayList g_AimMapList;
bool g_ForceEnded = false;
/** Specific choices made when setting up **/
int g_PlayersPerTeam = 5;
TeamType g_TeamType = TeamType_Captains;
MapType g_MapType = MapType_Vote;
bool g_RecordGameOption = false;
bool g_DoKnifeRound = false;
bool g_AutoLive = true;
bool g_DoAimWarmup = false;
bool g_DoPlayout = false;
/** Other important variables about the state of the game **/
TeamBalancerFunction g_BalancerFunction = INVALID_FUNCTION;
Handle g_BalancerFunctionPlugin = INVALID_HANDLE;
GameState g_GameState = GameState_None;
bool g_SwitchingMaps = false; // if we're in the middle of a map change
bool g_OnDecidedMap = false; // whether we're on the map that is going to be used
bool g_Recording = true;
char g_DemoFileName[PLATFORM_MAX_PATH];
bool g_LiveTimerRunning = false;
int g_CountDownTicks = 0;
bool g_ForceStartSignal = false;
#define CAPTAIN_COMMAND_HINT_TIME 15
#define START_COMMAND_HINT_TIME 15
#define READY_COMMAND_HINT_TIME 19
int g_LastCaptainHintTime = 0;
int g_LastReadyHintTime = 0;
/** Pause information **/
bool g_ctUnpaused = false;
bool g_tUnpaused = false;
/** Custom ready messages **/
Handle g_ReadyMessageCookie = INVALID_HANDLE;
/** Stuff for workshop map/collection cache **/
char g_DataDir[PLATFORM_MAX_PATH]; // directory to leave cache files in
char g_CacheFile[PLATFORM_MAX_PATH]; // filename of the keyvalue cache file
KeyValues g_WorkshopCache; // keyvalue struct for the cache
/** Chat aliases loaded **/
ArrayList g_ChatAliases;
ArrayList g_ChatAliasesCommands;
ArrayList g_ChatAliasesModes;
/** Permissions **/
StringMap g_PermissionsMap;
ArrayList g_Commands; // just a list of all known pugsetup commands
/** Map-choosing variables **/
ArrayList g_MapVetoed;
ArrayList g_MapVotePool;
/** Data about team selections **/
int g_capt1 = -1;
int g_capt2 = -1;
int g_Teams[MAXPLAYERS + 1];
bool g_Ready[MAXPLAYERS + 1];
bool g_PlayerAtStart[MAXPLAYERS + 1];
/** Clan tag data **/
#define CLANTAG_LENGTH 16
bool g_SavedClanTag[MAXPLAYERS + 1];
char g_ClanTag[MAXPLAYERS + 1][CLANTAG_LENGTH];
/** Knife round data **/
int g_KnifeWinner = -1;
enum KnifeDecision {
KnifeDecision_None,
KnifeDecision_Stay,
KnifeDecision_Swap,
};
KnifeDecision g_KnifeRoundVotes[MAXPLAYERS + 1];
int g_KnifeNumVotesNeeded = 0;
/** Forwards **/
Handle g_OnForceEnd = INVALID_HANDLE;
Handle g_hOnGoingLive = INVALID_HANDLE;
Handle g_hOnHelpCommand = INVALID_HANDLE;
Handle g_hOnKnifeRoundDecision = INVALID_HANDLE;
Handle g_hOnLive = INVALID_HANDLE;
Handle g_hOnLiveCfg = INVALID_HANDLE;
Handle g_hOnLiveCheck = INVALID_HANDLE;
Handle g_hOnMatchOver = INVALID_HANDLE;
Handle g_hOnNotPicked = INVALID_HANDLE;
Handle g_hOnPermissionCheck = INVALID_HANDLE;
Handle g_hOnPlayerAddedToCaptainMenu = INVALID_HANDLE;
Handle g_hOnPostGameCfg = INVALID_HANDLE;
Handle g_hOnReady = INVALID_HANDLE;
Handle g_hOnReadyToStart = INVALID_HANDLE;
Handle g_hOnSetup = INVALID_HANDLE;
Handle g_hOnSetupMenuOpen = INVALID_HANDLE;
Handle g_hOnSetupMenuSelect = INVALID_HANDLE;
Handle g_hOnStartRecording = INVALID_HANDLE;
Handle g_hOnStateChange = INVALID_HANDLE;
Handle g_hOnUnready = INVALID_HANDLE;
Handle g_hOnWarmupCfg = INVALID_HANDLE;
#include "pugsetup/captainpickmenus.sp"
#include "pugsetup/configs.sp"
#include "pugsetup/consolecommands.sp"
#include "pugsetup/instantrunoffvote.sp"
#include "pugsetup/kniferounds.sp"
#include "pugsetup/leadermenus.sp"
#include "pugsetup/liveon3.sp"
#include "pugsetup/maps.sp"
#include "pugsetup/mapveto.sp"
#include "pugsetup/mapvote.sp"
#include "pugsetup/natives.sp"
#include "pugsetup/setupmenus.sp"
#include "pugsetup/steamapi.sp"
/***********************
* *
* Sourcemod forwards *
* *
***********************/
// clang-format off
public Plugin myinfo = {
name = "CS:GO PugSetup",
author = "splewis",
description = "Tools for setting up pugs/10mans",
version = PLUGIN_VERSION,
url = "https://github.com/splewis/csgo-pug-setup"
};
// clang-format on
public void OnPluginStart() {
InitDebugLog(DEBUG_CVAR, "pugsetup");
LoadTranslations("common.phrases");
LoadTranslations("core.phrases");
LoadTranslations("pugsetup.phrases");
/** ConVars **/
g_AdminFlagCvar = CreateConVar(
"sm_pugsetup_admin_flag", "b",
"Admin flag to mark players as having elevated permissions - e.g. can always pause,setup,end the game, etc.");
g_AimMapListCvar = CreateConVar(
"sm_pugsetup_maplist_aim_maps", "aim_maps.txt",
"If using aim map warmup, the maplist file in addons/sourcemod/configs/pugsetup to use. You may also use a workshop collection ID instead of a maplist if you have the SteamWorks extension installed.");
g_AllowCustomReadyMessageCvar =
CreateConVar("sm_pugsetup_allow_custom_ready_messages", "1",
"Whether users can set custom ready messages saved via a clientprefs cookie");
g_AnnounceCountdownCvar =
CreateConVar("sm_pugsetup_announce_countdown_timer", "1",
"Whether to announce how long the countdown has left before the lo3 begins.");
g_AutoRandomizeCaptainsCvar = CreateConVar(
"sm_pugsetup_auto_randomize_captains", "0",
"When games are using captains, should they be automatically randomized once? Note you can still manually set them or use .rand/!rand to redo the randomization.");
g_AutoSetupCvar =
CreateConVar("sm_pugsetup_autosetup", "0",
"Whether a pug is automatically setup using the default setup options or not.");
g_AutoUpdateCvar = CreateConVar(
"sm_pugsetup_autoupdate", "1",
"Whether the plugin may (if the \"Updater\" plugin is loaded) automatically update.");
g_DemoNameFormatCvar = CreateConVar(
"sm_pugsetup_demo_name_format", "pug_{TIME}_{MAP}",
"Naming scheme for demos. You may use {MAP}, {TIME}, and {TEAMSIZE}. Make sure there are no spaces or colons in this.");
g_DemoTimeFormatCvar = CreateConVar(
"sm_pugsetup_time_format", "%Y-%m-%d_%H%M",
"Time format to use when creating demo file names. Don't tweak this unless you know what you're doing! Avoid using spaces or colons.");
g_DisplayMapVotesCvar =
CreateConVar("sm_pugsetup_display_map_votes", "1",
"Whether votes cast by players will be displayed to everyone");
g_DoVoteForKnifeRoundDecisionCvar = CreateConVar(
"sm_pugsetup_vote_for_knife_round_decision", "0",
"If 0, the first player to type .stay/.swap/.t/.ct will decide the round round winner decision - otherwise a majority vote will be used");
g_EchoReadyMessagesCvar = CreateConVar("sm_pugsetup_echo_ready_messages", "1",
"Whether to print to chat when clients ready/unready.");
g_ExcludedMaps = CreateConVar(
"sm_pugsetup_excluded_maps", "0",
"Number of past maps to exclude from map votes. Setting this to 0 disables this feature.");
g_ExcludeSpectatorsCvar = CreateConVar(
"sm_pugsetup_exclude_spectators", "0",
"Whether to exclude spectators in the ready-up counts. Setting this to 1 will exclude specators from being selected by captains as well.");
g_ExecDefaultConfigCvar = CreateConVar(
"sm_pugsetup_exec_default_game_config", "1",
"Whether gamemode_competitive (the matchmaking config) should be executed before the live config.");
g_ForceDefaultsCvar = CreateConVar(
"sm_pugsetup_force_defaults", "0",
"Whether the default setup options are forced as the setup options (note that admins can override them still).");
g_InstantRunoffVotingCvar = CreateConVar(
"sm_pugsetup_instant_runoff_voting", "1",
"If set, map votes will run instant-runoff style where each client selects their top 3 maps in preference order.");
g_KnifeConfigCvar = CreateConVar(
"sm_pugsetup_knife_cfg", "sourcemod/pugsetup/knife.cfg",
"Config to execute when the knife round begins. CVars set in this file are saved before execution, and reverted back to their pre-knife-config values when the game goes live, before executing the live.cfg.");
g_LiveCfgCvar = CreateConVar("sm_pugsetup_live_cfg", "sourcemod/pugsetup/live.cfg",
"Config to execute when the game goes live");
g_MapListCvar = CreateConVar(
"sm_pugsetup_maplist", "maps.txt",
"Maplist file in addons/sourcemod/configs/pugsetup to use. You may also use a workshop collection ID instead of a maplist if you have the SteamWorks extension installed.");
g_MapVoteTimeCvar =
CreateConVar("sm_pugsetup_mapvote_time", "25",
"How long the map vote should last if using map-votes.", _, true, 10.0);
g_MaxTeamSizeCvar =
CreateConVar("sm_pugsetup_max_team_size", "5",
"Maximum size of a team when selecting team sizes.", _, true, 2.0);
g_MessagePrefixCvar = CreateConVar(
"sm_pugsetup_message_prefix", "[{YELLOW}PugSetup{NORMAL}]",
"The tag applied before plugin messages. If you want no tag, you can set an empty string here. Note that beginning the string with a color will not render that color - you can workaround with a space or another character first.");
g_MutualUnpauseCvar = CreateConVar(
"sm_pugsetup_mutual_unpausing", "1",
"Whether an unpause command requires someone from both teams to fully unpause the match. Note that this forces the pause/unpause commands to be unrestricted (so anyone can use them).");
g_PausingEnabledCvar =
CreateConVar("sm_pugsetup_pausing_enabled", "1", "Whether pausing is allowed.");
g_PostGameCfgCvar =
CreateConVar("sm_pugsetup_postgame_cfg", "sourcemod/pugsetup/warmup.cfg",
"Config to execute after games finish; should be in the csgo/cfg directory.");
g_QuickRestartsCvar = CreateConVar(
"sm_pugsetup_quick_restarts", "0",
"If set to 1, going live won't restart 3 times and will just do a single restart.");
g_RandomizeMapOrderCvar =
CreateConVar("sm_pugsetup_randomize_maps", "1",
"When maps are shown in the map vote/veto, whether their order is randomized.");
g_RandomOptionInMapVoteCvar =
CreateConVar("sm_pugsetup_random_map_vote_option", "1",
"Whether option 1 in a mapvote is the random map choice.");
g_SetupEnabledCvar = CreateConVar("sm_pugsetup_setup_enabled", "1",
"Whether the sm_setup and sm_10man commands are enabled");
g_SnakeCaptainsCvar = CreateConVar(
"sm_pugsetup_snake_captain_picks", "0",
"If set to 0: captains pick players in a ABABABAB order. If set to 1, in a ABBAABBA order. If set to 2, in a ABBABABA order. If set to 3, in a ABBABAAB order.");
g_StartDelayCvar =
CreateConVar("sm_pugsetup_start_delay", "5",
"How many seconds of a countdown phase right before the lo3 process begins.", _,
true, 0.0, true, 60.0);
g_UseGameWarmupCvar = CreateConVar(
"sm_pugsetup_use_game_warmup", "1",
"Whether to use csgo's built-in warmup functionality. The warmup config (sm_pugsetup_warmup_cfg) will be executed regardless of this setting.");
g_WarmupCfgCvar =
CreateConVar("sm_pugsetup_warmup_cfg", "sourcemod/pugsetup/warmup.cfg",
"Config file to run before/after games; should be in the csgo/cfg directory.");
g_WarmupMoneyOnSpawnCvar = CreateConVar(
"sm_pugsetup_money_on_warmup_spawn", "1",
"Whether clients recieve 16,000 dollars when they spawn. It's recommended you use mp_death_drop_gun 0 in your warmup config if you use this.");
/** Create and exec plugin's configuration file **/
AutoExecConfig(true, "pugsetup", "sourcemod/pugsetup");
g_CvarVersionCvar =
CreateConVar("sm_pugsetup_version", PLUGIN_VERSION, "Current pugsetup version",
FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY | FCVAR_DONTRECORD);
g_CvarVersionCvar.SetString(PLUGIN_VERSION);
HookConVarChange(g_MapListCvar, OnMapListChanged);
HookConVarChange(g_AimMapListCvar, OnAimMapListChanged);
/** Commands **/
g_Commands = new ArrayList(COMMAND_LENGTH);
LoadTranslatedAliases();
AddPugSetupCommand("ready", Command_Ready, "Marks the client as ready", Permission_All,
ChatAlias_WhenSetup);
AddPugSetupCommand("notready", Command_NotReady, "Marks the client as not ready", Permission_All,
ChatAlias_WhenSetup);
AddPugSetupCommand("setup", Command_Setup,
"Starts pug setup (.ready, .capt commands become avaliable)", Permission_All);
AddPugSetupCommand("10man", Command_10man,
"Starts 10man setup (alias for .setup with 10 man/gather settings)",
Permission_All);
AddPugSetupCommand("rand", Command_Rand, "Sets random captains", Permission_Captains,
ChatAlias_WhenSetup);
AddPugSetupCommand("pause", Command_Pause, "Pauses the game", Permission_All,
ChatAlias_WhenSetup);
AddPugSetupCommand("unpause", Command_Unpause, "Unpauses the game", Permission_All,
ChatAlias_WhenSetup);
AddPugSetupCommand("endgame", Command_EndGame, "Pre-emptively ends the match", Permission_Leader);
AddPugSetupCommand("forceend", Command_ForceEnd,
"Pre-emptively ends the match, without any confirmation menu",
Permission_Leader);
AddPugSetupCommand("forceready", Command_ForceReady, "Force-readies a player", Permission_Admin,
ChatAlias_WhenSetup);
AddPugSetupCommand("leader", Command_Leader, "Sets the pug leader", Permission_Leader);
AddPugSetupCommand("capt", Command_Capt, "Gives the client a menu to pick captains",
Permission_Leader);
AddPugSetupCommand("stay", Command_Stay,
"Elects to stay on the current team after winning a knife round",
Permission_All, ChatAlias_WhenSetup);
AddPugSetupCommand("swap", Command_Swap,
"Elects to swap the current teams after winning a knife round", Permission_All,
ChatAlias_WhenSetup);
AddPugSetupCommand("t", Command_T, "Elects to start on T side after winning a knife round",
Permission_All, ChatAlias_WhenSetup);
AddPugSetupCommand("ct", Command_Ct, "Elects to start on CT side after winning a knife round",
Permission_All, ChatAlias_WhenSetup);
AddPugSetupCommand("forcestart", Command_ForceStart, "Force starts the game", Permission_Admin,
ChatAlias_WhenSetup);
AddPugSetupCommand("addmap", Command_AddMap, "Adds a map to the current maplist",
Permission_Admin);
AddPugSetupCommand("removemap", Command_RemoveMap, "Removes a map to the current maplist",
Permission_Admin);
AddPugSetupCommand("listpugmaps", Command_ListPugMaps, "Lists the current maplist",
Permission_All);
AddPugSetupCommand("listaimmaps", Command_ListAimMaps, "Lists the current aim maplist",
Permission_All);
AddPugSetupCommand("start", Command_Start, "Starts the game if autolive is disabled",
Permission_Leader, ChatAlias_WhenSetup);
AddPugSetupCommand("addalias", Command_AddAlias,
"Adds a pugsetup alias, and saves it to the chatalias.cfg file",
Permission_Admin);
AddPugSetupCommand("removealias", Command_RemoveAlias, "Removes a pugsetup alias",
Permission_Admin);
AddPugSetupCommand("setdefault", Command_SetDefault, "Sets a default setup option",
Permission_Admin);
AddPugSetupCommand("setdisplay", Command_SetDisplay,
"Sets whether a setup option will be displayed", Permission_Admin);
AddPugSetupCommand("readymessage", Command_ReadyMessage, "Sets your ready message",
Permission_All);
LoadExtraAliases();
RegConsoleCmd("pugstatus", Command_Pugstatus, "Dumps information about the pug game status");
RegConsoleCmd("pugsetup_status", Command_Pugstatus,
"Dumps information about the pug game status");
RegConsoleCmd("pugsetup_permissions", Command_ShowPermissions,
"Dumps pugsetup command permissions");
RegConsoleCmd("pugsetup_chataliases", Command_ShowChatAliases,
"Dumps registered pugsetup chat aliases");
/** Hooks **/
HookEvent("cs_win_panel_match", Event_MatchOver);
HookEvent("round_start", Event_RoundStart);
HookEvent("round_end", Event_RoundEnd);
HookEvent("player_spawn", Event_PlayerSpawn);
HookEvent("server_cvar", Event_CvarChanged, EventHookMode_Pre);
HookEvent("player_connect", Event_PlayerConnect);
HookEvent("player_disconnect", Event_PlayerDisconnect);
g_OnForceEnd = CreateGlobalForward("PugSetup_OnForceEnd", ET_Ignore, Param_Cell);
g_hOnGoingLive = CreateGlobalForward("PugSetup_OnGoingLive", ET_Ignore);
g_hOnHelpCommand = CreateGlobalForward("PugSetup_OnHelpCommand", ET_Ignore, Param_Cell,
Param_Cell, Param_Cell, Param_CellByRef);
g_hOnKnifeRoundDecision =
CreateGlobalForward("PugSetup_OnKnifeRoundDecision", ET_Ignore, Param_Cell);
g_hOnLive = CreateGlobalForward("PugSetup_OnLive", ET_Ignore);
g_hOnLiveCfg = CreateGlobalForward("PugSetup_OnLiveCfgExecuted", ET_Ignore);
g_hOnLiveCheck =
CreateGlobalForward("PugSetup_OnReadyToStartCheck", ET_Ignore, Param_Cell, Param_Cell);
g_hOnMatchOver = CreateGlobalForward("PugSetup_OnMatchOver", ET_Ignore, Param_Cell, Param_String);
g_hOnNotPicked = CreateGlobalForward("PugSetup_OnNotPicked", ET_Ignore, Param_Cell);
g_hOnPermissionCheck = CreateGlobalForward("PugSetup_OnPermissionCheck", ET_Ignore, Param_Cell,
Param_String, Param_Cell, Param_CellByRef);
g_hOnPlayerAddedToCaptainMenu =
CreateGlobalForward("PugSetup_OnPlayerAddedToCaptainMenu", ET_Ignore, Param_Cell, Param_Cell,
Param_String, Param_Cell);
g_hOnPostGameCfg = CreateGlobalForward("PugSetup_OnPostGameCfgExecuted", ET_Ignore);
g_hOnReady = CreateGlobalForward("PugSetup_OnReady", ET_Ignore, Param_Cell);
g_hOnReadyToStart = CreateGlobalForward("PugSetup_OnReadyToStart", ET_Ignore);
g_hOnSetup = CreateGlobalForward("PugSetup_OnSetup", ET_Ignore, Param_Cell, Param_Cell,
Param_Cell, Param_Cell);
g_hOnSetupMenuOpen =
CreateGlobalForward("PugSetup_OnSetupMenuOpen", ET_Event, Param_Cell, Param_Cell, Param_Cell);
g_hOnSetupMenuSelect = CreateGlobalForward("PugSetup_OnSetupMenuSelect", ET_Ignore, Param_Cell,
Param_Cell, Param_String, Param_Cell);
g_hOnStartRecording = CreateGlobalForward("PugSetup_OnStartRecording", ET_Ignore, Param_String);
g_hOnStateChange =
CreateGlobalForward("PugSetup_OnGameStateChanged", ET_Ignore, Param_Cell, Param_Cell);
g_hOnUnready = CreateGlobalForward("PugSetup_OnUnready", ET_Ignore, Param_Cell);
g_hOnWarmupCfg = CreateGlobalForward("PugSetup_OnWarmupCfgExecuted", ET_Ignore);
g_ReadyMessageCookie =
RegClientCookie("pugsetup_ready", "Pugsetup ready message", CookieAccess_Protected);
g_LiveTimerRunning = false;
ReadSetupOptions();
g_MapVotePool = new ArrayList(PLATFORM_MAX_PATH);
g_PastMaps = new ArrayList(PLATFORM_MAX_PATH);
// Get workshop cache file setup
BuildPath(Path_SM, g_DataDir, sizeof(g_DataDir), "data/pugsetup");
if (!DirExists(g_DataDir)) {
CreateDirectory(g_DataDir, 511);
}
Format(g_CacheFile, sizeof(g_CacheFile), "%s/cache.cfg", g_DataDir);
/** Updater support **/
if (GetConVarInt(g_AutoUpdateCvar) != 0) {
if (LibraryExists("updater")) {
Updater_AddPlugin(UPDATE_URL);
}
}
}
static void AddPugSetupCommand(const char[] command, ConCmd callback, const char[] description,
Permission p, ChatAliasMode mode = ChatAlias_Always) {
char smCommandBuffer[64];
Format(smCommandBuffer, sizeof(smCommandBuffer), "sm_%s", command);
g_Commands.PushString(smCommandBuffer);
RegConsoleCmd(smCommandBuffer, callback, description);
PugSetup_SetPermissions(smCommandBuffer, p);
char dotCommandBuffer[64];
Format(dotCommandBuffer, sizeof(dotCommandBuffer), ".%s", command);
PugSetup_AddChatAlias(dotCommandBuffer, smCommandBuffer, mode);
}
public void OnMapListChanged(ConVar convar, const char[] oldValue, const char[] newValue) {
if (!StrEqual(oldValue, newValue)) {
FillMapList(g_MapListCvar, g_MapList);
}
}
public void OnAimMapListChanged(ConVar convar, const char[] oldValue, const char[] newValue) {
if (!StrEqual(oldValue, newValue)) {
FillMapList(g_AimMapListCvar, g_AimMapList);
}
}
public void OnConfigsExecuted() {
FillMapList(g_MapListCvar, g_MapList);
FillMapList(g_AimMapListCvar, g_AimMapList);
ReadPermissions();
}
public void OnLibraryAdded(const char[] name) {
if (GetConVarInt(g_AutoUpdateCvar) != 0) {
if (LibraryExists("updater")) {
Updater_AddPlugin(UPDATE_URL);
}
}
}
public bool OnClientConnect(int client, char[] rejectmsg, int maxlen) {
g_Ready[client] = false;
g_SavedClanTag[client] = false;
CheckAutoSetup();
return true;
}
public void OnClientDisconnect_Post(int client) {
int numPlayers = 0;
for (int i = 1; i <= MaxClients; i++)
if (IsPlayer(i))
numPlayers++;
if (numPlayers == 0 && !g_SwitchingMaps && g_AutoSetupCvar.IntValue == 0) {
EndMatch(true);
}
}
public void OnMapStart() {
if (g_SwitchingMaps) {
g_SwitchingMaps = false;
}
g_ForceEnded = false;
g_MapVetoed = new ArrayList();
g_Recording = false;
g_LiveTimerRunning = false;
g_ForceStartSignal = false;
// Map init for workshop collection stuff
g_WorkshopCache = new KeyValues("Workshop");
g_WorkshopCache.ImportFromFile(g_CacheFile);
if (g_GameState == GameState_Warmup) {
ExecWarmupConfigs();
if (g_UseGameWarmupCvar.IntValue != 0) {
StartWarmup();
}
StartLiveTimer();
} else {
g_capt1 = -1;
g_capt2 = -1;
g_Leader = -1;
for (int i = 1; i <= MaxClients; i++) {
g_Ready[i] = false;
g_Teams[i] = CS_TEAM_NONE;
}
}
}
public void OnMapEnd() {
CloseHandle(g_MapVetoed);
g_WorkshopCache.Rewind();
g_WorkshopCache.ExportToFile(g_CacheFile);
delete g_WorkshopCache;
}
public bool UsingCaptains() {
return g_TeamType == TeamType_Captains || g_MapType == MapType_Veto;
}
public Action Timer_CheckReady(Handle timer) {
if (g_GameState != GameState_Warmup || !g_LiveTimerRunning) {
g_LiveTimerRunning = false;
return Plugin_Stop;
}
if (g_DoAimWarmup) {
EnsurePausedWarmup();
}
int readyPlayers = 0;
int totalPlayers = 0;
for (int i = 1; i <= MaxClients; i++) {
if (IsPlayer(i)) {
UpdateClanTag(i);
int team = GetClientTeam(i);
if (g_ExcludeSpectatorsCvar.IntValue == 0 || team == CS_TEAM_CT || team == CS_TEAM_T) {
totalPlayers++;
if (g_Ready[i]) {
readyPlayers++;
}
}
}
}
if (totalPlayers >= PugSetup_GetPugMaxPlayers()) {
GiveReadyHints();
}
// beware: scary spaghetti code ahead
if ((readyPlayers == totalPlayers && readyPlayers >= 2 * g_PlayersPerTeam) ||
g_ForceStartSignal) {
g_ForceStartSignal = false;
if (g_OnDecidedMap) {
if (g_TeamType == TeamType_Captains) {
if (IsPlayer(g_capt1) && IsPlayer(g_capt2) && g_capt1 != g_capt2) {
g_LiveTimerRunning = false;
PrintHintTextToAll("%t\n%t", "ReadyStatusPlayers", readyPlayers, totalPlayers,
"ReadyStatusAllReadyPick");
CreateTimer(1.0, StartPicking, _, TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
} else {
StatusHint(readyPlayers, totalPlayers);
}
} else {
g_LiveTimerRunning = false;
if (g_AutoLive) {
PrintHintTextToAll("%t\n%t", "ReadyStatusPlayers", readyPlayers, totalPlayers,
"ReadyStatusAllReady");
} else {
PrintHintTextToAll("%t\n%t", "ReadyStatusPlayers", readyPlayers, totalPlayers,
"ReadyStatusAllReadyWaiting");
}
ReadyToStart();
return Plugin_Stop;
}
} else {
if (g_MapType == MapType_Veto) {
if (IsPlayer(g_capt1) && IsPlayer(g_capt2) && g_capt1 != g_capt2) {
g_LiveTimerRunning = false;
PrintHintTextToAll("%t\n%t", "ReadyStatusPlayers", readyPlayers, totalPlayers,
"ReadyStatusAllReadyVeto");
PugSetup_MessageToAll("%t", "VetoMessage");
CreateTimer(2.0, MapSetup, _, TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
} else {
StatusHint(readyPlayers, totalPlayers);
}
} else {
g_LiveTimerRunning = false;
PrintHintTextToAll("%t\n%t", "ReadyStatusPlayers", readyPlayers, totalPlayers,
"ReadyStatusAllReadyVote");
PugSetup_MessageToAll("%t", "VoteMessage");
CreateTimer(2.0, MapSetup, _, TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
}
} else {
StatusHint(readyPlayers, totalPlayers);
}
Call_StartForward(g_hOnLiveCheck);
Call_PushCell(readyPlayers);
Call_PushCell(totalPlayers);
Call_Finish();
if (g_TeamType == TeamType_Captains && g_AutoRandomizeCaptainsCvar.IntValue != 0 &&
totalPlayers >= PugSetup_GetPugMaxPlayers()) {
// re-randomize captains if they aren't set yet
if (!IsPlayer(g_capt1)) {
g_capt1 = RandomPlayer();
}
while (!IsPlayer(g_capt2) || g_capt1 == g_capt2) {
if (GetRealClientCount() < 2)
break;
g_capt2 = RandomPlayer();
}
}
return Plugin_Continue;
}
public void StatusHint(int readyPlayers, int totalPlayers) {
char rdyCommand[ALIAS_LENGTH];
FindAliasFromCommand("sm_ready", rdyCommand);
bool captainsNeeded = (!g_OnDecidedMap && g_MapType == MapType_Veto) ||
(g_OnDecidedMap && g_TeamType == TeamType_Captains);
if (captainsNeeded) {
for (int i = 1; i <= MaxClients; i++) {
if (IsPlayer(i)) {
GiveCaptainHint(i, readyPlayers, totalPlayers);
}
}
} else {
PrintHintTextToAll("%t", "ReadyStatus", readyPlayers, totalPlayers, rdyCommand);
}
}
static void GiveReadyHints() {
int time = GetTime();
int dt = time - g_LastReadyHintTime;
if (dt >= READY_COMMAND_HINT_TIME) {
g_LastReadyHintTime = time;
char cmd[ALIAS_LENGTH];
FindAliasFromCommand("sm_ready", cmd);
for (int i = 1; i <= MaxClients; i++) {
if (IsPlayer(i) && !PugSetup_IsReady(i) && OnActiveTeam(i)) {
PugSetup_Message(i, "%t", "ReadyCommandHint", cmd);
}
}
}
}
static void GiveCaptainHint(int client, int readyPlayers, int totalPlayers) {
char cap1[MAX_NAME_LENGTH];
char cap2[MAX_NAME_LENGTH];
const int kMaxNameLength = 14;
if (IsPlayer(g_capt1)) {
Format(cap1, sizeof(cap1), "%N", g_capt1);
if (strlen(cap1) > kMaxNameLength) {
strcopy(cap1, kMaxNameLength, cap1);
Format(cap1, sizeof(cap1), "%s...", cap1);
}
} else {
Format(cap1, sizeof(cap1), "%T", "CaptainNotSelected", client);
}
if (IsPlayer(g_capt2)) {
Format(cap2, sizeof(cap2), "%N", g_capt2);
if (strlen(cap2) > kMaxNameLength) {
strcopy(cap2, kMaxNameLength, cap2);
Format(cap2, sizeof(cap2), "%s...", cap2);
}
} else {
Format(cap2, sizeof(cap2), "%T", "CaptainNotSelected", client);
}
PrintHintTextToAll("%t", "ReadyStatusCaptains", readyPlayers, totalPlayers, cap1, cap2);
// if there aren't any captains and we full players, print the hint telling the leader how to set
// captains
if (!IsPlayer(g_capt1) && !IsPlayer(g_capt2) && totalPlayers >= PugSetup_GetPugMaxPlayers()) {
// but only do it at most every CAPTAIN_COMMAND_HINT_TIME seconds so it doesn't get spammed
int time = GetTime();
int dt = time - g_LastCaptainHintTime;
if (dt >= CAPTAIN_COMMAND_HINT_TIME) {
g_LastCaptainHintTime = time;
char cmd[ALIAS_LENGTH];
FindAliasFromCommand("sm_capt", cmd);
PugSetup_MessageToAll("%t", "SetCaptainsHint", PugSetup_GetLeader(), cmd);
}
}
}
/***********************
* *
* Commands *
* *
***********************/
public bool DoPermissionCheck(int client, const char[] command) {
Permission p = PugSetup_GetPermissions(command);
bool result = PugSetup_HasPermissions(client, p);
char cmd[COMMAND_LENGTH];
GetCmdArg(0, cmd, sizeof(cmd));
Call_StartForward(g_hOnPermissionCheck);
Call_PushCell(client);
Call_PushString(cmd);
Call_PushCell(p);
Call_PushCellRef(result);
Call_Finish();
return result;
}
public Action Command_Setup(int client, int args) {
if (g_SetupEnabledCvar.IntValue == 0) {
return Plugin_Handled;
}
if (g_GameState > GameState_Warmup) {
PugSetup_Message(client, "%t", "AlreadyLive");
return Plugin_Handled;
}
bool allowedToSetup = DoPermissionCheck(client, "sm_setup");
if (g_GameState == GameState_None && !allowedToSetup) {
PugSetup_Message(client, "%t", "NoPermission");
return Plugin_Handled;
}
bool allowedToChangeSetup = PugSetup_HasPermissions(client, Permission_Leader);
if (g_GameState == GameState_Warmup && !allowedToChangeSetup) {
PugSetup_GiveSetupMenu(client, true);
return Plugin_Handled;
}
if (IsPlayer(client)) {
g_Leader = client;
}
if (client == 0) {
// if we did the setup command from the console just use the default settings
ReadSetupOptions();
PugSetup_SetupGame(g_TeamType, g_MapType, g_PlayersPerTeam, g_RecordGameOption, g_DoKnifeRound,
g_AutoLive);
} else {
PugSetup_GiveSetupMenu(client);
}
return Plugin_Handled;
}
public Action Command_10man(int client, int args) {
if (g_SetupEnabledCvar.IntValue == 0) {
return Plugin_Handled;
}
if (g_GameState > GameState_Warmup) {
PugSetup_Message(client, "%t", "AlreadyLive");
return Plugin_Handled;
}
bool allowedToSetup = DoPermissionCheck(client, "sm_10man");
if (g_GameState == GameState_None && !allowedToSetup) {
PugSetup_Message(client, "%t", "NoPermission");
return Plugin_Handled;
}
bool allowedToChangeSetup = PugSetup_HasPermissions(client, Permission_Leader);
if (g_GameState == GameState_Warmup && !allowedToChangeSetup) {
PugSetup_GiveSetupMenu(client, true);
return Plugin_Handled;
}
if (IsPlayer(client)) {
g_Leader = client;
}
PugSetup_SetupGame(TeamType_Captains, MapType_Vote, 5, g_RecordGameOption, g_DoKnifeRound,
g_AutoLive);
return Plugin_Handled;
}
public Action Command_Rand(int client, int args) {
if (g_GameState != GameState_Warmup)
return Plugin_Handled;
if (!UsingCaptains()) {
PugSetup_Message(client, "%t", "NotUsingCaptains");
return Plugin_Handled;
}
if (!DoPermissionCheck(client, "sm_rand")) {
if (IsValidClient(client))
PugSetup_Message(client, "%t", "NoPermission");
return Plugin_Handled;
}
PugSetup_SetRandomCaptains();
return Plugin_Handled;
}
public Action Command_Capt(int client, int args) {
if (g_GameState != GameState_Warmup)
return Plugin_Handled;
if (!UsingCaptains()) {
PugSetup_Message(client, "%t", "NotUsingCaptains");
return Plugin_Handled;
}
if (!DoPermissionCheck(client, "sm_capt")) {
if (IsValidClient(client))
PugSetup_Message(client, "%t", "NoPermission");
return Plugin_Handled;
}
char buffer[MAX_NAME_LENGTH];
if (GetCmdArgs() >= 1) {
GetCmdArg(1, buffer, sizeof(buffer));
int target = FindTarget(client, buffer, true, false);
if (IsPlayer(target))
PugSetup_SetCaptain(1, target, true);
if (GetCmdArgs() >= 2) {
GetCmdArg(2, buffer, sizeof(buffer));
target = FindTarget(client, buffer, true, false);
if (IsPlayer(target))
PugSetup_SetCaptain(2, target, true);
} else {
Captain2Menu(client);
}
} else {
Captain1Menu(client);
}
return Plugin_Handled;
}
public Action Command_ForceStart(int client, int args) {
if (g_GameState != GameState_Warmup)
return Plugin_Handled;
if (!DoPermissionCheck(client, "sm_forcestart")) {
if (IsValidClient(client))
PugSetup_Message(client, "%t", "NoPermission");
return Plugin_Handled;
}
for (int i = 1; i <= MaxClients; i++) {
if (IsPlayer(i) && !PugSetup_IsReady(i)) {
PugSetup_ReadyPlayer(i, false);
}
}
g_ForceStartSignal = true;
return Plugin_Handled;
}
static void ListMapList(int client, ArrayList maplist) {
int n = maplist.Length;
if (n == 0) {
PugSetup_Message(client, "No maps found");
} else {
char buffer[PLATFORM_MAX_PATH];
for (int i = 0; i < n; i++) {
FormatMapName(maplist, i, buffer, sizeof(buffer));
PugSetup_Message(client, "Map %d: %s", i + 1, buffer);
}
}
}
public Action Command_ListPugMaps(int client, int args) {
if (!DoPermissionCheck(client, "sm_listpugmaps")) {
if (IsValidClient(client))
PugSetup_Message(client, "%t", "NoPermission");
return Plugin_Handled;
}
ListMapList(client, g_MapList);
return Plugin_Handled;
}
public Action Command_ListAimMaps(int client, int args) {
if (!DoPermissionCheck(client, "sm_listaimmaps")) {
if (IsValidClient(client))
PugSetup_Message(client, "%t", "NoPermission");
return Plugin_Handled;
}
ListMapList(client, g_AimMapList);
return Plugin_Handled;
}
public Action Command_Start(int client, int args) {
// Some people like to type .start instead of .setup, since
// that's often types in ESEA's scrim server setup, so this is allowed here as well.
if (g_GameState == GameState_None) {
FakeClientCommand(client, "sm_setup");
return Plugin_Handled;
}
if (g_GameState != GameState_WaitingForStart) {
return Plugin_Handled;
}
if (!DoPermissionCheck(client, "sm_start")) {
if (IsValidClient(client))
PugSetup_Message(client, "%t", "NoPermission");
return Plugin_Handled;
}
CreateCountDown();
return Plugin_Handled;
}
public void LoadTranslatedAliases() {
// For each of these sm_x commands, we need the
// translation phrase sm_x_alias to be present.
AddTranslatedAlias("sm_capt", ChatAlias_WhenSetup);
AddTranslatedAlias("sm_endgame", ChatAlias_WhenSetup);
AddTranslatedAlias("sm_notready", ChatAlias_WhenSetup);
AddTranslatedAlias("sm_pause", ChatAlias_WhenSetup);
AddTranslatedAlias("sm_ready", ChatAlias_WhenSetup);
AddTranslatedAlias("sm_setup");
AddTranslatedAlias("sm_stay", ChatAlias_WhenSetup);
AddTranslatedAlias("sm_swap", ChatAlias_WhenSetup);
AddTranslatedAlias("sm_unpause", ChatAlias_WhenSetup);
AddTranslatedAlias("sm_start", ChatAlias_WhenSetup);
}
public void LoadExtraAliases() {
// Read custom user aliases
ReadChatConfig();
// Any extra chat aliases we want
PugSetup_AddChatAlias(".captain", "sm_capt", ChatAlias_WhenSetup);