This repository has been archived by the owner on May 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmapmanager.sma
2069 lines (1827 loc) · 54.1 KB
/
mapmanager.sma
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 <amxmodx>
#if AMXX_VERSION_NUM < 183
#include <colorchat>
#endif
#define PLUGIN "Map Manager"
#define VERSION "2.5.61"
#define AUTHOR "Mistrick"
#pragma semicolon 1
///******** Settings ********///
#define FUNCTION_NEXTMAP //replace default nextmap
#define FUNCTION_RTV
#define FUNCTION_NOMINATION
//#define FUNCTION_NIGHTMODE
#define FUNCTION_NIGHTMODE_BLOCK_CMDS
#define FUNCTION_BLOCK_MAPS
#define FUNCTION_SOUND
#define SELECT_MAPS 5
#define PRE_START_TIME 5
#define VOTE_TIME 10
#define NOMINATED_MAPS_IN_VOTE 3
#define NOMINATED_MAPS_PER_PLAYER 3
#define BLOCK_MAP_COUNT 5
#define MIN_DENOMINATE_TIME 3
new const PREFIX[] = "^4[MapManager]";
///**************************///
#if BLOCK_MAP_COUNT <= 1
#undef FUNCTION_BLOCK_MAPS
#endif
enum (+=100)
{
TASK_CHECKTIME = 100,
TASK_SHOWTIMER,
TASK_TIMER,
TASK_VOTEMENU,
TASK_CHANGETODEFAULT,
TASK_CHECKNIGHT
};
enum _:MAP_INFO
{
m_MapName[32],
m_MinPlayers,
m_MaxPlayers,
m_BlockCount
};
enum _:VOTEMENU_INFO
{
v_MapName[32],
v_MapIndex,
v_Votes
};
enum _:NOMINATEDMAP_INFO
{
n_MapName[32],
n_Player,
n_MapIndex
};
enum _:BLOCKEDMAP_INFO
{
b_MapName[32],
b_Count
};
new Array: g_aMaps;
enum _:CVARS
{
CHANGE_TYPE,
START_VOTE_BEFORE_END,
SHOW_RESULT_TYPE,
SHOW_SELECTS,
START_VOTE_IN_NEW_ROUND,
FREEZE_IN_VOTE,
BLACK_SCREEN_IN_VOTE,
LAST_ROUND,
CHANGE_TO_DEDAULT,
DEFAULT_MAP,
EXTENDED_TYPE,
EXTENDED_MAX,
EXTENDED_TIME,
EXTENDED_ROUNDS,
#if defined FUNCTION_RTV
ROCK_MODE,
ROCK_PERCENT,
ROCK_PLAYERS,
ROCK_CHANGE_TYPE,
ROCK_DELAY,
#endif
#if defined FUNCTION_NOMINATION
NOMINATION_DONT_CLOSE_MENU,
NOMINATION_DEL_NON_CUR_ONLINE,
#endif
#if defined FUNCTION_NIGHTMODE
NIGHTMODE_TIME,
#endif
MAXROUNDS,
WINLIMIT,
TIMELIMIT,
FREEZETIME,
CHATTIME,
NEXTMAP,
ROUNDTIME
};
new const FILE_MAPS[] = "maps.ini";//configdir
#if defined FUNCTION_BLOCK_MAPS
new const FILE_BLOCKEDMAPS[] = "blockedmaps.ini";//datadir
#endif
#if defined FUNCTION_NIGHTMODE
new const FILE_NIGHTMAPS[] = "nightmaps.ini";//configdir
#endif
new g_pCvars[CVARS];
new g_iTeamScore[2];
new g_szCurrentMap[32];
new g_bVoteStarted;
new g_bVoteFinished;
new g_bNotUnlimitTime;
new g_eMenuItems[SELECT_MAPS + 1][VOTEMENU_INFO];
new g_iMenuItemsCount;
new g_iTotalVotes;
new g_iTimer;
new g_bPlayerVoted[33];
new g_iExtendedMax;
new g_bExtendMap;
new g_bStartVote;
new g_bChangedFreezeTime;
new Float:g_fOldTimeLimit;
new g_iForwardPreStartVote;
new g_iForwardStartVote;
new g_iForwardFinishVote;
#if defined FUNCTION_SOUND
new const g_szSound[][] =
{
"sound/fvox/one.wav", "sound/fvox/two.wav", "sound/fvox/three.wav", "sound/fvox/four.wav", "sound/fvox/five.wav",
"sound/fvox/six.wav", "sound/fvox/seven.wav", "sound/fvox/eight.wav", "sound/fvox/nine.wav", "sound/fvox/ten.wav"
};
#endif
#if defined FUNCTION_RTV
new g_bRockVoted[33];
new g_iRockVotes;
new g_bRockVote;
#endif
#if defined FUNCTION_NOMINATION
new Array:g_aNominatedMaps;
new g_iNominatedMaps[33];
new g_iLastDenominate[33];
new Array:g_aMapPrefixes;
new g_iMapPrefixesNum;
#endif
#if defined FUNCTION_BLOCK_MAPS
new g_iBlockedSize;
#endif
#if defined FUNCTION_NIGHTMODE
new Array:g_aNightMaps;
new g_bNightMode;
new g_bNightModeOneMap;
new g_bCurMapInNightMode;
new Float:g_fOldNightTimeLimit;
#if defined FUNCTION_NIGHTMODE_BLOCK_CMDS
new g_szBlockedCmds[][] =
{
"amx_map", "amx_votemap", "amx_mapmenu", "amx_votemapmenu"
};
#endif
#endif
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_cvar("mapm_version", VERSION, FCVAR_SERVER | FCVAR_SPONLY);
g_pCvars[CHANGE_TYPE] = register_cvar("mapm_change_type", "2");//0 - after end vote, 1 - in round end, 2 - after end map
g_pCvars[START_VOTE_BEFORE_END] = register_cvar("mapm_start_vote_before_end", "2");//minutes
g_pCvars[SHOW_RESULT_TYPE] = register_cvar("mapm_show_result_type", "1");//0 - disable, 1 - menu, 2 - hud
g_pCvars[SHOW_SELECTS] = register_cvar("mapm_show_selects", "1");//0 - disable, 1 - all
g_pCvars[START_VOTE_IN_NEW_ROUND] = register_cvar("mapm_start_vote_in_new_round", "0");//0 - disable, 1 - enable
g_pCvars[FREEZE_IN_VOTE] = register_cvar("mapm_freeze_in_vote", "0");//0 - disable, 1 - enable, if mapm_start_vote_in_new_round 1
g_pCvars[BLACK_SCREEN_IN_VOTE] = register_cvar("mapm_black_screen_in_vote", "0");//0 - disable, 1 - enable
g_pCvars[LAST_ROUND] = register_cvar("mapm_last_round", "0");//0 - disable, 1 - enable
g_pCvars[CHANGE_TO_DEDAULT] = register_cvar("mapm_change_to_default_map", "0");//minutes, 0 - disable
g_pCvars[DEFAULT_MAP] = register_cvar("mapm_default_map", "de_dust2");
g_pCvars[EXTENDED_TYPE] = register_cvar("mapm_extended_type", "0");//0 - minutes, 1 - rounds
g_pCvars[EXTENDED_MAX] = register_cvar("mapm_extended_map_max", "3");
g_pCvars[EXTENDED_TIME] = register_cvar("mapm_extended_time", "15");//minutes
g_pCvars[EXTENDED_ROUNDS] = register_cvar("mapm_extended_rounds", "3");//rounds
#if defined FUNCTION_RTV
g_pCvars[ROCK_MODE] = register_cvar("mapm_rtv_mode", "0");//0 - percents, 1 - players
g_pCvars[ROCK_PERCENT] = register_cvar("mapm_rtv_percent", "60");
g_pCvars[ROCK_PLAYERS] = register_cvar("mapm_rtv_players", "5");
g_pCvars[ROCK_CHANGE_TYPE] = register_cvar("mapm_rtv_change_type", "1");//0 - after vote, 1 - in round end
g_pCvars[ROCK_DELAY] = register_cvar("mapm_rtv_delay", "0");//minutes
#endif
#if defined FUNCTION_NOMINATION
g_pCvars[NOMINATION_DONT_CLOSE_MENU] = register_cvar("mapm_nom_dont_close_menu", "0");//0 - disable, 1 - enable
g_pCvars[NOMINATION_DEL_NON_CUR_ONLINE] = register_cvar("mapm_nom_del_noncur_online", "0");//0 - disable, 1 - enable
#endif
#if defined FUNCTION_NIGHTMODE
g_pCvars[NIGHTMODE_TIME] = register_cvar("mapm_night_time", "00:00 8:00");
#endif
g_pCvars[MAXROUNDS] = get_cvar_pointer("mp_maxrounds");
g_pCvars[WINLIMIT] = get_cvar_pointer("mp_winlimit");
g_pCvars[TIMELIMIT] = get_cvar_pointer("mp_timelimit");
g_pCvars[FREEZETIME] = get_cvar_pointer("mp_freezetime");
g_pCvars[ROUNDTIME] = get_cvar_pointer("mp_roundtime");
g_pCvars[NEXTMAP] = register_cvar("amx_nextmap", "", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY);
#if defined FUNCTION_NEXTMAP
g_pCvars[CHATTIME] = get_cvar_pointer("mp_chattime");
#endif
register_event("TeamScore", "Event_TeamScore", "a");
register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0");
#if defined FUNCTION_NEXTMAP
register_event("30", "Event_Intermisson", "a");
#endif
register_concmd("mapm_debug", "Commang_Debug", ADMIN_MAP);
register_concmd("mapm_startvote", "Command_StartVote", ADMIN_MAP);
register_concmd("mapm_stopvote", "Command_StopVote", ADMIN_MAP);
register_clcmd("say timeleft", "Command_Timeleft");
register_clcmd("say thetime", "Command_TheTime");
register_clcmd("votemap", "Command_Votemap");
#if defined FUNCTION_NEXTMAP
register_clcmd("say nextmap", "Command_Nextmap");
register_clcmd("say currentmap", "Command_CurrentMap");
#endif
#if defined FUNCTION_RTV
register_clcmd("say rtv", "Command_RockTheVote");
register_clcmd("say /rtv", "Command_RockTheVote");
#endif
#if defined FUNCTION_NOMINATION
register_clcmd("say", "Command_Say");
register_clcmd("say_team", "Command_Say");
register_clcmd("say maps", "Command_MapsList");
register_clcmd("say /maps", "Command_MapsList");
#endif
#if defined FUNCTION_NIGHTMODE && defined FUNCTION_NIGHTMODE_BLOCK_CMDS
for(new i; i < sizeof(g_szBlockedCmds); i++)
{
register_clcmd(g_szBlockedCmds[i], "Command_BlockedCmds");
}
#endif
g_iForwardPreStartVote = CreateMultiForward("mapmanager_prestartvote", ET_IGNORE);
g_iForwardStartVote = CreateMultiForward("mapmanager_startvote", ET_IGNORE);
g_iForwardFinishVote = CreateMultiForward("mapmanager_finishvote", ET_IGNORE);
register_menucmd(register_menuid("VoteMenu"), 1023, "VoteMenu_Handler");
set_task(10.0, "Task_CheckTime", TASK_CHECKTIME, .flags = "b");
#if defined FUNCTION_NIGHTMODE
set_task(60.0, "Task_CheckNight", TASK_CHECKNIGHT, .flags = "b");
#endif
}
#if defined FUNCTION_NIGHTMODE
public plugin_natives()
{
register_native("is_night_mode", "Native_IsNightMode");
}
public Native_IsNightMode()
{
return g_bNightMode;
}
#endif
#if defined FUNCTION_NIGHTMODE && defined FUNCTION_NIGHTMODE_BLOCK_CMDS
public Command_BlockedCmds(id)
{
if(g_bNightMode)
{
console_print(id, "%L", LANG_PLAYER, "MAPM_NIGHT_BLOCK_CMD");
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
#endif
public Command_Votemap(id)
{
return PLUGIN_HANDLED;
}
public Commang_Debug(id, flag)
{
if(~get_user_flags(id) & flag) return PLUGIN_HANDLED;
console_print(id, "^nLoaded maps:");
new eMapInfo[MAP_INFO], iSize = ArraySize(g_aMaps);
for(new i; i < iSize; i++)
{
ArrayGetArray(g_aMaps, i, eMapInfo);
console_print(id, "%3d %32s ^t%d^t%d^t%d", i, eMapInfo[m_MapName], eMapInfo[m_MinPlayers], eMapInfo[m_MaxPlayers], eMapInfo[m_BlockCount]);
}
#if defined FUNCTION_NOMINATION
new szPrefix[32];
console_print(id, "^nLoaded prefixes:");
for(new i; i < g_iMapPrefixesNum; i++)
{
ArrayGetString(g_aMapPrefixes, i, szPrefix, charsmax(szPrefix));
console_print(id, "%s", szPrefix);
}
#endif
return PLUGIN_HANDLED;
}
public Command_StartVote(id, flag)
{
if(~get_user_flags(id) & flag) return PLUGIN_HANDLED;
#if defined FUNCTION_NIGHTMODE
if(g_bNightMode && g_bNightModeOneMap)
{
console_print(id, "%L", LANG_PLAYER, "MAPM_NIGHT_BLOCK_CMD");
return PLUGIN_HANDLED;
}
#endif
if(get_pcvar_num(g_pCvars[START_VOTE_IN_NEW_ROUND]) == 0)
{
StartVote(id);
}
else
{
SetNewRoundVote();
client_print_color(0, print_team_default, "%s^1 %L", PREFIX, LANG_PLAYER, "MAPM_VOTE_WILL_BEGIN");
}
return PLUGIN_HANDLED;
}
public Command_StopVote(id, flag)
{
if(~get_user_flags(id) & flag) return PLUGIN_HANDLED;
if(g_bVoteStarted)
{
g_bVoteStarted = false;
#if defined FUNCTION_RTV
g_bRockVote = false;
g_iRockVotes = 0;
arrayset(g_bRockVoted, false, 33);
#endif
if(get_pcvar_num(g_pCvars[BLACK_SCREEN_IN_VOTE]))
{
SetBlackScreenFade(0);
}
if(g_bChangedFreezeTime)
{
set_pcvar_float(g_pCvars[FREEZETIME], get_pcvar_float(g_pCvars[FREEZETIME]) - float(PRE_START_TIME + VOTE_TIME + 1));
g_bChangedFreezeTime = false;
}
remove_task(TASK_VOTEMENU);
remove_task(TASK_SHOWTIMER);
remove_task(TASK_TIMER);
for(new i = 1; i <= 32; i++)
remove_task(TASK_VOTEMENU + i);
show_menu(0, 0, "^n", 1);
new szName[32];
if(id) get_user_name(id, szName, charsmax(szName));
else szName = "Server";
client_print_color(0, id, "%s^3 %L", PREFIX, LANG_PLAYER, "MAPM_CANCEL_VOTE", szName);
log_amx("%s canceled vote.", szName);
}
return PLUGIN_HANDLED;
}
public Command_Timeleft(id)
{
new iWinLimit = get_pcvar_num(g_pCvars[WINLIMIT]);
new iMaxRounds = get_pcvar_num(g_pCvars[MAXROUNDS]);
if((iWinLimit || iMaxRounds) && get_pcvar_num(g_pCvars[EXTENDED_TYPE]) == 1)
{
new szText[128], len;
len = formatex(szText, charsmax(szText), "%L ", LANG_PLAYER, "MAPM_TIME_TO_END");
if(iWinLimit)
{
new iLeftWins = iWinLimit - max(g_iTeamScore[0], g_iTeamScore[1]);
new szWins[16]; get_ending(iLeftWins, "MAPM_WIN1", "MAPM_WIN2", "MAPM_WIN3", szWins, charsmax(szWins));
len += formatex(szText[len], charsmax(szText) - len, "%d %L", iLeftWins, LANG_PLAYER, szWins);
}
if(iWinLimit && iMaxRounds)
{
len += formatex(szText[len], charsmax(szText) - len, " %L ", LANG_PLAYER, "MAPM_TIMELEFT_OR");
}
if(iMaxRounds)
{
new iLeftRounds = iMaxRounds - g_iTeamScore[0] - g_iTeamScore[1];
new szRounds[16]; get_ending(iLeftRounds, "MAPM_ROUND1", "MAPM_ROUND2", "MAPM_ROUND3", szRounds, charsmax(szRounds));
len += formatex(szText[len], charsmax(szText) - len, "%d %L", iLeftRounds, LANG_PLAYER, szRounds);
}
client_print_color(0, print_team_default, "%s^1 %s.", PREFIX, szText);
}
else
{
if (get_pcvar_num(g_pCvars[TIMELIMIT]))
{
new a = get_timeleft();
client_print_color(0, id, "%s^1 %L:^3 %d:%02d", PREFIX, LANG_PLAYER, "MAPM_TIME_TO_END", (a / 60), (a % 60));
}
else
{
client_print_color(0, print_team_default, "%s^1 %L", PREFIX, LANG_PLAYER, "MAPM_NO_TIMELIMIT");
}
}
}
public Command_TheTime(id)
{
new szTime[64]; get_time("%Y/%m/%d - %H:%M:%S", szTime, charsmax(szTime));
client_print_color(0, print_team_default, "%s^3 %L", PREFIX, LANG_PLAYER, "MAPM_THETIME", szTime);
}
#if defined FUNCTION_NEXTMAP
public Command_Nextmap(id)
{
if(g_bVoteFinished)
{
new szMap[32]; get_pcvar_string(g_pCvars[NEXTMAP], szMap, charsmax(szMap));
client_print_color(0, id, "%s^1 %L ^3%s^1.", PREFIX, LANG_PLAYER, "MAPM_NEXTMAP", szMap);
}
else
{
client_print_color(0, id, "%s^1 %L ^3%L^1.", PREFIX, LANG_PLAYER, "MAPM_NEXTMAP", LANG_PLAYER, "MAPM_NOT_SELECTED");
}
}
public Command_CurrentMap(id)
{
client_print_color(0, id, "%s^1 %L", PREFIX, LANG_PLAYER, "MAPM_CURRENT_MAP", g_szCurrentMap);
}
#endif
#if defined FUNCTION_RTV
public Command_RockTheVote(id)
{
if(g_bVoteFinished || g_bVoteStarted || g_bStartVote) return PLUGIN_HANDLED;
#if defined FUNCTION_NIGHTMODE
if(g_bNightMode && g_bNightModeOneMap)
{
client_print_color(id, print_team_default, "%s^1 %L", PREFIX, LANG_PLAYER, "MAPM_NIGHT_NOT_AVAILABLE");
return PLUGIN_HANDLED;
}
#endif
new iTime = get_pcvar_num(g_pCvars[ROCK_DELAY]) * 60 - (floatround(get_pcvar_float(g_pCvars[TIMELIMIT]) * 60.0) - get_timeleft());
if(iTime > 0)
{
client_print_color(id, print_team_default, "%s^1 %L", PREFIX, LANG_PLAYER, "MAPM_RTV_DELAY", iTime / 60, iTime % 60);
return PLUGIN_HANDLED;
}
if(!g_bRockVoted[id]) g_iRockVotes++;
new iVotes = (get_pcvar_num(g_pCvars[ROCK_MODE])) ? get_pcvar_num(g_pCvars[ROCK_PLAYERS]) - g_iRockVotes : floatround(get_players_num() * get_pcvar_num(g_pCvars[ROCK_PERCENT]) / 100.0, floatround_ceil) - g_iRockVotes;
if(iVotes <= 0)
{
g_bRockVote = true;
if(!get_pcvar_num(g_pCvars[START_VOTE_IN_NEW_ROUND]))
{
StartVote(0);
client_print_color(0, print_team_default, "%s^1 %L", PREFIX, LANG_PLAYER, "MAPM_RTV_START_VOTE");
}
else
{
SetNewRoundVote();
client_print_color(0, print_team_default, "%s^1 %L", PREFIX, LANG_PLAYER, "MAPM_START_VOTE_NEW_ROUND");
}
return PLUGIN_HANDLED;
}
new szVote[16]; get_ending(iVotes, "MAPM_VOTE1", "MAPM_VOTE2", "MAPM_VOTE3", szVote, charsmax(szVote));
if(!g_bRockVoted[id])
{
g_bRockVoted[id] = true;
new szName[33]; get_user_name(id, szName, charsmax(szName));
client_print_color(0, print_team_default, "%s^3 %L %L.", PREFIX, LANG_PLAYER, "MAPM_RTV_VOTED", szName, iVotes, LANG_PLAYER, szVote);
}
else
{
client_print_color(id, print_team_default, "%s^1 %L %L.", PREFIX, LANG_PLAYER, "MAPM_RTV_ALREADY_VOTED", iVotes, LANG_PLAYER, szVote);
}
return PLUGIN_HANDLED;
}
#endif
#if defined FUNCTION_NOMINATION
public Command_Say(id)
{
if(g_bVoteStarted || g_bVoteFinished) return;
#if defined FUNCTION_NIGHTMODE
if(g_bNightMode) return;
#endif
new szText[32]; read_args(szText, charsmax(szText));
remove_quotes(szText); trim(szText); strtolower(szText);
if(string_with_space(szText)) return;
new map_index = is_map_in_array(szText);
if(map_index)
{
NominateMap(id, szText, map_index - 1);
}
else if(strlen(szText) >= 4)
{
new szFormat[32], szPrefix[32], Array:aNominateList = ArrayCreate(), iArraySize;
for(new i; i < g_iMapPrefixesNum; i++)
{
ArrayGetString(g_aMapPrefixes, i, szPrefix, charsmax(szPrefix));
formatex(szFormat, charsmax(szFormat), "%s%s", szPrefix, szText);
map_index = 0;
while((map_index = find_similar_map(map_index, szFormat)))
{
ArrayPushCell(aNominateList, map_index - 1);
iArraySize++;
}
}
if(iArraySize == 1)
{
map_index = ArrayGetCell(aNominateList, 0);
new eMapInfo[MAP_INFO]; ArrayGetArray(g_aMaps, map_index, eMapInfo);
copy(szFormat, charsmax(szFormat), eMapInfo[m_MapName]);
NominateMap(id, szFormat, map_index);
}
else if(iArraySize > 1)
{
Show_NominationList(id, aNominateList, iArraySize);
}
ArrayDestroy(aNominateList);
}
}
public Show_NominationList(id, Array: array, size)
{
new szText[64]; formatex(szText, charsmax(szText), "%L", LANG_PLAYER, "MAPM_MENU_FAST_NOM");
new iMenu = menu_create(szText, "NominationList_Handler");
new eMapInfo[MAP_INFO], szString[64], map_index, nominate_index;
for(new i, szNum[8]; i < size; i++)
{
map_index = ArrayGetCell(array, i);
ArrayGetArray(g_aMaps, map_index, eMapInfo);
num_to_str(map_index, szNum, charsmax(szNum));
nominate_index = is_map_nominated(map_index);
if(eMapInfo[m_BlockCount])
{
formatex(szString, charsmax(szString), "%s[\r%d\d]", eMapInfo[m_MapName], eMapInfo[m_BlockCount]);
menu_additem(iMenu, szString, szNum, (1 << 31));
}
else if(nominate_index)
{
new eNomInfo[NOMINATEDMAP_INFO]; ArrayGetArray(g_aNominatedMaps, nominate_index - 1, eNomInfo);
if(id == eNomInfo[n_Player])
{
formatex(szString, charsmax(szString), "%s[\y*\w]", eMapInfo[m_MapName]);
menu_additem(iMenu, szString, szNum);
}
else
{
formatex(szString, charsmax(szString), "%s[\y*\d]", eMapInfo[m_MapName]);
menu_additem(iMenu, szString, szNum, (1 << 31));
}
}
else
{
menu_additem(iMenu, eMapInfo[m_MapName], szNum);
}
}
formatex(szText, charsmax(szText), "%L", LANG_PLAYER, "MAPM_MENU_BACK");
menu_setprop(iMenu, MPROP_BACKNAME, szText);
formatex(szText, charsmax(szText), "%L", LANG_PLAYER, "MAPM_MENU_NEXT");
menu_setprop(iMenu, MPROP_NEXTNAME, szText);
formatex(szText, charsmax(szText), "%L", LANG_PLAYER, "MAPM_MENU_EXIT");
menu_setprop(iMenu, MPROP_EXITNAME, szText);
menu_display(id, iMenu);
}
public NominationList_Handler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new szData[8], szName[32], iAccess, iCallback;
menu_item_getinfo(menu, item, iAccess, szData, charsmax(szData), szName, charsmax(szName), iCallback);
new map_index = str_to_num(szData);
trim_bracket(szName);
new is_map_nominated = NominateMap(id, szName, map_index);
if(is_map_nominated == 2 || get_pcvar_num(g_pCvars[NOMINATION_DONT_CLOSE_MENU]))
{
if(is_map_nominated == 1)
{
new szString[48]; formatex(szString, charsmax(szString), "%s[\y*\w]", szName);
menu_item_setname(menu, item, szString);
}
else if(is_map_nominated == 2)
{
menu_item_setname(menu, item, szName);
}
menu_display(id, menu);
}
else
{
menu_destroy(menu);
}
return PLUGIN_HANDLED;
}
NominateMap(id, map[32], map_index)
{
new eMapInfo[MAP_INFO]; ArrayGetArray(g_aMaps, map_index, eMapInfo);
#if defined FUNCTION_BLOCK_MAPS
if(eMapInfo[m_BlockCount])
{
client_print_color(id, print_team_default, "%s^1 %L", PREFIX, LANG_PLAYER, "MAPM_NOM_NOT_AVAILABLE_MAP");
return 0;
}
#endif
new eNomInfo[NOMINATEDMAP_INFO];
new szName[32]; get_user_name(id, szName, charsmax(szName));
new nominate_index = is_map_nominated(map_index);
if(nominate_index)
{
ArrayGetArray(g_aNominatedMaps, nominate_index - 1, eNomInfo);
if(id == eNomInfo[n_Player])
{
new iSysTime = get_systime();
if(g_iLastDenominate[id] + MIN_DENOMINATE_TIME <= iSysTime)
{
g_iLastDenominate[id] = iSysTime;
g_iNominatedMaps[id]--;
ArrayDeleteItem(g_aNominatedMaps, nominate_index - 1);
client_print_color(0, id, "%s^3 %L", PREFIX, LANG_PLAYER, "MAPM_NOM_REMOVE_NOM", szName, map);
return 2;
}
client_print_color(id, print_team_default, "%s^1 %L", PREFIX, LANG_PLAYER, "MAPM_NOM_SPAM");
return 0;
}
client_print_color(id, print_team_default, "%s^1 %L", PREFIX, LANG_PLAYER, "MAPM_NOM_ALREADY_NOM");
return 0;
}
if(g_iNominatedMaps[id] >= NOMINATED_MAPS_PER_PLAYER)
{
client_print_color(id, print_team_default, "%s^1 %L", PREFIX, LANG_PLAYER, "MAPM_NOM_CANT_NOM");
return 0;
}
eNomInfo[n_MapName] = map;
eNomInfo[n_Player] = id;
eNomInfo[n_MapIndex] = map_index;
ArrayPushArray(g_aNominatedMaps, eNomInfo);
g_iNominatedMaps[id]++;
if(get_pcvar_num(g_pCvars[NOMINATION_DEL_NON_CUR_ONLINE]))
{
new iMinPlayers = eMapInfo[m_MinPlayers] == 0 ? 1 : eMapInfo[m_MinPlayers];
client_print_color(0, id, "%s^3 %L", PREFIX, LANG_PLAYER, "MAPM_NOM_MAP2", szName, map, iMinPlayers, eMapInfo[m_MaxPlayers]);
}
else
{
client_print_color(0, id, "%s^3 %L", PREFIX, LANG_PLAYER, "MAPM_NOM_MAP", szName, map);
}
return 1;
}
public Command_MapsList(id)
{
#if defined FUNCTION_NIGHTMODE
if(g_bNightMode)
{
client_print_color(id, print_team_default, "%s^1 %L", PREFIX, LANG_PLAYER, "MAPM_NIGHT_NOT_AVAILABLE");
return;
}
#endif
Show_MapsListMenu(id);
}
Show_MapsListMenu(id)
{
new szText[64]; formatex(szText, charsmax(szText), "%L", LANG_PLAYER, "MAPM_MENU_MAP_LIST");
new iMenu = menu_create(szText, "MapsListMenu_Handler");
new eMapInfo[MAP_INFO], szString[48], iSize = ArraySize(g_aMaps);
for(new i, nominate_index; i < iSize; i++)
{
ArrayGetArray(g_aMaps, i, eMapInfo);
nominate_index = is_map_nominated(i);
if(eMapInfo[m_BlockCount])
{
formatex(szString, charsmax(szString), "%s[\r%d\d]", eMapInfo[m_MapName], eMapInfo[m_BlockCount]);
menu_additem(iMenu, szString, _, (1 << 31));
}
else if(nominate_index)
{
new eNomInfo[NOMINATEDMAP_INFO]; ArrayGetArray(g_aNominatedMaps, nominate_index - 1, eNomInfo);
if(id == eNomInfo[n_Player])
{
formatex(szString, charsmax(szString), "%s[\y*\w]", eMapInfo[m_MapName]);
menu_additem(iMenu, szString);
}
else
{
formatex(szString, charsmax(szString), "%s[\y*\d]", eMapInfo[m_MapName]);
menu_additem(iMenu, szString, _, (1 << 31));
}
}
else
{
menu_additem(iMenu, eMapInfo[m_MapName]);
}
}
formatex(szText, charsmax(szText), "%L", LANG_PLAYER, "MAPM_MENU_BACK");
menu_setprop(iMenu, MPROP_BACKNAME, szText);
formatex(szText, charsmax(szText), "%L", LANG_PLAYER, "MAPM_MENU_NEXT");
menu_setprop(iMenu, MPROP_NEXTNAME, szText);
formatex(szText, charsmax(szText), "%L", LANG_PLAYER, "MAPM_MENU_EXIT");
menu_setprop(iMenu, MPROP_EXITNAME, szText);
menu_display(id, iMenu);
}
public MapsListMenu_Handler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new szData[2], szName[32], iAccess, iCallback;
menu_item_getinfo(menu, item, iAccess, szData, charsmax(szData), szName, charsmax(szName), iCallback);
new map_index = item;
trim_bracket(szName);
new is_map_nominated = NominateMap(id, szName, map_index);
if(g_iNominatedMaps[id] < NOMINATED_MAPS_PER_PLAYER || get_pcvar_num(g_pCvars[NOMINATION_DONT_CLOSE_MENU]))
{
if(is_map_nominated == 1)
{
new szString[48]; formatex(szString, charsmax(szString), "%s[\y*\w]", szName);
menu_item_setname(menu, item, szString);
}
else if(is_map_nominated == 2)
{
menu_item_setname(menu, item, szName);
}
menu_display(id, menu, map_index / 7);
}
else
{
menu_destroy(menu);
}
return PLUGIN_HANDLED;
}
#endif
public client_putinserver(id)
{
if(!is_user_bot(id) && !is_user_hltv(id))
remove_task(TASK_CHANGETODEFAULT);
}
public client_disconnect(id)
{
remove_task(id + TASK_VOTEMENU);
#if defined FUNCTION_RTV
if(g_bRockVoted[id])
{
g_bRockVoted[id] = false;
g_iRockVotes--;
}
#endif
#if defined FUNCTION_NOMINATION
if(g_iNominatedMaps[id])
{
clear_nominated_maps(id);
}
#endif
#if defined FUNCTION_NIGHTMODE
if(!g_bNightMode) set_task(1.0, "Task_DelayedChangeToDelault");
#else
set_task(1.0, "Task_DelayedChangeToDelault");
#endif
}
public Task_DelayedChangeToDelault()
{
new Float:fChangeTime = get_pcvar_float(g_pCvars[CHANGE_TO_DEDAULT]);
if(fChangeTime > 0.0 && get_players_num() == 0)
{
set_task(fChangeTime * 60.0, "Task_ChangeToDefault", TASK_CHANGETODEFAULT);
}
}
public Task_ChangeToDefault()
{
new szMapName[32]; get_pcvar_string(g_pCvars[DEFAULT_MAP], szMapName, charsmax(szMapName));
if(get_players_num() == 0 && is_map_valid(szMapName) && !equali(szMapName, g_szCurrentMap))
{
log_amx("Map changed to default[%s]", szMapName);
set_pcvar_string(g_pCvars[NEXTMAP], szMapName);
Intermission();
}
}
public plugin_end()
{
#if defined FUNCTION_NIGHTMODE
if(g_fOldNightTimeLimit > 0.0)
{
set_pcvar_float(g_pCvars[TIMELIMIT], g_fOldNightTimeLimit);
}
#endif
if(g_bChangedFreezeTime)
{
set_pcvar_float(g_pCvars[FREEZETIME], get_pcvar_float(g_pCvars[FREEZETIME]) - float(PRE_START_TIME + VOTE_TIME + 1));
}
if(g_fOldTimeLimit > 0.0)
{
set_pcvar_float(g_pCvars[TIMELIMIT], g_fOldTimeLimit);
}
if(g_iExtendedMax)
{
if(get_pcvar_num(g_pCvars[EXTENDED_TYPE]) == 0)
{
set_pcvar_float(g_pCvars[TIMELIMIT], get_pcvar_float(g_pCvars[TIMELIMIT]) - float(g_iExtendedMax * get_pcvar_num(g_pCvars[EXTENDED_TIME])));
}
else
{
new iWinLimit = get_pcvar_num(g_pCvars[WINLIMIT]);
if(iWinLimit > 0)
{
set_pcvar_num(g_pCvars[WINLIMIT], iWinLimit - get_pcvar_num(g_pCvars[EXTENDED_ROUNDS]) * g_iExtendedMax);
}
new iMaxRounds = get_pcvar_num(g_pCvars[MAXROUNDS]);
if(iMaxRounds > 0)
{
set_pcvar_num(g_pCvars[MAXROUNDS], iMaxRounds - get_pcvar_num(g_pCvars[EXTENDED_ROUNDS]) * g_iExtendedMax);
}
}
}
}
public plugin_cfg()
{
new filepath[256]; get_localinfo("amxx_configsdir", filepath, charsmax(filepath));
add(filepath, charsmax(filepath), "/mapmanager.cfg");
if(file_exists(filepath))
{
server_cmd("exec %s", filepath);
server_exec();
}
g_aMaps = ArrayCreate(MAP_INFO);
#if defined FUNCTION_NOMINATION
g_aNominatedMaps = ArrayCreate(NOMINATEDMAP_INFO);
g_aMapPrefixes = ArrayCreate(32);
#endif
if( is_plugin_loaded("Nextmap Chooser") > -1 )
{
pause("cd", "mapchooser.amxx");
log_amx("MapManager: mapchooser.amxx has been stopped.");
}
#if defined FUNCTION_NEXTMAP
if( is_plugin_loaded("NextMap") > -1 )
{
pause("cd", "nextmap.amxx");
log_amx("MapManager: nextmap.amxx has been stopped.");
}
#endif
LoadMapsFromFile();
#if defined FUNCTION_NIGHTMODE
LoadNightMaps();
#endif
new Float:fChangeTime = get_pcvar_float(g_pCvars[CHANGE_TO_DEDAULT]);
if(fChangeTime > 0.0)
{
set_task(fChangeTime * 60.0, "Task_ChangeToDefault", TASK_CHANGETODEFAULT);
}
register_dictionary("mapmanager.txt");
}
LoadMapsFromFile()
{
new szDir[128], szFile[128];
get_mapname(g_szCurrentMap, charsmax(g_szCurrentMap));
#if defined FUNCTION_BLOCK_MAPS
get_localinfo("amxx_datadir", szDir, charsmax(szDir));
formatex(szFile, charsmax(szFile), "%s/%s", szDir, FILE_BLOCKEDMAPS);
new Array:aBlockedMaps = ArrayCreate(BLOCKEDMAP_INFO);
new eBlockedInfo[BLOCKEDMAP_INFO];
if(file_exists(szFile))
{
new szTemp[128]; formatex(szTemp, charsmax(szTemp), "%s/temp.ini", szDir);
new iFile = fopen(szFile, "rt");
new iTemp = fopen(szTemp, "wt");
new szBuffer[42], szMapName[32], szCount[8], iCount;
while(!feof(iFile))
{
fgets(iFile, szBuffer, charsmax(szBuffer));
parse(szBuffer, szMapName, charsmax(szMapName), szCount, charsmax(szCount));
if(!is_map_valid(szMapName) || is_map_blocked(aBlockedMaps, szMapName) || equali(szMapName, g_szCurrentMap)) continue;
iCount = str_to_num(szCount) - 1;
if(iCount <= 0) continue;
if(iCount > BLOCK_MAP_COUNT)
{
fprintf(iTemp, "^"%s^" ^"%d^"^n", szMapName, BLOCK_MAP_COUNT);
iCount = BLOCK_MAP_COUNT;
}
else
{
fprintf(iTemp, "^"%s^" ^"%d^"^n", szMapName, iCount);
}
formatex(eBlockedInfo[b_MapName], charsmax(eBlockedInfo[b_MapName]), szMapName);
eBlockedInfo[b_Count] = iCount;
ArrayPushArray(aBlockedMaps, eBlockedInfo);
}
fprintf(iTemp, "^"%s^" ^"%d^"^n", g_szCurrentMap, BLOCK_MAP_COUNT);