forked from kidfearless/shavit-mapchooser
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshavit-mapchooser.sp
1629 lines (1349 loc) · 38.6 KB
/
shavit-mapchooser.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
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <shavit>
#include <cstrike>
#undef REQUIRE_PLUGIN
// for MapChange type
#include <mapchooser>
#define PLUGIN_VERSION "1.0.4.7"
Database g_hDatabase;
char g_cSQLPrefix[32];
#if defined DEBUG
bool g_bDebug;
#endif
/* ConVars */
ConVar g_cvRTVRequiredPercentage;
ConVar g_cvRTVAllowSpectators;
ConVar g_cvRTVMinimumPoints;
ConVar g_cvRTVDelayTime;
ConVar g_cvMapListType;
ConVar g_cvMatchFuzzyMap;
ConVar g_cvMapVoteStartTime;
ConVar g_cvMapVoteDuration;
ConVar g_cvMapVoteBlockMapInterval;
ConVar g_cvMapVoteExtendLimit;
ConVar g_cvMapVoteEnableNoVote;
ConVar g_cvMapVoteExtendTime;
ConVar g_cvMapVoteShowTier;
ConVar g_cvMapVoteRunOff;
ConVar g_cvMapVoteRunOffPerc;
ConVar g_cvMapVoteRevoteTime;
ConVar g_cvDisplayTimeRemaining;
ConVar g_cvNominateMatches;
ConVar g_cvEnhancedMenu;
ConVar g_cvMinTier;
ConVar g_cvMaxTier;
/* Map arrays */
ArrayList g_aMapList;
ArrayList g_aNominateList;
ArrayList g_aAllMapsList;
ArrayList g_aOldMaps;
/* Map Data */
char g_cMapName[PLATFORM_MAX_PATH];
MapChange g_ChangeTime;
bool g_bMapVoteStarted;
bool g_bMapVoteFinished;
float g_fMapStartTime;
float g_fLastMapvoteTime = 0.0;
int g_iExtendCount;
Menu g_hNominateMenu;
Menu g_hEnhancedMenu;
ArrayList g_aTierMenus;
Menu g_hVoteMenu;
/* Player Data */
bool g_bRockTheVote[MAXPLAYERS + 1];
char g_cNominatedMap[MAXPLAYERS + 1][PLATFORM_MAX_PATH];
Handle g_hRetryTimer = null;
Handle g_hForward_OnRTV = null;
Handle g_hForward_OnUnRTV = null;
Handle g_hForward_OnSuccesfulRTV = null;
enum
{
MapListZoned,
MapListFile,
MapListFolder,
MapListMixed
}
public Plugin myinfo =
{
name = "shavit - MapChooser",
author = "SlidyBat",
description = "Automated Map Voting and nominating with Shavit timer integration",
version = PLUGIN_VERSION,
url = ""
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
g_hForward_OnRTV = CreateGlobalForward("SMC_OnRTV", ET_Event, Param_Cell);
g_hForward_OnUnRTV = CreateGlobalForward("SMC_OnUnRTV", ET_Event, Param_Cell);
g_hForward_OnSuccesfulRTV = CreateGlobalForward("SMC_OnSuccesfulRTV", ET_Event);
return APLRes_Success;
}
public void OnPluginStart()
{
LoadTranslations("mapchooser.phrases");
LoadTranslations("common.phrases");
LoadTranslations("rockthevote.phrases");
LoadTranslations("nominations.phrases");
g_aMapList = new ArrayList(ByteCountToCells(PLATFORM_MAX_PATH));
g_aAllMapsList = new ArrayList(ByteCountToCells(PLATFORM_MAX_PATH));
g_aNominateList = new ArrayList(ByteCountToCells(PLATFORM_MAX_PATH));
g_aOldMaps = new ArrayList(ByteCountToCells(PLATFORM_MAX_PATH));
g_aTierMenus = new ArrayList(ByteCountToCells(PLATFORM_MAX_PATH));
g_cvMapListType = CreateConVar("smc_maplist_type", "1", "Where the plugin should get the map list from. 0 = zoned maps from database, 1 = from maplist file (mapcycle.txt), 2 = from maps folder, 3 = from zoned maps and confirmed by maplist file", _, true, 0.0, true, 3.0);
g_cvMatchFuzzyMap = CreateConVar("smc_match_fuzzy", "1", "If set to 1, the plugin will accept partial map matches from the database. Useful for workshop maps, bad for duplicate map names", _, true, 0.0, true, 1.0);
g_cvMapVoteBlockMapInterval = CreateConVar("smc_mapvote_blockmap_interval", "1", "How many maps should be played before a map can be nominated again", _, true, 0.0, false);
g_cvMapVoteEnableNoVote = CreateConVar("smc_mapvote_enable_novote", "1", "Whether players are able to choose 'No Vote' in map vote", _, true, 0.0, true, 1.0);
g_cvMapVoteExtendLimit = CreateConVar("smc_mapvote_extend_limit", "3", "How many times players can choose to extend a single map (0 = block extending)", _, true, 0.0, false);
g_cvMapVoteExtendTime = CreateConVar("smc_mapvote_extend_time", "10", "How many minutes should the map be extended by if the map is extended through a mapvote", _, true, 1.0, false);
g_cvMapVoteShowTier = CreateConVar("smc_mapvote_show_tier", "1", "Whether the map tier should be displayed in the map vote", _, true, 0.0, true, 1.0);
g_cvMapVoteDuration = CreateConVar("smc_mapvote_duration", "1", "Duration of time in minutes that map vote menu should be displayed for", _, true, 0.1, false);
g_cvMapVoteStartTime = CreateConVar("smc_mapvote_start_time", "5", "Time in minutes before map end that map vote starts", _, true, 1.0, false);
g_cvRTVAllowSpectators = CreateConVar("smc_rtv_allow_spectators", "1", "Whether spectators should be allowed to RTV", _, true, 0.0, true, 1.0);
g_cvRTVMinimumPoints = CreateConVar("smc_rtv_minimum_points", "-1", "Minimum number of points a player must have before being able to RTV, or -1 to allow everyone", _, true, -1.0, false);
g_cvRTVDelayTime = CreateConVar("smc_rtv_delay", "5", "Time in minutes after map start before players should be allowed to RTV", _, true, 0.0, false);
g_cvRTVRequiredPercentage = CreateConVar("smc_rtv_required_percentage", "50", "Percentage of players who have RTVed before a map vote is initiated", _, true, 1.0, true, 100.0);
g_cvMapVoteRunOff = CreateConVar("smc_mapvote_runoff", "1", "Hold run of votes if winning choice is less than a certain margin", _, true, 0.0, true, 1.0);
g_cvMapVoteRunOffPerc = CreateConVar("smc_mapvote_runoffpercent", "50", "If winning choice has less than this percent of votes, hold a runoff", _, true, 0.0, true, 100.0);
g_cvMapVoteRevoteTime = CreateConVar("smc_mapvote_revotetime", "0", "How many minutes after a failed mapvote before rtv is enabled again", _, true, 0.0);
g_cvDisplayTimeRemaining = CreateConVar("smc_display_timeleft", "1", "Display remaining messages in chat", _, true, 0.0, true, 1.0);
g_cvNominateMatches = CreateConVar("smc_nominate_matches", "1", "Prompts a menu which shows all maps which match argument", _, true, 0.0, true, 1.0);
g_cvEnhancedMenu = CreateConVar("smc_enhanced_menu", "1", "Nominate menu can show maps by alphabetic order and tiers", _, true, 0.0, true, 1.0);
g_cvMinTier = CreateConVar("smc_min_tier", "0", "The minimum tier to show on the enhanced menu", _, true, 0.0, true, 10.0);
g_cvMaxTier = CreateConVar("smc_max_tier", "10", "The maximum tier to show on the enhanced menu", _, true, 0.0, true, 10.0);
AutoExecConfig();
RegAdminCmd("sm_extendmap", Command_Extend, ADMFLAG_RCON, "Admin command for extending map");
RegAdminCmd("sm_forcemapvote", Command_ForceMapVote, ADMFLAG_RCON, "Admin command for forcing the end of map vote");
RegAdminCmd("sm_reloadmaplist", Command_ReloadMaplist, ADMFLAG_CHANGEMAP, "Admin command for forcing maplist to be reloaded");
RegConsoleCmd("sm_nominate", Command_Nominate, "Lets players nominate maps to be on the end of map vote");
RegConsoleCmd("sm_unnominate", Command_UnNominate, "Removes nominations");
RegConsoleCmd("sm_rtv", Command_RockTheVote, "Lets players Rock The Vote");
RegConsoleCmd("sm_unrtv", Command_UnRockTheVote, "Lets players un-Rock The Vote");
RegConsoleCmd("sm_nomlist", Command_NomList, "Shows currently nominated maps");
#if defined DEBUG
RegConsoleCmd("sm_smcdebug", Command_Debug);
#endif
}
public void OnMapStart()
{
GetCurrentMap(g_cMapName, sizeof(g_cMapName));
SetNextMap(g_cMapName);
// disable rtv if delay time is > 0
g_fMapStartTime = GetGameTime();
g_fLastMapvoteTime = 0.0;
g_iExtendCount = 0;
g_bMapVoteFinished = false;
g_bMapVoteStarted = false;
g_aNominateList.Clear();
for(int i = 1; i <= MaxClients; ++i)
{
g_cNominatedMap[i][0] = '\0';
}
ClearRTV();
CreateTimer(2.0, Timer_OnMapTimeLeftChanged, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
public void OnConfigsExecuted()
{
// reload maplist array
LoadMapList();
// cache the nominate menu so that it isn't being built every time player opens it
}
public void OnMapEnd()
{
if(g_cvMapVoteBlockMapInterval.IntValue > 0)
{
g_aOldMaps.PushString(g_cMapName);
if(g_aOldMaps.Length > g_cvMapVoteBlockMapInterval.IntValue)
{
g_aOldMaps.Erase(0);
}
}
g_iExtendCount = 0;
g_bMapVoteFinished = false;
g_bMapVoteStarted = false;
g_aNominateList.Clear();
for(int i = 1; i <= MaxClients; i++)
{
g_cNominatedMap[i][0] = '\0';
}
ClearRTV();
}
public Action Timer_OnMapTimeLeftChanged(Handle Timer)
{
#if defined DEBUG
if(g_bDebug)
{
DebugPrint("[SMC] OnMapTimeLeftChanged: maplist_length=%i mapvote_started=%s mapvotefinished=%s", g_aMapList.Length, g_bMapVoteStarted ? "true" : "false", g_bMapVoteFinished ? "true" : "false");
}
#endif
int timeleft;
if(GetMapTimeLeft(timeleft))
{
if(!g_bMapVoteStarted && !g_bMapVoteFinished)
{
int mapvoteTime = timeleft - RoundFloat(g_cvMapVoteStartTime.FloatValue * 60.0);
switch(mapvoteTime)
{
case (10 * 60) - 3:
{
PrintToChatAll("[SMC] 10 minutes until map vote");
}
case (5 * 60) - 3:
{
PrintToChatAll("[SMC] 5 minutes until map vote");
}
case 60 - 3:
{
PrintToChatAll("[SMC] 1 minute until map vote");
}
case 30 - 3:
{
PrintToChatAll("[SMC] 30 seconds until map vote");
}
case 5 - 3:
{
PrintToChatAll("[SMC] 5 seconds until map vote");
}
}
}
else if(g_bMapVoteFinished && g_cvDisplayTimeRemaining.BoolValue)
{
switch(timeleft)
{
case (30 * 60) - 3:
{
PrintToChatAll("[SMC] 30 minutes remaining");
}
case (20 * 60) - 3:
{
PrintToChatAll("[SMC] 20 minutes remaining");
}
case (10 * 60) - 3:
{
PrintToChatAll("[SMC] 10 minutes remaining");
}
case (5 * 60) - 3:
{
PrintToChatAll("[SMC] 5 minutes remaining");
}
case 60 - 3:
{
PrintToChatAll("[SMC] 1 minute remaining");
}
case 10 - 3:
{
PrintToChatAll("[SMC] 10 seconds remaining");
}
case 5 - 3:
{
PrintToChatAll("[SMC] 5 seconds remaining");
}
case 3 - 3:
{
PrintToChatAll("[SMC] 3 seconds remaining");
}
case 2 - 3:
{
PrintToChatAll("[SMC] 2 seconds remaining");
}
case 1 - 3:
{
PrintToChatAll("[SMC] 1 seconds remaining");
}
}
}
}
if(g_aMapList.Length && !g_bMapVoteStarted && !g_bMapVoteFinished)
{
CheckTimeLeft();
}
}
void CheckTimeLeft()
{
int timeleft;
if(GetMapTimeLeft(timeleft) && timeleft > 0)
{
int startTime = RoundFloat(g_cvMapVoteStartTime.FloatValue * 60.0);
#if defined DEBUG
if(g_bDebug)
{
DebugPrint("[SMC] CheckTimeLeft: timeleft=%i startTime=%i", timeleft, startTime);
}
#endif
if(timeleft - startTime <= 0)
{
#if defined DEBUG
if(g_bDebug)
{
DebugPrint("[SMC] CheckTimeLeft: Initiating map vote ...", timeleft, startTime);
}
#endif
InitiateMapVote(MapChange_MapEnd);
}
}
#if defined DEBUG
else
{
if(g_bDebug)
{
DebugPrint("[SMC] CheckTimeLeft: GetMapTimeLeft=%s timeleft=%i", GetMapTimeLeft(timeleft) ? "true" : "false", timeleft);
}
}
#endif
}
public void OnClientDisconnect(int client)
{
// clear player data
g_bRockTheVote[client] = false;
g_cNominatedMap[client][0] = '\0';
CheckRTV();
}
public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs)
{
if(StrEqual(sArgs, "rtv", false) || StrEqual(sArgs, "rockthevote", false))
{
ReplySource old = SetCmdReplySource(SM_REPLY_TO_CHAT);
Command_RockTheVote(client, 0);
SetCmdReplySource(old);
}
else if(StrEqual(sArgs, "nominate", false))
{
ReplySource old = SetCmdReplySource(SM_REPLY_TO_CHAT);
Command_Nominate(client, 0);
SetCmdReplySource(old);
}
}
void InitiateMapVote(MapChange when)
{
g_ChangeTime = when;
g_bMapVoteStarted = true;
if (IsVoteInProgress())
{
// Can't start a vote, try again in 5 seconds.
//g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE);
DataPack data;
g_hRetryTimer = CreateDataTimer(5.0, Timer_StartMapVote, data, TIMER_FLAG_NO_MAPCHANGE);
data.WriteCell(when);
data.Reset();
return;
}
// create menu
Menu menu = new Menu(Handler_MapVoteMenu, MENU_ACTIONS_ALL);
menu.VoteResultCallback = Handler_MapVoteFinished;
menu.Pagination = MENU_NO_PAGINATION;
menu.SetTitle("Vote Nextmap");
int mapsToAdd = 8;
if(g_cvMapVoteExtendLimit.IntValue > 0 && g_iExtendCount < g_cvMapVoteExtendLimit.IntValue)
{
mapsToAdd--;
}
if(g_cvMapVoteEnableNoVote.BoolValue)
{
mapsToAdd--;
}
char map[PLATFORM_MAX_PATH];
char mapdisplay[PLATFORM_MAX_PATH + 32];
int nominateMapsToAdd = (mapsToAdd > g_aNominateList.Length) ? g_aNominateList.Length : mapsToAdd;
for(int i = 0; i < nominateMapsToAdd; i++)
{
g_aNominateList.GetString(i, map, sizeof(map));
GetMapDisplayName(map, mapdisplay, sizeof(mapdisplay));
if(g_cvMapVoteShowTier.BoolValue)
{
int tier = Shavit_GetMapTier(mapdisplay);
Format(mapdisplay, sizeof(mapdisplay), "[T%i] %s", tier, mapdisplay);
}
else
{
strcopy(mapdisplay, sizeof(mapdisplay), map);
}
menu.AddItem(map, mapdisplay);
mapsToAdd--;
}
for(int i = 0; i < mapsToAdd; i++)
{
int rand = GetRandomInt(0, g_aMapList.Length - 1);
g_aMapList.GetString(rand, map, sizeof(map));
GetMapDisplayName(map, mapdisplay, sizeof(mapdisplay));
if(StrEqual(map, g_cMapName))
{
// don't add current map to vote
i--;
continue;
}
int idx = g_aOldMaps.FindString(map);
if(idx != -1)
{
// map already played recently, get another map
i--;
continue;
}
if(g_cvMapVoteShowTier.BoolValue)
{
int tier = Shavit_GetMapTier(mapdisplay);
Format(mapdisplay, sizeof(mapdisplay), "[T%i] %s", tier, mapdisplay);
}
menu.AddItem(map, mapdisplay);
}
if(when == MapChange_MapEnd && g_cvMapVoteExtendLimit.IntValue > 0 && g_iExtendCount < g_cvMapVoteExtendLimit.IntValue)
{
menu.AddItem("extend", "Extend Map");
}
else if(when == MapChange_Instant)
{
menu.AddItem("dontchange", "Don't Change");
}
menu.NoVoteButton = g_cvMapVoteEnableNoVote.BoolValue;
menu.ExitButton = false;
menu.DisplayVoteToAll(RoundFloat(g_cvMapVoteDuration.FloatValue * 60.0));
PrintToChatAll("[SMC] %t", "Nextmap Voting Started");
}
public void Handler_MapVoteFinished(Menu menu, int num_votes, int num_clients, const int[][] client_info, int num_items, const int[][] item_info)
{
if (g_cvMapVoteRunOff.BoolValue && num_items > 1)
{
float winningvotes = float(item_info[0][VOTEINFO_ITEM_VOTES]);
float required = num_votes * (g_cvMapVoteRunOffPerc.FloatValue / 100.0);
if (winningvotes < required)
{
/* Insufficient Winning margin - Lets do a runoff */
g_hVoteMenu = new Menu(Handler_MapVoteMenu, MENU_ACTIONS_ALL);
g_hVoteMenu.SetTitle("Runoff Vote Nextmap");
g_hVoteMenu.VoteResultCallback = Handler_VoteFinishedGeneric;
char map[PLATFORM_MAX_PATH];
char info1[PLATFORM_MAX_PATH];
char info2[PLATFORM_MAX_PATH];
menu.GetItem(item_info[0][VOTEINFO_ITEM_INDEX], map, sizeof(map), _, info1, sizeof(info1));
g_hVoteMenu.AddItem(map, info1);
menu.GetItem(item_info[1][VOTEINFO_ITEM_INDEX], map, sizeof(map), _, info2, sizeof(info2));
g_hVoteMenu.AddItem(map, info2);
g_hVoteMenu.ExitButton = true;
g_hVoteMenu.DisplayVoteToAll(RoundFloat(g_cvMapVoteDuration.FloatValue * 60.0));
/* Notify */
float map1percent = float(item_info[0][VOTEINFO_ITEM_VOTES])/ float(num_votes) * 100;
float map2percent = float(item_info[1][VOTEINFO_ITEM_VOTES])/ float(num_votes) * 100;
PrintToChatAll("[SM] %t", "Starting Runoff", g_cvMapVoteRunOffPerc.FloatValue, info1, map1percent, info2, map2percent);
LogMessage("Voting for next map was indecisive, beginning runoff vote");
return;
}
}
Handler_VoteFinishedGeneric(menu, num_votes, num_clients, client_info, num_items, item_info);
}
public Action Timer_StartMapVote(Handle timer, DataPack data)
{
if (timer == g_hRetryTimer)
{
g_hRetryTimer = null;
}
if (!g_aMapList.Length || g_bMapVoteFinished || g_bMapVoteStarted)
{
return Plugin_Stop;
}
MapChange when = view_as<MapChange>(data.ReadCell());
InitiateMapVote(when);
return Plugin_Stop;
}
public void Handler_VoteFinishedGeneric(Menu menu, int num_votes, int num_clients, const int[][] client_info, int num_items, const int[][] item_info)
{
char map[PLATFORM_MAX_PATH];
char displayName[PLATFORM_MAX_PATH];
menu.GetItem(item_info[0][VOTEINFO_ITEM_INDEX], map, sizeof(map), _, displayName, sizeof(displayName));
PrintToChatAll("#1 vote was %s (%s)", map, (g_ChangeTime == MapChange_Instant) ? "instant" : "map end");
if(StrEqual(map, "extend"))
{
g_iExtendCount++;
int time;
if(GetMapTimeLimit(time))
{
if(time > 0)
{
ExtendMapTimeLimit(g_cvMapVoteExtendTime.IntValue * 60);
}
}
PrintToChatAll("[SMC] %t", "Current Map Extended", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
LogAction(-1, -1, "Voting for next map has finished. The current map has been extended.");
// We extended, so we'll have to vote again.
g_bMapVoteStarted = false;
g_fLastMapvoteTime = GetGameTime();
ClearRTV();
}
else if(StrEqual(map, "dontchange"))
{
PrintToChatAll("[SMC] %t", "Current Map Stays", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
LogAction(-1, -1, "Voting for next map has finished. 'No Change' was the winner");
g_bMapVoteFinished = false;
g_bMapVoteStarted = false;
g_fLastMapvoteTime = GetGameTime();
ClearRTV();
}
else
{
if(g_ChangeTime == MapChange_MapEnd)
{
SetNextMap(map);
}
else if(g_ChangeTime == MapChange_Instant)
{
if(GetRTVVotesNeeded() <= 0)
{
Call_StartForward(g_hForward_OnSuccesfulRTV);
Call_Finish();
}
DataPack data;
CreateDataTimer(2.0, Timer_ChangeMap, data);
data.WriteString(map);
ClearRTV();
}
g_bMapVoteStarted = false;
g_bMapVoteFinished = true;
PrintToChatAll("[SMC] %t", "Nextmap Voting Finished", displayName, RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
LogAction(-1, -1, "Voting for next map has finished. Nextmap: %s.", map);
}
}
public int Handler_MapVoteMenu(Menu menu, MenuAction action, int param1, int param2)
{
switch(action)
{
case MenuAction_End:
{
delete menu;
}
case MenuAction_Display:
{
Panel panel = view_as<Panel>(param2);
panel.SetTitle("Vote Nextmap");
}
case MenuAction_DisplayItem:
{
if (menu.ItemCount - 1 == param2)
{
char map[PLATFORM_MAX_PATH], buffer[255];
menu.GetItem(param2, map, sizeof(map));
if (strcmp(map, "extend", false) == 0)
{
Format(buffer, sizeof(buffer), "Extend Map");
return RedrawMenuItem(buffer);
}
else if (strcmp(map, "novote", false) == 0)
{
Format(buffer, sizeof(buffer), "No Vote");
return RedrawMenuItem(buffer);
}
}
}
case MenuAction_VoteCancel:
{
// If we receive 0 votes, pick at random.
if(param1 == VoteCancel_NoVotes)
{
int count = menu.ItemCount;
char map[PLATFORM_MAX_PATH];
menu.GetItem(0, map, sizeof(map));
// Make sure the first map in the menu isn't one of the special items.
// This would mean there are no real maps in the menu, because the special items are added after all maps. Don't do anything if that's the case.
if(strcmp(map, "extend", false) != 0 && strcmp(map, "dontchange", false) != 0)
{
// Get a random map from the list.
// Make sure it's not one of the special items.
do
{
int item = GetRandomInt(0, count - 1);
menu.GetItem(item, map, sizeof(map));
}
while(strcmp(map, "extend", false) == 0 || strcmp(map, "dontchange", false) == 0);
SetNextMap(map);
PrintToChatAll("[SMC] %t", "Nextmap Voting Finished", map, 0, 0);
LogAction(-1, -1, "Voting for next map has finished. Nextmap: %s.", map);
g_bMapVoteFinished = true;
}
}
else
{
// We were actually cancelled. I guess we do nothing.
}
g_bMapVoteStarted = false;
}
}
return 0;
}
// extends map while also notifying players and setting plugin data
void ExtendMap(int time = 0)
{
if(time == 0)
{
time = RoundFloat(g_cvMapVoteExtendTime.FloatValue * 60);
}
ExtendMapTimeLimit(time);
PrintToChatAll("[SMC] The map was extended for %.1f minutes", time / 60.0);
g_bMapVoteStarted = false;
g_bMapVoteFinished = false;
}
void LoadMapList()
{
g_aMapList.Clear();
g_aAllMapsList.Clear();
switch(g_cvMapListType.IntValue)
{
case MapListZoned:
{
delete g_hDatabase;
SQL_SetPrefix();
char buffer[512];
g_hDatabase = SQL_Connect("shavit", true, buffer, sizeof(buffer));
Format(buffer, sizeof(buffer), "SELECT `map` FROM `%smapzones` WHERE `type` = 1 AND `track` = 0 ORDER BY `map`", g_cSQLPrefix);
g_hDatabase.Query(LoadZonedMapsCallback, buffer, _, DBPrio_High);
}
case MapListFolder:
{
LoadFromMapsFolder(g_aMapList);
CreateNominateMenu();
}
case MapListFile:
{
ReadMapList(g_aMapList, _, "default");
CreateNominateMenu();
}
case MapListMixed:
{
delete g_hDatabase;
SQL_SetPrefix();
ReadMapList(g_aAllMapsList, _, "default");
char buffer[512];
g_hDatabase = SQL_Connect("shavit", true, buffer, sizeof(buffer));
Format(buffer, sizeof(buffer), "SELECT `map` FROM `%smapzones` WHERE `type` = 1 AND `track` = 0 ORDER BY `map`", g_cSQLPrefix);
g_hDatabase.Query(LoadZonedMapsCallbackMixed, buffer, _, DBPrio_High);
}
}
}
public void LoadZonedMapsCallback(Database db, DBResultSet results, const char[] error, any data)
{
if(results == null)
{
LogError("[SMC] - (LoadMapZonesCallback) - %s", error);
return;
}
char map[PLATFORM_MAX_PATH];
char map2[PLATFORM_MAX_PATH];
while(results.FetchRow())
{
results.FetchString(0, map, sizeof(map));
if((FindMap(map, map2, sizeof(map2)) == FindMap_Found) || (g_cvMatchFuzzyMap.BoolValue && FindMap(map, map2, sizeof(map2)) == FindMap_FuzzyMatch))
{
g_aMapList.PushString(map2);
}
}
CreateNominateMenu();
}
public void LoadZonedMapsCallbackMixed(Database db, DBResultSet results, const char[] error, any data)
{
if(results == null)
{
LogError("[SMC] - (LoadMapZonesCallbackMixed) - %s", error);
return;
}
char map[PLATFORM_MAX_PATH];
char map2[PLATFORM_MAX_PATH];
char buffer[PLATFORM_MAX_PATH];
while(results.FetchRow())
{
results.FetchString(0, map, sizeof(map));//db mapname
for (int i = 0; i < g_aAllMapsList.Length; ++i)
{
g_aAllMapsList.GetString(i, buffer, sizeof(buffer));//maplistmapname
GetMapDisplayName(buffer, map2, sizeof(map2));//get's the displayname of the map
if (StrEqual(map, map2, false))
{
g_aMapList.PushString(buffer);
}
}
}
CreateNominateMenu();
}
bool SMC_FindMap(const char[] mapname, char[] output, int maxlen)
{
int length = g_aMapList.Length;
for(int i = 0; i < length; i++)
{
char entry[PLATFORM_MAX_PATH];
g_aMapList.GetString(i, entry, sizeof(entry));
if(StrContains(entry, mapname) != -1)
{
strcopy(output, maxlen, entry);
return true;
}
}
return false;
}
void SMC_NominateMatches(int client, const char[] mapname)
{
Menu subNominateMenu = new Menu(NominateMenuHandler);
subNominateMenu.SetTitle("Nominate Menu\nMaps matching \"%s\"\n ", mapname);
bool isCurrentMap = false;
bool isOldMap = false;
char map[PLATFORM_MAX_PATH];
char oldMapName[PLATFORM_MAX_PATH];
int length = g_aMapList.Length;
for(int i = 0; i < length; i++)
{
char entry[PLATFORM_MAX_PATH];
g_aMapList.GetString(i, entry, sizeof(entry));
if(StrContains(entry, mapname) != -1)
{
if(StrEqual(entry, g_cMapName))
{
isCurrentMap = true;
continue;
}
int idx = g_aOldMaps.FindString(entry);
if(idx != -1)
{
isOldMap = true;
oldMapName = entry;
continue;
}
map = entry;
char mapdisplay[PLATFORM_MAX_PATH + 32];
GetMapDisplayName(entry, mapdisplay, sizeof(mapdisplay));
int tier = Shavit_GetMapTier(mapdisplay);
Format(mapdisplay, sizeof(mapdisplay), "%s | T%i", mapdisplay, tier);
subNominateMenu.AddItem(entry, mapdisplay);
}
}
switch (subNominateMenu.ItemCount)
{
case 0:
{
if (isCurrentMap)
{
ReplyToCommand(client, "[SMC] %t", "Can't Nominate Current Map");
}
else if (isOldMap)
{
ReplyToCommand(client, "[SMC] %s %t", oldMapName, "Recently Played");
}
else
{
ReplyToCommand(client, "[SMC] %t", "Map was not found", mapname);
}
if (subNominateMenu != INVALID_HANDLE)
{
CloseHandle(subNominateMenu);
}
}
case 1:
{
Nominate(client, map);
if (subNominateMenu != INVALID_HANDLE)
{
CloseHandle(subNominateMenu);
}
}
default:
{
subNominateMenu.Display(client, MENU_TIME_FOREVER);
}
}
}
bool IsRTVEnabled()
{
float time = GetGameTime();
if(g_fLastMapvoteTime != 0.0)
{
if(time - g_fLastMapvoteTime > g_cvMapVoteRevoteTime.FloatValue * 60)
{
return true;
}
}
else if(time - g_fMapStartTime > g_cvRTVDelayTime.FloatValue * 60)
{
return true;
}
return false;
}
void ClearRTV()
{
for(int i = 1; i <= MaxClients; i++)
{
g_bRockTheVote[i] = false;
}
}
/* Timers */
public Action Timer_ChangeMap(Handle timer, DataPack data)
{
char map[PLATFORM_MAX_PATH];
data.Reset();
data.ReadString(map, sizeof(map));
ForceChangeLevel(map, "RTV Mapvote");
}
/* Commands */
public Action Command_Extend(int client, int args)
{
int extendtime;
if(args > 0)
{
char sArg[8];
GetCmdArg(1, sArg, sizeof(sArg));
extendtime = RoundFloat(StringToFloat(sArg) * 60);
}
else
{
extendtime = RoundFloat(g_cvMapVoteExtendTime.FloatValue * 60.0);
}
ExtendMap(extendtime);
return Plugin_Handled;
}
public Action Command_ForceMapVote(int client, int args)
{
if(g_bMapVoteStarted || g_bMapVoteFinished)
{
ReplyToCommand(client, "[SMC] Map vote already %s", (g_bMapVoteStarted) ? "initiated" : "finished");
}
else
{
InitiateMapVote(MapChange_Instant);
}
return Plugin_Handled;
}
public Action Command_ReloadMaplist(int client, int args)
{
LoadMapList();
return Plugin_Handled;
}
public Action Command_Nominate(int client, int args)
{
if(args < 1)
{
if (g_cvEnhancedMenu.BoolValue)
{
OpenEnhancedMenu(client);
}
else
{
OpenNominateMenu(client);