Pending Map should no longer be shown when mapvotes are disabled.
Removed tf2 include from mapchooser.
Moved sm_setnextmap to mapchooser and made it block the end of map vote.
3 * =============================================================================
4 * SourceMod Mapchooser Plugin
5 * Creates a map vote at appropriate times, setting sm_nextmap to the winning
8 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
9 * =============================================================================
11 * This program is free software; you can redistribute it and/or modify it under
12 * the terms of the GNU General Public License, version 3.0, as published by the
13 * Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License along with
21 * this program. If not, see <http://www.gnu.org/licenses/>.
23 * As a special exception, AlliedModders LLC gives you permission to link the
24 * code of this program (as well as its derivative works) to "Half-Life 2," the
25 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
26 * by the Valve Corporation. You must obey the GNU General Public License in
27 * all respects for all other code used. Additionally, AlliedModders LLC grants
28 * this exception to all derivative works. AlliedModders LLC defines further
29 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
30 * or <http://www.sourcemod.net/license.php>.
40 public Plugin:myinfo =
43 author = "AlliedModders LLC",
44 description = "Automated Map Voting",
45 version = SOURCEMOD_VERSION,
46 url = "http://www.sourcemod.net/"
50 new Handle:g_Cvar_Winlimit = INVALID_HANDLE;
51 new Handle:g_Cvar_Maxrounds = INVALID_HANDLE;
52 new Handle:g_Cvar_Fraglimit = INVALID_HANDLE;
53 new Handle:g_Cvar_Bonusroundtime = INVALID_HANDLE;
56 new Handle:g_Cvar_StartTime = INVALID_HANDLE;
57 new Handle:g_Cvar_StartRounds = INVALID_HANDLE;
58 new Handle:g_Cvar_StartFrags = INVALID_HANDLE;
59 new Handle:g_Cvar_ExtendTimeStep = INVALID_HANDLE;
60 new Handle:g_Cvar_ExtendRoundStep = INVALID_HANDLE;
61 new Handle:g_Cvar_ExtendFragStep = INVALID_HANDLE;
62 new Handle:g_Cvar_ExcludeMaps = INVALID_HANDLE;
63 new Handle:g_Cvar_IncludeMaps = INVALID_HANDLE;
64 new Handle:g_Cvar_NoVoteMode = INVALID_HANDLE;
65 new Handle:g_Cvar_Extend = INVALID_HANDLE;
66 new Handle:g_Cvar_DontChange = INVALID_HANDLE;
67 new Handle:g_Cvar_EndOfMapVote = INVALID_HANDLE;
68 new Handle:g_Cvar_VoteDuration = INVALID_HANDLE;
70 new Handle:g_VoteTimer = INVALID_HANDLE;
71 new Handle:g_RetryTimer = INVALID_HANDLE;
74 new Handle:g_MapList = INVALID_HANDLE;
75 new Handle:g_NominateList = INVALID_HANDLE;
76 new Handle:g_NominateOwners = INVALID_HANDLE;
77 new Handle:g_OldMapList = INVALID_HANDLE;
78 new Handle:g_NextMapList = INVALID_HANDLE;
79 new Handle:g_VoteMenu = INVALID_HANDLE;
83 new bool:g_HasVoteStarted;
84 new bool:g_WaitingForVote;
85 new bool:g_MapVoteCompleted;
86 new bool:g_ChangeMapAtRoundEnd;
87 new g_mapFileSerial = -1;
89 new g_NominateCount = 0;
90 new MapChange:g_ChangeTime;
92 new Handle:g_NominationsResetForward = INVALID_HANDLE;
94 /* Upper bound of how many team there could be */
96 new g_winCount[MAXTEAMS];
98 #define VOTE_EXTEND "##extend##"
99 #define VOTE_DONTCHANGE "##dontchange##"
101 public OnPluginStart()
103 LoadTranslations("mapchooser.phrases");
104 LoadTranslations("common.phrases");
106 new arraySize = ByteCountToCells(33);
107 g_MapList = CreateArray(arraySize);
108 g_NominateList = CreateArray(arraySize);
109 g_NominateOwners = CreateArray(1);
110 g_OldMapList = CreateArray(arraySize);
111 g_NextMapList = CreateArray(arraySize);
113 g_Cvar_EndOfMapVote = CreateConVar("sm_mapvote_endvote", "1", "Specifies if MapChooser should run an end of map vote", _, true, 0.0, true, 1.0);
115 g_Cvar_StartTime = CreateConVar("sm_mapvote_start", "3.0", "Specifies when to start the vote based on time remaining.", _, true, 1.0);
116 g_Cvar_StartRounds = CreateConVar("sm_mapvote_startround", "2.0", "Specifies when to start the vote based on rounds remaining. Use 0 on TF2 to start vote during bonus round time", _, true, 0.0);
117 g_Cvar_StartFrags = CreateConVar("sm_mapvote_startfrags", "5.0", "Specifies when to start the vote base on frags remaining.", _, true, 1.0);
118 g_Cvar_ExtendTimeStep = CreateConVar("sm_extendmap_timestep", "15", "Specifies how much many more minutes each extension makes", _, true, 5.0);
119 g_Cvar_ExtendRoundStep = CreateConVar("sm_extendmap_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 1.0);
120 g_Cvar_ExtendFragStep = CreateConVar("sm_extendmap_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0);
121 g_Cvar_ExcludeMaps = CreateConVar("sm_mapvote_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0);
122 g_Cvar_IncludeMaps = CreateConVar("sm_mapvote_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 6.0);
123 g_Cvar_NoVoteMode = CreateConVar("sm_mapvote_novote", "1", "Specifies whether or not MapChooser should pick a map if no votes are received.", _, true, 0.0, true, 1.0);
124 g_Cvar_Extend = CreateConVar("sm_mapvote_extend", "0", "Number of extensions allowed each map.", _, true, 0.0);
125 g_Cvar_DontChange = CreateConVar("sm_mapvote_dontchange", "1", "Specifies if a 'Don't Change' option should be added to early votes", _, true, 0.0);
126 g_Cvar_VoteDuration = CreateConVar("sm_mapvote_voteduration", "20", "Specifies how long the mapvote should be available for.", _, true, 5.0, true, 25.0);
128 RegAdminCmd("sm_mapvote", Command_Mapvote, ADMFLAG_CHANGEMAP, "sm_mapvote - Forces MapChooser to attempt to run a map vote now.");
129 RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap <map>");
131 g_Cvar_Winlimit = FindConVar("mp_winlimit");
132 g_Cvar_Maxrounds = FindConVar("mp_maxrounds");
133 g_Cvar_Fraglimit = FindConVar("mp_fraglimit");
134 g_Cvar_Bonusroundtime = FindConVar("mp_bonusroundtime");
136 if (g_Cvar_Winlimit != INVALID_HANDLE || g_Cvar_Maxrounds != INVALID_HANDLE)
138 HookEvent("round_end", Event_RoundEnd);
139 HookEventEx("teamplay_win_panel", Event_TeamPlayWinPanel);
140 HookEventEx("teamplay_restart_round", Event_TFRestartRound);
143 if (g_Cvar_Fraglimit != INVALID_HANDLE)
145 HookEvent("player_death", Event_PlayerDeath);
148 AutoExecConfig(true, "mapchooser");
150 //Change the mp_bonusroundtime max so that we have time to display the vote
151 //If you display a vote during bonus time good defaults are 17 vote duration and 19 mp_bonustime
152 if (g_Cvar_Bonusroundtime != INVALID_HANDLE)
154 SetConVarBounds(g_Cvar_Bonusroundtime, ConVarBound_Upper, true, 30.0);
157 g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
160 public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
162 RegPluginLibrary("mapchooser");
164 CreateNative("NominateMap", Native_NominateMap);
165 CreateNative("InitiateMapChooserVote", Native_InitiateVote);
166 CreateNative("CanMapChooserStartVote", Native_CanVoteStart);
167 CreateNative("HasEndOfMapVoteFinished", Native_CheckVoteDone);
168 CreateNative("GetExcludeMapList", Native_GetExcludeMapList);
173 public OnConfigsExecuted()
175 if (ReadMapList(g_MapList,
178 MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER)
182 if (g_mapFileSerial == -1)
184 LogError("Unable to create a valid map list.");
189 SetupTimeleftTimer();
195 g_MapVoteCompleted = false;
198 ClearArray(g_NominateList);
199 ClearArray(g_NominateOwners);
201 for (new i=0; i<MAXTEAMS; i++)
207 /* Check if mapchooser will attempt to start mapvote during bonus round time - TF2 Only */
208 if ((g_Cvar_Bonusroundtime != INVALID_HANDLE) && !GetConVarInt(g_Cvar_StartRounds))
210 if (GetConVarFloat(g_Cvar_Bonusroundtime) <= GetConVarFloat(g_Cvar_VoteDuration))
212 LogError("Warning - Bonus Round Time shorter than Vote Time. Votes during bonus round may not have time to complete");
219 g_HasVoteStarted = false;
220 g_WaitingForVote = false;
222 g_VoteTimer = INVALID_HANDLE;
223 g_RetryTimer = INVALID_HANDLE;
226 GetCurrentMap(map, sizeof(map));
227 PushArrayString(g_OldMapList, map);
229 if (GetArraySize(g_OldMapList) > GetConVarInt(g_Cvar_ExcludeMaps))
231 RemoveFromArray(g_OldMapList, 0);
235 public OnClientDisconnect(client)
237 new index = FindValueInArray(g_NominateOwners, client);
244 new String:oldmap[33];
245 GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap));
246 Call_StartForward(g_NominationsResetForward);
247 Call_PushString(oldmap);
248 Call_PushCell(GetArrayCell(g_NominateOwners, index));
251 RemoveFromArray(g_NominateOwners, index);
252 RemoveFromArray(g_NominateList, index);
256 public Action:Command_SetNextmap(client, args)
260 ReplyToCommand(client, "[SM] Usage: sm_setnextmap <map>");
261 return Plugin_Handled;
265 GetCmdArg(1, map, sizeof(map));
267 if (!IsMapValid(map))
269 ReplyToCommand(client, "[SM] %t", "Map was not found", map);
270 return Plugin_Handled;
273 ShowActivity(client, "%t", "Changed Next Map", map);
274 LogMessage("\"%L\" changed nextmap to \"%s\"", client, map);
277 g_MapVoteCompleted = true;
279 return Plugin_Handled;
282 public OnMapTimeLeftChanged()
284 if (GetArraySize(g_MapList))
286 SetupTimeleftTimer();
293 if (GetMapTimeLeft(time) && time > 0)
295 new startTime = GetConVarInt(g_Cvar_StartTime) * 60;
296 if (time - startTime < 0 && GetConVarBool(g_Cvar_EndOfMapVote) && !g_MapVoteCompleted && !g_HasVoteStarted)
298 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
302 if (g_VoteTimer != INVALID_HANDLE)
304 KillTimer(g_VoteTimer);
305 g_VoteTimer = INVALID_HANDLE;
308 g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE);
313 public Action:Timer_StartMapVote(Handle:timer)
315 if (!GetArraySize(g_MapList) || !GetConVarBool(g_Cvar_EndOfMapVote) || g_MapVoteCompleted || g_HasVoteStarted)
320 if (timer == g_RetryTimer)
322 g_RetryTimer = INVALID_HANDLE;
326 g_VoteTimer = INVALID_HANDLE;
329 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
334 public Event_TFRestartRound(Handle:event, const String:name[], bool:dontBroadcast)
336 /* Game got restarted - reset our round count tracking */
340 public Event_TeamPlayWinPanel(Handle:event, const String:name[], bool:dontBroadcast)
342 if (g_ChangeMapAtRoundEnd)
344 g_ChangeMapAtRoundEnd = false;
345 CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
348 if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted || !GetConVarBool(g_Cvar_EndOfMapVote))
353 new bluescore = GetEventInt(event, "blue_score");
354 new redscore = GetEventInt(event, "red_score");
356 if(GetEventInt(event, "round_complete") == 1)
358 switch(GetEventInt(event, "winning_team"))
362 CheckWinLimit(bluescore);
366 CheckWinLimit(redscore);
368 //We need to do nothing on winning_team == 0 this indicates stalemate.
376 CheckMaxRounds(g_TotalRounds);
379 /* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */
380 public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
382 if (g_ChangeMapAtRoundEnd)
384 g_ChangeMapAtRoundEnd = false;
385 CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
388 if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted)
393 new winner = GetEventInt(event, "winner");
395 if (winner == 0 || winner == 1 || !GetConVarBool(g_Cvar_EndOfMapVote))
400 if (winner >= MAXTEAMS)
402 SetFailState("Mod exceed maximum team count - Please file a bug report.");
407 g_winCount[winner]++;
409 CheckWinLimit(g_winCount[winner]);
410 CheckMaxRounds(g_TotalRounds);
413 public CheckWinLimit(winner_score)
415 if (g_Cvar_Winlimit != INVALID_HANDLE)
417 new winlimit = GetConVarInt(g_Cvar_Winlimit);
420 if (winner_score >= (winlimit - GetConVarInt(g_Cvar_StartRounds)))
422 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
428 public CheckMaxRounds(roundcount)
430 if (g_Cvar_Maxrounds != INVALID_HANDLE)
432 new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
435 if (roundcount >= (maxrounds - GetConVarInt(g_Cvar_StartRounds)))
437 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
443 public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
445 if (!GetArraySize(g_MapList) || g_Cvar_Fraglimit == INVALID_HANDLE || g_HasVoteStarted)
450 if (!GetConVarInt(g_Cvar_Fraglimit) || !GetConVarBool(g_Cvar_EndOfMapVote))
455 new fragger = GetClientOfUserId(GetEventInt(event, "attacker"));
456 if (fragger && GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags)))
458 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
462 public Action:Command_Mapvote(client, args)
464 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
466 return Plugin_Handled;
469 InitiateVote(MapChange:when, Handle:inputlist)
476 g_WaitingForVote = true;
478 if (IsVoteInProgress())
480 // Can't start a vote, try again in 5 seconds.
481 g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE);
487 g_WaitingForVote = false;
489 g_HasVoteStarted = true;
490 g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
491 SetMenuTitle(g_VoteMenu, "Vote Nextmap");
492 SetVoteResultCallback(g_VoteMenu, Handler_MapVoteFinished);
495 * TODO: Make a proper decision on when to clear the nominations list.
496 * Currently it clears when used, and stays if an external list is provided.
497 * Is this the right thing to do? External lists will probably come from places
498 * like sm_mapvote from the adminmenu in the future.
503 /* No input given - User our internal nominations and maplist */
504 if (inputlist == INVALID_HANDLE)
506 new nominateCount = GetArraySize(g_NominateList);
507 new voteSize = GetConVarInt(g_Cvar_IncludeMaps);
509 /* Smaller of the two - It should be impossible for nominations to exceed the size though (cvar changed mid-map?) */
510 new nominationsToAdd = nominateCount >= voteSize ? voteSize : nominateCount;
513 for (new i=0; i<nominationsToAdd; i++)
515 GetArrayString(g_NominateList, i, map, sizeof(map));
516 AddMenuItem(g_VoteMenu, map, map);
518 /* Notify Nominations that this map is now free */
519 Call_StartForward(g_NominationsResetForward);
520 Call_PushString(map);
521 Call_PushCell(GetArrayCell(g_NominateOwners, i));
525 /* Clear out the rest of the nominations array */
526 for (new i=nominationsToAdd; i<nominateCount; i++)
528 GetArrayString(g_NominateList, i, map, sizeof(map));
530 /* Notify Nominations that this map is now free */
531 Call_StartForward(g_NominationsResetForward);
532 Call_PushString(map);
533 Call_PushCell(GetArrayCell(g_NominateOwners, i));
537 /* There should currently be 'nominationsToAdd' unique maps in the vote */
539 new i = nominationsToAdd;
541 new availableMaps = GetArraySize(g_NextMapList);
545 GetArrayString(g_NextMapList, count, map, sizeof(map));
548 //Check if this map is in the nominate list (and thus already in the vote) */
549 if (FindStringInArray(g_NominateList, map) == -1)
551 /* Insert the map and increment our count */
552 AddMenuItem(g_VoteMenu, map, map);
556 if (count >= availableMaps)
558 //Run out of maps, this will have to do.
563 /* Wipe out our nominations list - Nominations have already been informed of this */
564 ClearArray(g_NominateOwners);
565 ClearArray(g_NominateList);
567 else //We were given a list of maps to start the vote with
569 new size = GetArraySize(inputlist);
571 for (new i=0; i<size; i++)
573 GetArrayString(inputlist, i, map, sizeof(map));
577 AddMenuItem(g_VoteMenu, map, map);
582 /* Do we add any special items? */
583 if ((when == MapChange_Instant || when == MapChange_RoundEnd) && GetConVarBool(g_Cvar_DontChange))
585 AddMenuItem(g_VoteMenu, VOTE_DONTCHANGE, "Don't Change");
587 else if (GetConVarBool(g_Cvar_Extend) && g_Extends < GetConVarInt(g_Cvar_Extend))
589 AddMenuItem(g_VoteMenu, VOTE_EXTEND, "Extend Map");
592 new voteDuration = GetConVarInt(g_Cvar_VoteDuration);
594 SetMenuExitButton(g_VoteMenu, false);
595 VoteMenuToAll(g_VoteMenu, voteDuration);
597 LogMessage("Voting for next map has started.");
598 PrintToChatAll("[SM] %t", "Nextmap Voting Started");
601 public Handler_MapVoteFinished(Handle:menu,
604 const client_info[][2],
606 const item_info[][2])
610 LogError("No Votes recorded yet Advanced callback fired - Tell pRED* to fix this");
615 GetMenuItem(menu, item_info[0][VOTEINFO_ITEM_INDEX], map, sizeof(map));
617 if (strcmp(map, VOTE_EXTEND, false) == 0)
622 if (GetMapTimeLimit(time))
626 ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60);
630 if (g_Cvar_Winlimit != INVALID_HANDLE)
632 new winlimit = GetConVarInt(g_Cvar_Winlimit);
635 SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep));
639 if (g_Cvar_Maxrounds != INVALID_HANDLE)
641 new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
644 SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep));
648 if (g_Cvar_Fraglimit != INVALID_HANDLE)
650 new fraglimit = GetConVarInt(g_Cvar_Fraglimit);
653 SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep));
657 PrintToChatAll("[SM] %t", "Current Map Extended", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
658 LogMessage("Voting for next map has finished. The current map has been extended.");
660 // We extended, so we'll have to vote again.
661 g_HasVoteStarted = false;
663 SetupTimeleftTimer();
666 else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
668 PrintToChatAll("[SM] %t", "Current Map Stays", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
669 LogMessage("Voting for next map has finished. 'No Change' was the winner");
671 g_HasVoteStarted = false;
673 SetupTimeleftTimer();
677 if (g_ChangeTime == MapChange_MapEnd)
681 else if (g_ChangeTime == MapChange_Instant)
684 CreateDataTimer(2.0, Timer_ChangeMap, data);
685 WritePackString(data, map);
687 else // MapChange_RoundEnd
690 g_ChangeMapAtRoundEnd = true;
693 g_HasVoteStarted = false;
694 g_MapVoteCompleted = true;
696 PrintToChatAll("[SM] %t", "Nextmap Voting Finished", map, RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
697 LogMessage("Voting for next map has finished. Nextmap: %s.", map);
701 public Handler_MapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
707 g_VoteMenu = INVALID_HANDLE;
711 case MenuAction_Display:
713 decl String:buffer[255];
714 Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1);
716 new Handle:panel = Handle:param2;
717 SetPanelTitle(panel, buffer);
720 case MenuAction_DisplayItem:
722 if (GetMenuItemCount(menu) - 1 == param2)
724 decl String:map[64], String:buffer[255];
725 GetMenuItem(menu, param2, map, sizeof(map));
726 if (strcmp(map, VOTE_EXTEND, false) == 0)
728 Format(buffer, sizeof(buffer), "%T", "Extend Map", param1);
729 return RedrawMenuItem(buffer);
731 else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
733 Format(buffer, sizeof(buffer), "%T", "Dont Change", param1);
734 return RedrawMenuItem(buffer);
739 case MenuAction_VoteCancel:
741 // If we receive 0 votes, pick at random.
742 if (param1 == VoteCancel_NoVotes && GetConVarBool(g_Cvar_NoVoteMode))
744 new count = GetMenuItemCount(menu);
745 new item = GetRandomInt(0, count - 1);
747 GetMenuItem(menu, item, map, sizeof(map));
749 while (strcmp(map, VOTE_EXTEND, false) == 0)
751 item = GetRandomInt(0, count - 1);
752 GetMenuItem(menu, item, map, sizeof(map));
759 // We were actually cancelled. I guess we do nothing.
767 public Action:Timer_ChangeMap(Handle:hTimer, Handle:dp)
771 if (dp == INVALID_HANDLE)
773 if (!GetNextMap(map, sizeof(map)))
775 //No passed map and no set nextmap. fail!
782 ReadPackString(dp, map, sizeof(map));
785 ForceChangeLevel(map, "Map Vote");
792 if(g_NextMapList != INVALID_HANDLE)
794 ClearArray(g_NextMapList);
798 new index, Handle:tempMaps = CloneArray(g_MapList);
800 GetCurrentMap(map, sizeof(map));
801 index = FindStringInArray(tempMaps, map);
804 RemoveFromArray(tempMaps, index);
807 if (GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps))
809 for (new i = 0; i < GetArraySize(g_OldMapList); i++)
811 GetArrayString(g_OldMapList, i, map, sizeof(map));
812 index = FindStringInArray(tempMaps, map);
815 RemoveFromArray(tempMaps, index);
820 new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(tempMaps) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(tempMaps));
821 for (new i = 0; i < limit; i++)
823 new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
824 GetArrayString(tempMaps, b, map, sizeof(map));
825 PushArrayString(g_NextMapList, map);
826 RemoveFromArray(tempMaps, b);
829 CloseHandle(tempMaps);
834 if (g_WaitingForVote || g_HasVoteStarted)
842 NominateResult:InternalNominateMap(String:map[], bool:force, owner)
844 if (!IsMapValid(map))
846 return Nominate_InvalidMap;
851 if ((index = FindValueInArray(g_NominateOwners, owner)) != -1)
853 new String:oldmap[33];
854 GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap));
855 Call_StartForward(g_NominationsResetForward);
856 Call_PushString(oldmap);
857 Call_PushCell(owner);
861 SetArrayString(g_NominateList, index, map);
862 return Nominate_Replaced;
865 /* Too many nominated maps. */
866 if (g_NominateCount >= GetConVarInt(g_Cvar_IncludeMaps) && !force)
868 return Nominate_VoteFull;
871 /* Map already in the vote */
872 if (FindStringInArray(g_NominateList, map) != -1)
874 return Nominate_AlreadyInVote;
878 PushArrayString(g_NominateList, map);
879 PushArrayCell(g_NominateOwners, owner);
882 while (GetArraySize(g_NominateList) > GetConVarInt(g_Cvar_IncludeMaps))
884 new String:oldmap[33];
885 GetArrayString(g_NominateList, 0, oldmap, sizeof(oldmap));
886 Call_StartForward(g_NominationsResetForward);
887 Call_PushString(oldmap);
888 Call_PushCell(GetArrayCell(g_NominateOwners, 0));
891 RemoveFromArray(g_NominateList, 0);
892 RemoveFromArray(g_NominateOwners, 0);
895 return Nominate_Added;
898 /* Add natives to allow nominate and initiate vote to be call */
900 /* native bool:NominateMap(const String:map[], bool:force, &NominateError:error); */
901 public Native_NominateMap(Handle:plugin, numParams)
904 GetNativeStringLength(1, len);
911 new String:map[len+1];
912 GetNativeString(1, map, len+1);
914 return _:InternalNominateMap(map, GetNativeCell(2), GetNativeCell(3));
917 /* native InitiateMapChooserVote(); */
918 public Native_InitiateVote(Handle:plugin, numParams)
920 new MapChange:when = MapChange:GetNativeCell(1);
921 new Handle:inputarray = Handle:GetNativeCell(2);
923 LogMessage("Starting map vote because outside request");
924 InitiateVote(when, inputarray);
927 public Native_CanVoteStart(Handle:plugin, numParams)
929 return CanVoteStart();
932 public Native_CheckVoteDone(Handle:plugin, numParams)
934 if (GetConVarBool(g_Cvar_EndOfMapVote) == false)
939 return g_MapVoteCompleted;
942 public Native_GetExcludeMapList(Handle:plugin, numParams)
944 new Handle:array = Handle:GetNativeCell(1);
946 if (array == INVALID_HANDLE)
952 new size = GetArraySize(g_OldMapList);
955 for (new i=0; i<size; i++)
957 GetArrayString(g_OldMapList, i, map, sizeof(map));
958 PushArrayString(array, map);