-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmapchooser_redux.sp
1251 lines (1034 loc) · 36.1 KB
/
mapchooser_redux.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 <smutils>
#include <mapchooser_redux>
// options
#undef REQUIRE_PLUGIN
#include <store>
#include <shop>
#include <fys.pupd>
#include <fys.bans>
Handle g_tVote;
Handle g_tRetry;
Handle g_tWarning;
Menu g_hVoteMenu;
ArrayList g_aMapList;
ArrayList g_aNextMapList;
ArrayList g_aNominations;
int g_iExtends;
int g_iMapFileSerial = -1;
int g_iNominateCount;
int g_iRunoffCount;
bool g_bPartyblock;
bool g_bAllowCountdown;
bool g_bHasVoteStarted;
bool g_bWaitingForVote;
bool g_bMapVoteCompleted;
bool g_bChangeMapInProgress;
bool g_bChangeMapAtRoundEnd;
bool g_bWarningInProgress;
bool g_bBlockedSlots;
bool g_bMapLoaded;
bool g_pStore;
bool g_pShop;
bool g_pMaps;
bool g_pBans;
enum TimerLocation
{
TimerLocation_Hint = 0,
TimerLocation_Text,
TimerLocation_Chat,
TimerLocation_HUD
}
enum struct Convars
{
ConVar TimeLoc;
ConVar NameTag;
ConVar TierTag;
ConVar DescTag;
ConVar MaxExts;
ConVar Recents;
ConVar LtpMtpl;
ConVar BCState;
ConVar Shuffle;
ConVar Refunds;
ConVar Require;
ConVar NoVotes;
ConVar MinRuns;
ConVar AutoGen;
}
// tier
char g_TierString[MAX_TIER+1][32] = {
"", "Intro", "Easy", "Normal", "Hard", "Mars", "Death"
};
// cvars
Convars g_ConVars;
MapChange g_MapChange;
// external
native int Maps_GetTier(const char[] map);
native bool Maps_GetName(const char[] map, char[] buffer, int maxLen);
#include "mapchooser/cmds.sp"
#include "mapchooser/cvars.sp"
#include "mapchooser/data.sp"
#include "mapchooser/events.sp"
#include "mapchooser/natives.sp"
#include "mapchooser/stocks.sp"
public Plugin myinfo =
{
name = "MapChooser Redux",
author = "Kyle",
description = "Automated Map Voting with Extensions",
version = MCR_VERSION,
url = "https://kxnrl.com"
};
public void OnPluginStart()
{
SMUtils_SetChatPrefix("[\x02M\x04C\x0CR\x01]");
SMUtils_SetChatSpaces(" ");
SMUtils_SetChatConSnd(false);
SMUtils_SetTextDest(HUD_PRINTCENTER);
Cmds_OnPluginStart();
Cvars_OnPluginStart();
Data_OnPluginStart();
Events_OnPluginStart();
Natives_OnPluginStart();
LoadTranslations("com.kxnrl.mcr.translations");
g_aMapList = new ArrayList(ByteCountToCells(128));
g_aNextMapList = new ArrayList(ByteCountToCells(128));
g_aNominations = new ArrayList(sizeof(Nominations));
}
public void OnAllPluginsLoaded()
{
g_pStore = LibraryExists("store");
g_pShop = LibraryExists("shop-core");
g_pMaps = LibraryExists("fys-Maps");
g_pBans = LibraryExists("fys-Bans");
Data_OnAllPluginsLoaded();
}
public void Pupd_OnCheckAllPlugins()
{
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/MCR/");
Pupd_CheckTranslation("com.kxnrl.mcr.translations.txt", "https://build.kxnrl.com/updater/MCR/translation/");
}
public void OnConfigsExecuted()
{
if (ReadMapList(g_aMapList, g_iMapFileSerial, "mapchooser", MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER) != null)
if (g_iMapFileSerial == -1)
SetFailState("Unable to create a valid map list.");
g_aNominations.Clear();
g_iExtends = 0;
g_bPartyblock = false;
g_bAllowCountdown = false;
g_bMapVoteCompleted = false;
g_bChangeMapAtRoundEnd = false;
g_iNominateCount = 0;
g_bMapLoaded = true;
CreateNextVote();
SetupTimeleftTimer();
Call_MapDataLoaded();
Call_MapVotePoolChanged();
}
public void OnMapEnd()
{
g_bMapLoaded = false;
g_bHasVoteStarted = false;
g_bWaitingForVote = false;
g_bChangeMapInProgress = false;
g_tVote = null;
g_tRetry = null;
g_tWarning = null;
g_iRunoffCount = 0;
Data_OnMapEnd();
}
public void OnClientConnected(int client)
{
if (GetClientCount(false) >= g_ConVars.MinRuns.IntValue)
{
// allow countdown cooldown
if (!g_bAllowCountdown)
{
char map[128];
GetCurrentMap(map, 128);
SetCooldown(map, false);
SetLastPlayed(map, false);
SaveMapPool(map);
// marked
g_bAllowCountdown = true;
}
}
}
public void OnClientDisconnect(int client)
{
if (!IsClientInGame(client))
return;
for (int index = 0; index < g_aNominations.Length; index++)
{
Nominations n;
g_aNominations.GetArray(index, n, sizeof(Nominations));
if (n.m_Owner == client)
{
g_aNominations.Erase(index);
Call_NominationsReset(n.m_Map, n.m_Owner, g_bPartyblock, NominateResetReason_Disconnect);
LogMessage("Removed [%s] by %L from nomination list.", n.m_Map, n.m_Owner);
// party block disconnect
if (g_bPartyblock)
g_bPartyblock = false;
break;
}
}
}
public void Maps_OnDataFetched()
{
Data_OnAllPluginsLoaded();
Call_MapDataLoaded();
PrintToServer("[MCR] Mapchooser-Redux has beed reloaded with Maps.");
}
/**
* Notification that the map's time left has changed via a change in the time
* limit or a change in the game rules (such as mp_restartgame). This is useful
* for plugins trying to create timers based on the time left in the map.
*
* Calling ExtendMapTimeLimit() from here, without proper precaution, will
* cause infinite recursion.
*
* If the operation is not supported, this will never be called.
* If the server has not yet processed any frames (i.e. no players have joined
* the map yet), then this will be called once the server begins ticking, even
* if there is no time limit set.
*/
public void OnMapTimeLeftChanged()
{
// anyhow?
if (!g_bMapLoaded)
return;
SetupTimeleftTimer();
}
void SetupTimeleftTimer()
{
if (g_bMapVoteCompleted)
{
PrintToServer("Map vote had been completed.");
return;
}
int timeLeft = GetTimeLeft();
// if timeLeft <= 0 meaning going to intermission
if (timeLeft <= 0)
return;
if (timeLeft - 300 < 0 && !g_bHasVoteStarted)
{
SetupWarningTimer(WarningType_Vote);
return;
}
if (g_aMapList.Length <= 0)
{
LogError("No enough maps to start the vote.");
return;
}
if (g_tWarning == null)
{
if (g_tVote != null)
KillTimer(g_tVote);
g_tVote = CreateTimer(float(timeLeft - 300), Timer_StartWarningTimer, _, TIMER_FLAG_NO_MAPCHANGE);
}
}
public Action Timer_StartWarningTimer(Handle timer)
{
g_tVote = null;
if (!g_bWarningInProgress || g_tWarning == null)
SetupWarningTimer(WarningType_Vote);
return Plugin_Stop;
}
public Action Timer_StartMapVote(Handle timer, DataPack data)
{
static int timePassed;
if (!g_aMapList.Length || g_bMapVoteCompleted || g_bHasVoteStarted)
{
g_tWarning = null;
return Plugin_Stop;
}
data.Reset();
int warningMaxTime = data.ReadCell();
int warningTimeRemaining = warningMaxTime - timePassed;
switch(view_as<TimerLocation>(g_ConVars.TimeLoc.IntValue))
{
case TimerLocation_Text: tTextAll("%t", g_ConVars.Shuffle.BoolValue ? "mcr countdown text hint shuffle" : "mcr countdown text hint", warningTimeRemaining);
case TimerLocation_Chat: tChatAll("%t", g_ConVars.Shuffle.BoolValue ? "mcr countdown chat shuffle" : "mcr countdown chat", warningTimeRemaining);
case TimerLocation_Hint: tHintAll("%t", g_ConVars.Shuffle.BoolValue ? "mcr countdown text hint shuffle" : "mcr countdown text hint", warningTimeRemaining);
case TimerLocation_HUD: DisplayCountdownHUD(warningTimeRemaining);
}
if (timePassed++ >= warningMaxTime)
{
if (timer == g_tRetry)
{
g_bWaitingForVote = false;
g_tRetry = null;
}
else
{
g_tWarning = null;
}
timePassed = 0;
MapChange mapChange = view_as<MapChange>(data.ReadCell());
ArrayList arraylist = view_as<ArrayList>(data.ReadCell());
InitiateVote(mapChange, arraylist);
return Plugin_Stop;
}
return Plugin_Continue;
}
public Action Command_Mapvote(int client, int args)
{
tChatAll("%t", "mcr voting started");
SetupWarningTimer(WarningType_Vote, MapChange_MapEnd, null, true);
LogAdminAction(client, "CallMapVote", "Start vote manually.");
return Plugin_Handled;
}
void InitiateVote(MapChange when, ArrayList inputlist)
{
g_bWaitingForVote = true;
g_bWarningInProgress = false;
if (IsVoteInProgress())
{
LogMessage("IsVoteInProgress -> %d", FAILURE_TIMER_LENGTH);
DataPack data = new DataPack();
data.WriteCell(FAILURE_TIMER_LENGTH);
data.WriteCell(when);
data.WriteCell(inputlist);
data.Reset();
g_tRetry = CreateTimer(1.0, Timer_StartMapVote, data, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT|TIMER_DATA_HNDL_CLOSE);
return;
}
if (g_bMapVoteCompleted && g_bChangeMapInProgress)
return;
SetHudTextParams(-1.0, 0.32, 3.5, 0, 255, 255, 255, 0, 0.3, 0.3, 0.3);
for(int client = 1; client <= MaxClients; ++client)
if (IsClientInGame(client) && !IsFakeClient(client))
ShowHudText(client, 0, "%T", "mcr voting started", client);
g_MapChange = when;
g_bWaitingForVote = false;
g_bHasVoteStarted = true;
Handle menuStyle = GetMenuStyleHandle(MenuStyle_Default);
if (menuStyle != INVALID_HANDLE)
g_hVoteMenu = CreateMenuEx(menuStyle, Handler_MapVoteMenu, MenuAction_End | MenuAction_Display | MenuAction_DisplayItem | MenuAction_VoteCancel);
else
g_hVoteMenu = new Menu(Handler_MapVoteMenu, MenuAction_End | MenuAction_Display | MenuAction_DisplayItem | MenuAction_VoteCancel);
Handle radioStyle = GetMenuStyleHandle(MenuStyle_Radio);
if (GetMenuStyle(g_hVoteMenu) == radioStyle)
{
g_bBlockedSlots = true;
if (!g_ConVars.NoVotes.BoolValue)
{
g_hVoteMenu.AddItem(LINE_SPACER, "", ITEMDRAW_SPACER);
}
g_hVoteMenu.AddItem(LINE_ONE, "Choose something...", ITEMDRAW_DISABLED);
g_hVoteMenu.AddItem(LINE_TWO, "...will ya?", ITEMDRAW_DISABLED);
}
else
g_bBlockedSlots = false;
if (g_ConVars.NoVotes.BoolValue)
{
g_hVoteMenu.OptionFlags = MENUFLAG_BUTTON_NOVOTE;
}
g_hVoteMenu.SetTitle("选择下一张地图\n ");
g_hVoteMenu.VoteResultCallback = Handler_MapVoteFinished;
int shuffleStart = -2;
if (g_bPartyblock)
{
for(int i = 0; i < 5; i++)
{
Nominations n;
g_aNominations.GetArray(0, n, sizeof(Nominations));
AddMapItem(g_hVoteMenu, n.m_Map, g_ConVars.NameTag.BoolValue, g_ConVars.TierTag.BoolValue, !g_ConVars.DescTag.BoolValue, n.m_Owner, i == 0 ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);
}
//AddExtendToMenu(g_hVoteMenu, when);
}
else if (inputlist == null)
{
char map[128];
int voteSize = 5, nominationsToAdd = g_aNominations.Length >= voteSize ? voteSize : g_aNominations.Length;
static ArrayList votePool = null;
if (votePool != null)
delete votePool;
votePool = new ArrayList(sizeof(Nominations));
if (g_ConVars.Shuffle.BoolValue && g_aNominations.Length >= g_ConVars.Require.IntValue)
{
// all maps should be shuffle.
shuffleStart = -1;
// randomly pool
for(int i = 0; i < nominationsToAdd; i++)
{
Nominations n;
g_aNominations.GetArray(i, n, sizeof(Nominations));
votePool.PushArray(n, sizeof(Nominations));
RemoveStringFromArray(g_aNextMapList, n.m_Map);
}
if (votePool.Length < voteSize && g_aNextMapList.Length == 0)
{
if (votePool.Length == 0)
{
LogMessage("No maps available for vote.");
return;
}
else
{
LogMessage("No enough maps to fill map list.");
voteSize = votePool.Length;
}
}
int count = 0;
while(votePool.Length < voteSize && count < g_aNextMapList.Length)
{
g_aNextMapList.GetString(count, map, 128);
count++;
Nominations n;
strcopy(n.m_Map, 128, map);
n.m_Owner = -1;
votePool.PushArray(n, sizeof(Nominations));
}
// Randomly menu
while (votePool.Length > 0)
{
Nominations n;
int i = RandomInt(0, votePool.Length - 1);
votePool.GetArray(i, n, sizeof(Nominations));
votePool.Erase(i);
AddMapItem(g_hVoteMenu, n.m_Map, g_ConVars.NameTag.BoolValue, g_ConVars.TierTag.BoolValue, !g_ConVars.DescTag.BoolValue, n.m_Owner);
}
}
else
{
// we just shuffle random maps
shuffleStart = nominationsToAdd - 1;
for(int i = 0; i < nominationsToAdd; i++)
{
Nominations n;
g_aNominations.GetArray(i, n, sizeof(Nominations));
AddMapItem(g_hVoteMenu, n.m_Map, g_ConVars.NameTag.BoolValue, g_ConVars.TierTag.BoolValue, !g_ConVars.DescTag.BoolValue, n.m_Owner);
RemoveStringFromArray(g_aNextMapList, map);
}
int i = nominationsToAdd;
int count = 0;
if (i < voteSize && g_aNextMapList.Length == 0)
{
if (i == 0)
{
LogMessage("No maps available for vote.");
return;
}
else
{
LogMessage("Not enough maps to fill map list.");
voteSize = i;
}
}
while(i < voteSize && count < g_aNextMapList.Length)
{
g_aNextMapList.GetString(count, map, 128);
count++;
AddMapItem(g_hVoteMenu, map, g_ConVars.NameTag.BoolValue, g_ConVars.TierTag.BoolValue, !g_ConVars.DescTag.BoolValue);
i++;
}
}
//g_aNominations.Clear();
AddExtendToMenu(g_hVoteMenu, when);
}
else
{
char map[128];
for(int i = 0; i < inputlist.Length; i++)
{
inputlist.GetString(i, map, 128);
if (IsMapValid(map))
AddMapItem(g_hVoteMenu, map, g_ConVars.NameTag.BoolValue, g_ConVars.TierTag.BoolValue, !g_ConVars.DescTag.BoolValue, GetNominationOwner(map));
else if (StrEqual(map, VOTE_DONTCHANGE))
g_hVoteMenu.AddItem(VOTE_DONTCHANGE, "Don't Change");
else if (StrEqual(map, VOTE_EXTEND))
g_hVoteMenu.AddItem(VOTE_EXTEND, "Extend Map");
}
delete inputlist;
}
if (5 <= GetMaxPageItems(GetMenuStyle(g_hVoteMenu)))
g_hVoteMenu.Pagination = MENU_NO_PAGINATION;
LogMessage("g_hVoteMenu -> shuffleStart = %d | count = %d", shuffleStart, g_hVoteMenu.ItemCount);
if (shuffleStart > -2)
{
// HACK
// if using shuffle
// we start at index 4 ~ 8
g_hVoteMenu.ShufflePerClient(shuffleStart + 4, 8);
}
g_hVoteMenu.DisplayVoteToAll(15);
Call_MapVoteStarted();
LogAction(-1, -1, "Voting for next map has started.");
tChatAll("%t", "mcr voting started");
}
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[128];
GetMapItem(menu, item_info[0][VOTEINFO_ITEM_INDEX], map, 128);
Call_MapVoteEnd(map, g_bPartyblock, GetMapNominator(map));
if (strcmp(map, VOTE_EXTEND, false) == 0)
{
g_iExtends++;
int timeLimit;
if (GetMapTimeLimit(timeLimit))
if (timeLimit > 0)
ExtendMapTimeLimit(1200);
tChatAll("%t", "mcr extend map", item_info[0][VOTEINFO_ITEM_VOTES], num_votes);
LogAction(-1, -1, "Voting for next map has finished. The current map has been extended.");
g_bHasVoteStarted = false;
CreateNextVote();
SetupTimeleftTimer();
}
else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
{
tChatAll("%t", "mcr dont change", item_info[0][VOTEINFO_ITEM_VOTES], num_votes);
LogAction(-1, -1, "Voting for next map has finished. 'No Change' was the winner");
g_bHasVoteStarted = false;
CreateNextVote();
SetupTimeleftTimer();
}
else
{
if (g_MapChange == MapChange_Instant)
{
g_bChangeMapInProgress = true;
CreateTimer(10.0 , Timer_ChangeMaprtv, _, TIMER_FLAG_NO_MAPCHANGE);
}
else if (g_MapChange == MapChange_RoundEnd)
{
g_bChangeMapAtRoundEnd = true;
FindConVar("mp_halftime").SetInt(0);
FindConVar("mp_timelimit").SetInt(0);
FindConVar("mp_maxrounds").SetInt(0);
FindConVar("mp_roundtime").SetInt(1);
}
SetEngineNextMap(map);
g_bHasVoteStarted = false;
g_bMapVoteCompleted = true;
tChatAll("%t", "mcr next map", map, item_info[0][VOTEINFO_ITEM_VOTES], num_votes);
if (g_ConVars.DescTag.BoolValue)
{
char desc[128];
GetDescEx(map, desc, 128, _, _, _, true);
SMUtils_SkipNextPrefix();
ChatAll("\x0E ➤ \x0E ➢ \x0E ➣ \x01 \x0A[\x05%s\x0A]", desc);
}
LogAction(-1, -1, "Voting for next map has finished. Nextmap: %s.", map);
}
// refunds
RefundAllCredits(map);
// reset
g_bPartyblock = false;
}
public Action Timer_ChangeMaprtv(Handle hTimer)
{
FindConVar("mp_halftime").SetInt(0);
FindConVar("mp_timelimit").SetInt(0);
FindConVar("mp_maxrounds").SetInt(0);
FindConVar("mp_roundtime").SetInt(1);
for(int client = 1; client <= MaxClients; ++client)
if (IsClientInGame(client))
if (IsPlayerAlive(client))
ForcePlayerSuicide(client);
CreateTimer(60.0, Timer_ChangeMap, 0, TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
public void Handler_MapVoteFinished(Menu menu, int num_votes, int num_clients, const int[][] client_info, int num_items, const int[][] item_info)
{
if (num_items > 1 && g_iRunoffCount < 1)
{
g_iRunoffCount++;
int highest_votes = item_info[0][VOTEINFO_ITEM_VOTES];
int required_percent = 50;
int required_votes = RoundToCeil(float(num_votes) * float(required_percent) / 100);
if (highest_votes == item_info[1][VOTEINFO_ITEM_VOTES])
{
g_bHasVoteStarted = false;
ArrayList mapList = new ArrayList(ByteCountToCells(128));
for(int i = 0; i < num_items; i++)
{
if (item_info[i][VOTEINFO_ITEM_VOTES] == highest_votes)
{
char map[128];
GetMapItem(menu, item_info[i][VOTEINFO_ITEM_INDEX], map, 128);
mapList.PushString(map);
}
else
break;
}
tChatAll("%t", "mcr tier", mapList.Length);
SetupWarningTimer(WarningType_Revote, view_as<MapChange>(g_MapChange), mapList);
return;
}
else if (highest_votes < required_votes)
{
g_bHasVoteStarted = false;
ArrayList mapList = new ArrayList(ByteCountToCells(128));
char map[128];
GetMapItem(menu, item_info[0][VOTEINFO_ITEM_INDEX], map, 128);
mapList.PushString(map);
for(int i = 1; i < num_items; i++)
{
if (mapList.Length < 2 || item_info[i][VOTEINFO_ITEM_VOTES] == item_info[i - 1][VOTEINFO_ITEM_VOTES])
{
GetMapItem(menu, item_info[i][VOTEINFO_ITEM_INDEX], map, 128);
mapList.PushString(map);
}
else
break;
}
tChatAll("%t", "mcr runoff", required_percent);
SetupWarningTimer(WarningType_Revote, view_as<MapChange>(g_MapChange), mapList);
return;
}
}
Handler_VoteFinishedGeneric(menu, num_votes, num_clients, client_info, num_items, item_info);
}
public int Handler_MapVoteMenu(Menu menu, MenuAction action, int param1, int param2)
{
switch(action)
{
case MenuAction_End:
{
g_hVoteMenu = null;
delete menu;
}
case MenuAction_Display:
{
char text[32];
FormatEx(text, 32, "%T \n ", "vote item title", param1);
SetPanelTitle(view_as<Handle>(param2), text);
}
case MenuAction_DisplayItem:
{
char map[128];
char buffer[128];
menu.GetItem(param2, map, 128, _, _, _, param1);
if (StrEqual(map, VOTE_EXTEND, false))
FormatEx(buffer, 128, "%T", "vote item extend", param1);
else if (StrEqual(map, VOTE_DONTCHANGE, false))
FormatEx(buffer, 128, "%T", "vote item dont change", param1);
else if (StrEqual(map, LINE_ONE, false))
FormatEx(buffer, 128, "%T", "LINE_ONE", param1);
else if (StrEqual(map, LINE_TWO, false))
FormatEx(buffer, 128, "%T", "LINE_TWO", param1);
if (buffer[0] != '\0')
return RedrawMenuItem(buffer);
}
case MenuAction_VoteCancel:
{
if (param1 == VoteCancel_NoVotes)
{
int count = GetMenuItemCount(menu);
int item;
char map[128];
do
{
int startInt = 0;
if (g_bBlockedSlots)
startInt = 2;
item = RandomInt(startInt, count - 1);
menu.GetItem(item, map, 128, _, _, _, -1);
}
while(strcmp(map, VOTE_EXTEND, false) == 0);
SetEngineNextMap(map);
g_bMapVoteCompleted = true;
}
g_bHasVoteStarted = false;
}
}
return 0;
}
public Action Timer_ChangeMap(Handle timer)
{
g_bChangeMapInProgress = false;
char map[128];
if (!GetNextMap(map, 128))
{
ThrowError("Timer_ChangeMap -> !GetNextMap");
return Plugin_Stop;
}
LogMessage("Timer_ChangeMap -> ForceChangeLevel -> %s", map);
ForceChangeLevel(map, "Map Vote");
return Plugin_Stop;
}
bool RemoveStringFromArray(ArrayList array, const char[] str)
{
int index = array.FindString(str);
if (index != -1)
{
array.Erase(index);
return true;
}
return false;
}
void CreateNextVote()
{
g_aNextMapList.Clear();
ArrayList tempMaps = g_aMapList.Clone();
ShuffleStringArray(tempMaps);
char map[128];
GetCurrentMap(map, 128);
RemoveStringFromArray(tempMaps, map);
for(int x = 0; x < tempMaps.Length; ++x)
{
tempMaps.GetString(x, map, 128);
// we remove big maps( >150 will broken fastdl .bz2), nice map, and only nominations, in cooldown, is not in certain times, requires min players.
if (IsBigMap(map) ||
IsNominateOnly(map) ||
IsAdminOnly(map) ||
IsVIPOnly(map) ||
GetCooldown(map) > 0 ||
IsCertainTimes(map) == false ||
GetMinPlayers(map) > 0 ||
IsDisabled(map))
{
tempMaps.Erase(x);
x--;
}
}
int players = GetRealPlayers();
for(int x = 0; x < tempMaps.Length; ++x)
{
tempMaps.GetString(x, map, 128);
// we remove map if player amount not match with configs
int max = GetMaxPlayers(map);
int min = GetMinPlayers(map);
if ((min != 0 && players < min) || (max != 0 && players > max))
{
tempMaps.Erase(x);
x--;
}
}
// check outside forward
for(int x = 0; x < tempMaps.Length; ++x)
{
tempMaps.GetString(x, map, 128);
if (!AllowInNextVotePool(map))
{
tempMaps.Erase(x);
x--;
}
}
int limit = (5 < tempMaps.Length ? 5 : tempMaps.Length);
for(int i = 0; i < limit; i++)
{
int b = RandomInt(0, tempMaps.Length - 1);
tempMaps.GetString(b, map, 128);
g_aNextMapList.PushString(map);
tempMaps.Erase(b);
}
delete tempMaps;
}
bool CanVoteStart()
{
if (g_bWaitingForVote || g_bHasVoteStarted)
return false;
return true;
}
bool InternalSetNextMap(const char[] map, int client, bool isCommand)
{
if (!Call_OnSetNextMap(map, client) || IsDisabled(map))
return false;
SetEngineNextMap(map);
Call_SetNextMapManually(map, client, isCommand);
g_bMapVoteCompleted = true;
RefundAllCredits(map);
return true;
}
NominateResult InternalNominateMap(const char[] map, bool force, int owner, bool partyblock)
{
if (!IsMapValid(map) || IsDisabled(map))
return NominateResult_InvalidMap;
if (!Call_OnNominateMap(map, owner, partyblock, false))
{
// rejected
return NominateResult_Reject;
}
for (int i = 0; i < g_aNominations.Length; i++)
{
Nominations n;
g_aNominations.GetArray(i, n, sizeof(Nominations));
if (strcmp(n.m_Map, map) == 0)
return NominateResult_AlreadyInVote;
}
if (g_aNominations.Length >= 5 && !force)
return NominateResult_VoteFull;
if (IsVIPOnly(map) && !IsClientVIP(owner))
return NominateResult_VIPOnly;
if (IsAdminOnly(map) && !IsClientAdmin(owner))
return NominateResult_AdminOnly;
if (GetCooldown(map) > 0)
return NominateResult_RecentlyPlayed;
if (!IsCertainTimes(map))
return NominateResult_CertainTimes;
int max = GetMaxPlayers(map);
if (max != 0 && GetRealPlayers() > max)
return NominateResult_MaxPlayers;
int min = GetMinPlayers(map);
if (min != 0 && GetRealPlayers() < min)
return NominateResult_MinPlayers;
if (g_pStore && Store_GetClientCredits(owner) < GetPrice(map))
return NominateResult_NoCredits;
if (g_pShop && MG_Shop_GetClientMoney(owner) < GetPrice(map))
return NominateResult_NoCredits;
if (g_bPartyblock)
return NominateResult_PartyBlock;
if (partyblock && owner)
{
if (!g_ConVars.BCState.BoolValue)
{
// ?
return NominateResult_PartyBlockDisabled;
}
int price = GetPrice(map, false, true); Nominations n;
if (!Call_OnNominatePrice(map, owner, price, partyblock))
{
// block
return NominateResult_NoCredits;
}
for (int i = 0; i < g_aNominations.Length; i++)
{
g_aNominations.GetArray(i, n, sizeof(Nominations));
price += n.m_Price;
PrintToServer("Foreach [%s] niminations list.", n.m_Map);
}
if (g_pStore && Store_GetClientCredits(owner) < price)
return NominateResult_NoCredits;
if (g_pShop && MG_Shop_GetClientMoney(owner) < price)
return NominateResult_NoCredits;
while (g_aNominations.Length > 0)
{
g_aNominations.GetArray(0, n, sizeof(Nominations));
g_aNominations.Erase(0);
Call_NominationsReset(n.m_Map, n.m_Owner, false, NominateResetReason_PartyBlock);
PrintToServer("Erase [%s] niminations list.", n.m_Map);
int refund = GetRefundCreditsByNomination(n);
char reason[128];
FormatEx(reason, sizeof(reason), "nomination-refund-partyblock-[%s]", n.m_Map);
if (ClientIsValid(n.m_Owner) && refund > 0)
if (g_pStore)
{
Store_SetClientCredits(n.m_Owner, Store_GetClientCredits(n.m_Owner)+refund, reason);
Chat(n.m_Owner, "%T", "mcr nominate fallback", n.m_Owner, n.m_Map, refund);
}
else if (g_pShop)
{
MG_Shop_ClientEarnMoney(n.m_Owner, refund, reason);
Chat(n.m_Owner, "%T", "mcr nominate fallback", n.m_Owner, n.m_Map, refund);
}