Nominations not blocking current map and excluded maps when used from console.
Removed error causing debug stuff from mapchooser.
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>.
39 #undef REQUIRE_EXTENSIONS
41 #define REQUIRE_EXTENSIONS
43 public Plugin:myinfo =
46 author = "AlliedModders LLC",
47 description = "Automated Map Voting",
48 version = SOURCEMOD_VERSION,
49 url = "http://www.sourcemod.net/"
53 new Handle:g_Cvar_Winlimit = INVALID_HANDLE;
54 new Handle:g_Cvar_Maxrounds = INVALID_HANDLE;
55 new Handle:g_Cvar_Fraglimit = INVALID_HANDLE;
56 new Handle:g_Cvar_Bonusroundtime = INVALID_HANDLE;
59 new Handle:g_Cvar_StartTime = INVALID_HANDLE;
60 new Handle:g_Cvar_StartRounds = INVALID_HANDLE;
61 new Handle:g_Cvar_StartFrags = INVALID_HANDLE;
62 new Handle:g_Cvar_ExtendTimeStep = INVALID_HANDLE;
63 new Handle:g_Cvar_ExtendRoundStep = INVALID_HANDLE;
64 new Handle:g_Cvar_ExtendFragStep = INVALID_HANDLE;
65 new Handle:g_Cvar_ExcludeMaps = INVALID_HANDLE;
66 new Handle:g_Cvar_IncludeMaps = INVALID_HANDLE;
67 new Handle:g_Cvar_NoVoteMode = INVALID_HANDLE;
68 new Handle:g_Cvar_Extend = INVALID_HANDLE;
69 new Handle:g_Cvar_DontChange = INVALID_HANDLE;
70 new Handle:g_Cvar_EndOfMapVote = INVALID_HANDLE;
71 new Handle:g_Cvar_VoteDuration = INVALID_HANDLE;
72 new Handle:g_VoteTimer = INVALID_HANDLE;
73 new Handle:g_RetryTimer = INVALID_HANDLE;
76 new Handle:g_MapList = INVALID_HANDLE;
77 new Handle:g_NominateList = INVALID_HANDLE;
78 new Handle:g_NominateOwners = INVALID_HANDLE;
79 new Handle:g_OldMapList = INVALID_HANDLE;
80 new Handle:g_NextMapList = INVALID_HANDLE;
81 new Handle:g_VoteMenu = INVALID_HANDLE;
85 new bool:g_HasVoteStarted;
86 new bool:g_WaitingForVote;
87 new bool:g_MapVoteCompleted;
88 new bool:g_ChangeMapAtRoundEnd;
89 new g_mapFileSerial = -1;
91 new g_NominateCount = 0;
92 new MapChange:g_ChangeTime;
94 new Handle:g_NominationsResetForward = INVALID_HANDLE;
96 /* Upper bound of how many team there could be */
98 new g_winCount[MAXTEAMS];
100 #define VOTE_EXTEND "##extend##"
101 #define VOTE_DONTCHANGE "##dontchange##"
103 public OnPluginStart()
105 LoadTranslations("mapchooser.phrases");
107 new arraySize = ByteCountToCells(33);
108 g_MapList = CreateArray(arraySize);
109 g_NominateList = CreateArray(arraySize);
110 g_NominateOwners = CreateArray(1);
111 g_OldMapList = CreateArray(arraySize);
112 g_NextMapList = CreateArray(arraySize);
114 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 HookConVarChange(g_Cvar_EndOfMapVote, EndVoteChanged);
117 g_Cvar_StartTime = CreateConVar("sm_mapvote_start", "3.0", "Specifies when to start the vote based on time remaining.", _, true, 1.0);
118 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);
119 g_Cvar_StartFrags = CreateConVar("sm_mapvote_startfrags", "5.0", "Specifies when to start the vote base on frags remaining.", _, true, 1.0);
120 g_Cvar_ExtendTimeStep = CreateConVar("sm_extendmap_timestep", "15", "Specifies how much many more minutes each extension makes", _, true, 5.0);
121 g_Cvar_ExtendRoundStep = CreateConVar("sm_extendmap_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 1.0);
122 g_Cvar_ExtendFragStep = CreateConVar("sm_extendmap_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0);
123 g_Cvar_ExcludeMaps = CreateConVar("sm_mapvote_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0);
124 g_Cvar_IncludeMaps = CreateConVar("sm_mapvote_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 6.0);
125 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);
126 g_Cvar_Extend = CreateConVar("sm_mapvote_extend", "0", "Number of extensions allowed each map.", _, true, 0.0);
127 g_Cvar_DontChange = CreateConVar("sm_mapvote_dontchange", "1", "Specifies if a 'Don't Change' option should be added to early votes", _, true, 0.0);
128 g_Cvar_VoteDuration = CreateConVar("sm_mapvote_voteduration", "20", "Specifies how long the mapvote should be available for.", _, true, 5.0, true, 25.0);
129 RegAdminCmd("sm_mapvote", Command_Mapvote, ADMFLAG_CHANGEMAP, "sm_mapvote - Forces MapChooser to attempt to run a map vote now.");
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 RegPluginLibrary("mapchooser");
159 g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
162 public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
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 if (g_VoteTimer != INVALID_HANDLE)
224 KillTimer(g_VoteTimer);
225 g_VoteTimer = INVALID_HANDLE;
228 if (g_RetryTimer != INVALID_HANDLE)
230 KillTimer(g_RetryTimer);
231 g_RetryTimer = INVALID_HANDLE;
235 GetCurrentMap(map, sizeof(map));
236 PushArrayString(g_OldMapList, map);
238 if (GetArraySize(g_OldMapList) > GetConVarInt(g_Cvar_ExcludeMaps))
240 RemoveFromArray(g_OldMapList, 0);
244 public OnClientDisconnect(client)
246 new index = FindValueInArray(g_NominateOwners, client);
253 new String:oldmap[33];
254 GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap));
255 Call_StartForward(g_NominationsResetForward);
256 Call_PushString(oldmap);
257 Call_PushCell(GetArrayCell(g_NominateOwners, index));
260 RemoveFromArray(g_NominateOwners, index);
261 RemoveFromArray(g_NominateList, index);
265 public EndVoteChanged(Handle:convar, const String:oldValue[], const String:newValue[])
267 if (newValue[0] == '1')
269 SetNextMap("Pending Vote");
277 public OnMapTimeLeftChanged()
279 if (GetArraySize(g_MapList))
281 SetupTimeleftTimer();
288 if (GetMapTimeLeft(time) && time > 0)
290 new startTime = GetConVarInt(g_Cvar_StartTime) * 60;
291 if (time - startTime < 0 && GetConVarBool(g_Cvar_EndOfMapVote) && !g_MapVoteCompleted && !g_HasVoteStarted)
293 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
297 if (g_VoteTimer != INVALID_HANDLE)
299 KillTimer(g_VoteTimer);
300 g_VoteTimer = INVALID_HANDLE;
303 g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote);
308 public Action:Timer_StartMapVote(Handle:timer)
310 if (!GetArraySize(g_MapList) || !GetConVarBool(g_Cvar_EndOfMapVote) || g_MapVoteCompleted || g_HasVoteStarted)
315 if (timer == g_RetryTimer)
317 g_RetryTimer = INVALID_HANDLE;
321 g_VoteTimer = INVALID_HANDLE;
324 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
329 public Event_TFRestartRound(Handle:event, const String:name[], bool:dontBroadcast)
331 /* Game got restarted - reset our round count tracking */
335 public Event_TeamPlayWinPanel(Handle:event, const String:name[], bool:dontBroadcast)
337 if (g_ChangeMapAtRoundEnd)
339 g_ChangeMapAtRoundEnd = false;
340 CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE);
343 if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted || !GetConVarBool(g_Cvar_EndOfMapVote))
348 new bluescore = GetEventInt(event, "blue_score");
349 new redscore = GetEventInt(event, "red_score");
351 if(GetEventInt(event, "round_complete") == 1)
353 switch(GetEventInt(event, "winning_team"))
357 CheckWinLimit(bluescore);
361 CheckWinLimit(redscore);
363 //We need to do nothing on winning_team == 0 this indicates stalemate.
371 CheckMaxRounds(g_TotalRounds);
374 /* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */
375 public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
377 if (g_ChangeMapAtRoundEnd)
379 g_ChangeMapAtRoundEnd = false;
380 CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE);
383 if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted)
388 new winner = GetEventInt(event, "winner");
390 if (winner == 0 || winner == 1 || !GetConVarBool(g_Cvar_EndOfMapVote))
395 if (winner >= MAXTEAMS)
397 SetFailState("Mod exceed maximum team count - Please file a bug report.");
402 g_winCount[winner]++;
404 CheckWinLimit(g_winCount[winner]);
405 CheckMaxRounds(g_TotalRounds);
408 public CheckWinLimit(winner_score)
410 if (g_Cvar_Winlimit != INVALID_HANDLE)
412 new winlimit = GetConVarInt(g_Cvar_Winlimit);
415 if (winner_score >= (winlimit - GetConVarInt(g_Cvar_StartRounds)))
417 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
423 public CheckMaxRounds(roundcount)
425 if (g_Cvar_Maxrounds != INVALID_HANDLE)
427 new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
430 if (roundcount >= (maxrounds - GetConVarInt(g_Cvar_StartRounds)))
432 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
438 public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
440 if (!GetArraySize(g_MapList) || g_Cvar_Fraglimit == INVALID_HANDLE || g_HasVoteStarted)
445 if (!GetConVarInt(g_Cvar_Fraglimit) || !GetConVarBool(g_Cvar_EndOfMapVote))
450 new fragger = GetClientOfUserId(GetEventInt(event, "attacker"));
451 if (fragger && GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags)))
453 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
457 public Action:Command_Mapvote(client, args)
459 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
461 return Plugin_Handled;
464 InitiateVote(MapChange:when, Handle:inputlist)
471 g_WaitingForVote = true;
473 if (IsVoteInProgress())
475 // Can't start a vote, try again in 5 seconds.
476 g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote);
482 g_WaitingForVote = false;
484 g_HasVoteStarted = true;
485 g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
486 SetMenuTitle(g_VoteMenu, "Vote Nextmap");
487 SetVoteResultCallback(g_VoteMenu, Handler_MapVoteFinished);
490 * TODO: Make a proper decision on when to clear the nominations list.
491 * Currently it clears when used, and stays if an external list is provided.
492 * Is this the right thing to do? External lists will probably come from places
493 * like sm_mapvote from the adminmenu in the future.
498 /* No input given - User our internal nominations and maplist */
499 if (inputlist == INVALID_HANDLE)
501 new nominateCount = GetArraySize(g_NominateList);
502 new voteSize = GetConVarInt(g_Cvar_IncludeMaps);
504 /* Smaller of the two - It should be impossible for nominations to exceed the size though (cvar changed mid-map?) */
505 new nominationsToAdd = nominateCount >= voteSize ? voteSize : nominateCount;
508 for (new i=0; i<nominationsToAdd; i++)
510 GetArrayString(g_NominateList, i, map, sizeof(map));
511 AddMenuItem(g_VoteMenu, map, map);
513 /* Notify Nominations that this map is now free */
514 Call_StartForward(g_NominationsResetForward);
515 Call_PushString(map);
516 Call_PushCell(GetArrayCell(g_NominateOwners, i));
520 /* Clear out the rest of the nominations array */
521 for (new i=nominationsToAdd; i<nominateCount; i++)
523 GetArrayString(g_NominateList, i, map, sizeof(map));
525 /* Notify Nominations that this map is now free */
526 Call_StartForward(g_NominationsResetForward);
527 Call_PushString(map);
528 Call_PushCell(GetArrayCell(g_NominateOwners, i));
532 /* There should currently be 'nominationsToAdd' unique maps in the vote */
534 new i = nominationsToAdd;
536 new availableMaps = GetArraySize(g_NextMapList);
540 GetArrayString(g_NextMapList, count, map, sizeof(map));
543 //Check if this map is in the nominate list (and thus already in the vote) */
544 if (FindStringInArray(g_NominateList, map) == -1)
546 /* Insert the map and increment our count */
547 AddMenuItem(g_VoteMenu, map, map);
551 if (count >= availableMaps)
553 //Run out of maps, this will have to do.
558 /* Wipe out our nominations list - Nominations have already been informed of this */
559 ClearArray(g_NominateOwners);
560 ClearArray(g_NominateList);
562 else //We were given a list of maps to start the vote with
564 new size = GetArraySize(inputlist);
566 for (new i=0; i<size; i++)
568 GetArrayString(inputlist, i, map, sizeof(map));
572 AddMenuItem(g_VoteMenu, map, map);
577 /* Do we add any special items? */
578 if ((when == MapChange_Instant || when == MapChange_RoundEnd) && GetConVarBool(g_Cvar_DontChange))
580 AddMenuItem(g_VoteMenu, VOTE_DONTCHANGE, "Don't Change");
582 else if (GetConVarBool(g_Cvar_Extend) && g_Extends < GetConVarInt(g_Cvar_Extend))
584 AddMenuItem(g_VoteMenu, VOTE_EXTEND, "Extend Map");
587 new voteDuration = GetConVarInt(g_Cvar_VoteDuration);
589 SetMenuExitButton(g_VoteMenu, false);
590 VoteMenuToAll(g_VoteMenu, voteDuration);
592 LogMessage("Voting for next map has started.");
593 PrintToChatAll("[SM] %t", "Nextmap Voting Started");
596 public Handler_MapVoteFinished(Handle:menu,
599 const client_info[][2],
601 const item_info[][2])
605 LogError("No Votes recorded yet Advanced callback fired - Tell pRED* to fix this");
610 GetMenuItem(menu, item_info[0][VOTEINFO_ITEM_INDEX], map, sizeof(map));
612 if (strcmp(map, VOTE_EXTEND, false) == 0)
617 if (GetMapTimeLimit(time))
621 ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60);
625 if (g_Cvar_Winlimit != INVALID_HANDLE)
627 new winlimit = GetConVarInt(g_Cvar_Winlimit);
630 SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep));
634 if (g_Cvar_Maxrounds != INVALID_HANDLE)
636 new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
639 SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep));
643 if (g_Cvar_Fraglimit != INVALID_HANDLE)
645 new fraglimit = GetConVarInt(g_Cvar_Fraglimit);
648 SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep));
652 PrintToChatAll("[SM] %t", "Current Map Extended", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
653 LogMessage("Voting for next map has finished. The current map has been extended.");
655 // We extended, so we'll have to vote again.
656 g_HasVoteStarted = false;
658 SetupTimeleftTimer();
661 else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
663 PrintToChatAll("[SM] %t", "Current Map Stays", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
664 LogMessage("Voting for next map has finished. 'No Change' was the winner");
666 g_HasVoteStarted = false;
668 SetupTimeleftTimer();
672 if (g_ChangeTime == MapChange_MapEnd)
676 else if (g_ChangeTime == MapChange_Instant)
679 CreateDataTimer(2.0, Timer_ChangeMap, data);
680 WritePackString(data, map);
682 else // MapChange_RoundEnd
685 g_ChangeMapAtRoundEnd = true;
688 g_HasVoteStarted = false;
689 g_MapVoteCompleted = true;
691 PrintToChatAll("[SM] %t", "Nextmap Voting Finished", map, RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
692 LogMessage("Voting for next map has finished. Nextmap: %s.", map);
696 public Handler_MapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
702 g_VoteMenu = INVALID_HANDLE;
706 case MenuAction_Display:
708 decl String:buffer[255];
709 Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1);
711 new Handle:panel = Handle:param2;
712 SetPanelTitle(panel, buffer);
715 case MenuAction_DisplayItem:
717 if (GetMenuItemCount(menu) - 1 == param2)
719 decl String:map[64], String:buffer[255];
720 GetMenuItem(menu, param2, map, sizeof(map));
721 if (strcmp(map, VOTE_EXTEND, false) == 0)
723 Format(buffer, sizeof(buffer), "%T", "Extend Map", param1);
724 return RedrawMenuItem(buffer);
726 else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
728 Format(buffer, sizeof(buffer), "%T", "Dont Change", param1);
729 return RedrawMenuItem(buffer);
734 case MenuAction_VoteCancel:
736 // If we receive 0 votes, pick at random.
737 if (param1 == VoteCancel_NoVotes && GetConVarBool(g_Cvar_NoVoteMode))
739 new count = GetMenuItemCount(menu);
740 new item = GetRandomInt(0, count - 1);
742 GetMenuItem(menu, item, map, sizeof(map));
744 while (strcmp(map, VOTE_EXTEND, false) == 0)
746 item = GetRandomInt(0, count - 1);
747 GetMenuItem(menu, item, map, sizeof(map));
754 // We were actually cancelled. What should we do?
755 g_HasVoteStarted = false;
757 SetupTimeleftTimer();
765 public Action:Timer_ChangeMap(Handle:hTimer, Handle:dp)
769 if (dp == INVALID_HANDLE)
771 if (!GetNextMap(map, sizeof(map)))
773 //No passed map and no set nextmap. fail!
780 ReadPackString(dp, map, sizeof(map));
783 ServerCommand("changelevel \"%s\"", map);
790 if(g_NextMapList != INVALID_HANDLE)
792 ClearArray(g_NextMapList);
796 new index, Handle:tempMaps = CloneArray(g_MapList);
798 GetCurrentMap(map, sizeof(map));
799 index = FindStringInArray(tempMaps, map);
802 RemoveFromArray(tempMaps, index);
805 if (GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps))
807 for (new i = 0; i < GetArraySize(g_OldMapList); i++)
809 GetArrayString(g_OldMapList, i, map, sizeof(map));
810 index = FindStringInArray(tempMaps, map);
813 RemoveFromArray(tempMaps, index);
818 new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(tempMaps) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(tempMaps));
819 for (new i = 0; i < limit; i++)
821 new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
822 GetArrayString(tempMaps, b, map, sizeof(map));
823 PushArrayString(g_NextMapList, map);
824 RemoveFromArray(tempMaps, b);
827 CloseHandle(tempMaps);
832 if (g_WaitingForVote || g_HasVoteStarted)
840 NominateResult:InternalNominateMap(String:map[], bool:force, owner)
842 if (!IsMapValid(map))
844 return Nominate_InvalidMap;
849 if ((index = FindValueInArray(g_NominateOwners, owner)) != -1)
851 new String:oldmap[33];
852 GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap));
853 Call_StartForward(g_NominationsResetForward);
854 Call_PushString(oldmap);
855 Call_PushCell(owner);
859 SetArrayString(g_NominateList, index, map);
860 return Nominate_Replaced;
863 /* Too many nominated maps. */
864 if (g_NominateCount >= GetConVarInt(g_Cvar_IncludeMaps) && !force)
866 return Nominate_VoteFull;
869 /* Map already in the vote */
870 if (FindStringInArray(g_NominateList, map) != -1)
872 return Nominate_AlreadyInVote;
876 PushArrayString(g_NominateList, map);
877 PushArrayCell(g_NominateOwners, owner);
880 while (GetArraySize(g_NominateList) > GetConVarInt(g_Cvar_IncludeMaps))
882 new String:oldmap[33];
883 GetArrayString(g_NominateList, 0, oldmap, sizeof(oldmap));
884 Call_StartForward(g_NominationsResetForward);
885 Call_PushString(oldmap);
886 Call_PushCell(GetArrayCell(g_NominateOwners, 0));
889 RemoveFromArray(g_NominateList, 0);
890 RemoveFromArray(g_NominateOwners, 0);
893 return Nominate_Added;
896 /* Add natives to allow nominate and initiate vote to be call */
898 /* native bool:NominateMap(const String:map[], bool:force, &NominateError:error); */
899 public Native_NominateMap(Handle:plugin, numParams)
902 GetNativeStringLength(1, len);
909 new String:map[len+1];
910 GetNativeString(1, map, len+1);
912 return _:InternalNominateMap(map, GetNativeCell(2), GetNativeCell(3));
915 /* native InitiateMapChooserVote(); */
916 public Native_InitiateVote(Handle:plugin, numParams)
918 new MapChange:when = MapChange:GetNativeCell(1);
919 new Handle:inputarray = Handle:GetNativeCell(2);
921 LogMessage("Starting map vote because outside request");
922 InitiateVote(when, inputarray);
925 public Native_CanVoteStart(Handle:plugin, numParams)
927 return CanVoteStart();
930 public Native_CheckVoteDone(Handle:plugin, numParams)
932 return g_MapVoteCompleted;
935 public Native_GetExcludeMapList(Handle:plugin, numParams)
937 new Handle:array = Handle:GetNativeCell(1);
939 if (array == INVALID_HANDLE)
945 new size = GetArraySize(g_OldMapList);
948 for (new i=0; i<size; i++)
950 GetArrayString(g_OldMapList, i, map, sizeof(map));
951 PushArrayString(array, map);