fixed a compat regression, forgot msvc does funky things with overloaded virtual calls
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);
159 g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
162 public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
164 RegPluginLibrary("mapchooser");
166 CreateNative("NominateMap", Native_NominateMap);
167 CreateNative("InitiateMapChooserVote", Native_InitiateVote);
168 CreateNative("CanMapChooserStartVote", Native_CanVoteStart);
169 CreateNative("HasEndOfMapVoteFinished", Native_CheckVoteDone);
170 CreateNative("GetExcludeMapList", Native_GetExcludeMapList);
175 public OnConfigsExecuted()
177 if (ReadMapList(g_MapList,
180 MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER)
184 if (g_mapFileSerial == -1)
186 LogError("Unable to create a valid map list.");
191 SetupTimeleftTimer();
197 g_MapVoteCompleted = false;
200 ClearArray(g_NominateList);
201 ClearArray(g_NominateOwners);
203 for (new i=0; i<MAXTEAMS; i++)
209 /* Check if mapchooser will attempt to start mapvote during bonus round time - TF2 Only */
210 if ((g_Cvar_Bonusroundtime != INVALID_HANDLE) && !GetConVarInt(g_Cvar_StartRounds))
212 if (GetConVarFloat(g_Cvar_Bonusroundtime) <= GetConVarFloat(g_Cvar_VoteDuration))
214 LogError("Warning - Bonus Round Time shorter than Vote Time. Votes during bonus round may not have time to complete");
221 g_HasVoteStarted = false;
222 g_WaitingForVote = false;
224 if (g_VoteTimer != INVALID_HANDLE)
226 KillTimer(g_VoteTimer);
227 g_VoteTimer = INVALID_HANDLE;
230 if (g_RetryTimer != INVALID_HANDLE)
232 KillTimer(g_RetryTimer);
233 g_RetryTimer = INVALID_HANDLE;
237 GetCurrentMap(map, sizeof(map));
238 PushArrayString(g_OldMapList, map);
240 if (GetArraySize(g_OldMapList) > GetConVarInt(g_Cvar_ExcludeMaps))
242 RemoveFromArray(g_OldMapList, 0);
246 public OnClientDisconnect(client)
248 new index = FindValueInArray(g_NominateOwners, client);
255 new String:oldmap[33];
256 GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap));
257 Call_StartForward(g_NominationsResetForward);
258 Call_PushString(oldmap);
259 Call_PushCell(GetArrayCell(g_NominateOwners, index));
262 RemoveFromArray(g_NominateOwners, index);
263 RemoveFromArray(g_NominateList, index);
267 public EndVoteChanged(Handle:convar, const String:oldValue[], const String:newValue[])
269 if (newValue[0] == '1')
271 SetNextMap("Pending Vote");
279 public OnMapTimeLeftChanged()
281 if (GetArraySize(g_MapList))
283 SetupTimeleftTimer();
290 if (GetMapTimeLeft(time) && time > 0)
292 new startTime = GetConVarInt(g_Cvar_StartTime) * 60;
293 if (time - startTime < 0 && GetConVarBool(g_Cvar_EndOfMapVote) && !g_MapVoteCompleted && !g_HasVoteStarted)
295 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
299 if (g_VoteTimer != INVALID_HANDLE)
301 KillTimer(g_VoteTimer);
302 g_VoteTimer = INVALID_HANDLE;
305 g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote);
310 public Action:Timer_StartMapVote(Handle:timer)
312 if (!GetArraySize(g_MapList) || !GetConVarBool(g_Cvar_EndOfMapVote) || g_MapVoteCompleted || g_HasVoteStarted)
317 if (timer == g_RetryTimer)
319 g_RetryTimer = INVALID_HANDLE;
323 g_VoteTimer = INVALID_HANDLE;
326 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
331 public Event_TFRestartRound(Handle:event, const String:name[], bool:dontBroadcast)
333 /* Game got restarted - reset our round count tracking */
337 public Event_TeamPlayWinPanel(Handle:event, const String:name[], bool:dontBroadcast)
339 if (g_ChangeMapAtRoundEnd)
341 g_ChangeMapAtRoundEnd = false;
342 CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE);
345 if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted || !GetConVarBool(g_Cvar_EndOfMapVote))
350 new bluescore = GetEventInt(event, "blue_score");
351 new redscore = GetEventInt(event, "red_score");
353 if(GetEventInt(event, "round_complete") == 1)
355 switch(GetEventInt(event, "winning_team"))
359 CheckWinLimit(bluescore);
363 CheckWinLimit(redscore);
365 //We need to do nothing on winning_team == 0 this indicates stalemate.
373 CheckMaxRounds(g_TotalRounds);
376 /* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */
377 public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
379 if (g_ChangeMapAtRoundEnd)
381 g_ChangeMapAtRoundEnd = false;
382 CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE);
385 if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted)
390 new winner = GetEventInt(event, "winner");
392 if (winner == 0 || winner == 1 || !GetConVarBool(g_Cvar_EndOfMapVote))
397 if (winner >= MAXTEAMS)
399 SetFailState("Mod exceed maximum team count - Please file a bug report.");
404 g_winCount[winner]++;
406 CheckWinLimit(g_winCount[winner]);
407 CheckMaxRounds(g_TotalRounds);
410 public CheckWinLimit(winner_score)
412 if (g_Cvar_Winlimit != INVALID_HANDLE)
414 new winlimit = GetConVarInt(g_Cvar_Winlimit);
417 if (winner_score >= (winlimit - GetConVarInt(g_Cvar_StartRounds)))
419 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
425 public CheckMaxRounds(roundcount)
427 if (g_Cvar_Maxrounds != INVALID_HANDLE)
429 new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
432 if (roundcount >= (maxrounds - GetConVarInt(g_Cvar_StartRounds)))
434 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
440 public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
442 if (!GetArraySize(g_MapList) || g_Cvar_Fraglimit == INVALID_HANDLE || g_HasVoteStarted)
447 if (!GetConVarInt(g_Cvar_Fraglimit) || !GetConVarBool(g_Cvar_EndOfMapVote))
452 new fragger = GetClientOfUserId(GetEventInt(event, "attacker"));
453 if (fragger && GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags)))
455 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
459 public Action:Command_Mapvote(client, args)
461 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
463 return Plugin_Handled;
466 InitiateVote(MapChange:when, Handle:inputlist)
473 g_WaitingForVote = true;
475 if (IsVoteInProgress())
477 // Can't start a vote, try again in 5 seconds.
478 g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote);
484 g_WaitingForVote = false;
486 g_HasVoteStarted = true;
487 g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
488 SetMenuTitle(g_VoteMenu, "Vote Nextmap");
489 SetVoteResultCallback(g_VoteMenu, Handler_MapVoteFinished);
492 * TODO: Make a proper decision on when to clear the nominations list.
493 * Currently it clears when used, and stays if an external list is provided.
494 * Is this the right thing to do? External lists will probably come from places
495 * like sm_mapvote from the adminmenu in the future.
500 /* No input given - User our internal nominations and maplist */
501 if (inputlist == INVALID_HANDLE)
503 new nominateCount = GetArraySize(g_NominateList);
504 new voteSize = GetConVarInt(g_Cvar_IncludeMaps);
506 /* Smaller of the two - It should be impossible for nominations to exceed the size though (cvar changed mid-map?) */
507 new nominationsToAdd = nominateCount >= voteSize ? voteSize : nominateCount;
510 for (new i=0; i<nominationsToAdd; i++)
512 GetArrayString(g_NominateList, i, map, sizeof(map));
513 AddMenuItem(g_VoteMenu, map, map);
515 /* Notify Nominations that this map is now free */
516 Call_StartForward(g_NominationsResetForward);
517 Call_PushString(map);
518 Call_PushCell(GetArrayCell(g_NominateOwners, i));
522 /* Clear out the rest of the nominations array */
523 for (new i=nominationsToAdd; i<nominateCount; i++)
525 GetArrayString(g_NominateList, i, map, sizeof(map));
527 /* Notify Nominations that this map is now free */
528 Call_StartForward(g_NominationsResetForward);
529 Call_PushString(map);
530 Call_PushCell(GetArrayCell(g_NominateOwners, i));
534 /* There should currently be 'nominationsToAdd' unique maps in the vote */
536 new i = nominationsToAdd;
538 new availableMaps = GetArraySize(g_NextMapList);
542 GetArrayString(g_NextMapList, count, map, sizeof(map));
545 //Check if this map is in the nominate list (and thus already in the vote) */
546 if (FindStringInArray(g_NominateList, map) == -1)
548 /* Insert the map and increment our count */
549 AddMenuItem(g_VoteMenu, map, map);
553 if (count >= availableMaps)
555 //Run out of maps, this will have to do.
560 /* Wipe out our nominations list - Nominations have already been informed of this */
561 ClearArray(g_NominateOwners);
562 ClearArray(g_NominateList);
564 else //We were given a list of maps to start the vote with
566 new size = GetArraySize(inputlist);
568 for (new i=0; i<size; i++)
570 GetArrayString(inputlist, i, map, sizeof(map));
574 AddMenuItem(g_VoteMenu, map, map);
579 /* Do we add any special items? */
580 if ((when == MapChange_Instant || when == MapChange_RoundEnd) && GetConVarBool(g_Cvar_DontChange))
582 AddMenuItem(g_VoteMenu, VOTE_DONTCHANGE, "Don't Change");
584 else if (GetConVarBool(g_Cvar_Extend) && g_Extends < GetConVarInt(g_Cvar_Extend))
586 AddMenuItem(g_VoteMenu, VOTE_EXTEND, "Extend Map");
589 new voteDuration = GetConVarInt(g_Cvar_VoteDuration);
591 SetMenuExitButton(g_VoteMenu, false);
592 VoteMenuToAll(g_VoteMenu, voteDuration);
594 LogMessage("Voting for next map has started.");
595 PrintToChatAll("[SM] %t", "Nextmap Voting Started");
598 public Handler_MapVoteFinished(Handle:menu,
601 const client_info[][2],
603 const item_info[][2])
607 LogError("No Votes recorded yet Advanced callback fired - Tell pRED* to fix this");
612 GetMenuItem(menu, item_info[0][VOTEINFO_ITEM_INDEX], map, sizeof(map));
614 if (strcmp(map, VOTE_EXTEND, false) == 0)
619 if (GetMapTimeLimit(time))
623 ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60);
627 if (g_Cvar_Winlimit != INVALID_HANDLE)
629 new winlimit = GetConVarInt(g_Cvar_Winlimit);
632 SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep));
636 if (g_Cvar_Maxrounds != INVALID_HANDLE)
638 new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
641 SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep));
645 if (g_Cvar_Fraglimit != INVALID_HANDLE)
647 new fraglimit = GetConVarInt(g_Cvar_Fraglimit);
650 SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep));
654 PrintToChatAll("[SM] %t", "Current Map Extended", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
655 LogMessage("Voting for next map has finished. The current map has been extended.");
657 // We extended, so we'll have to vote again.
658 g_HasVoteStarted = false;
660 SetupTimeleftTimer();
663 else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
665 PrintToChatAll("[SM] %t", "Current Map Stays", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
666 LogMessage("Voting for next map has finished. 'No Change' was the winner");
668 g_HasVoteStarted = false;
670 SetupTimeleftTimer();
674 if (g_ChangeTime == MapChange_MapEnd)
678 else if (g_ChangeTime == MapChange_Instant)
681 CreateDataTimer(2.0, Timer_ChangeMap, data);
682 WritePackString(data, map);
684 else // MapChange_RoundEnd
687 g_ChangeMapAtRoundEnd = true;
690 g_HasVoteStarted = false;
691 g_MapVoteCompleted = true;
693 PrintToChatAll("[SM] %t", "Nextmap Voting Finished", map, RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
694 LogMessage("Voting for next map has finished. Nextmap: %s.", map);
698 public Handler_MapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
704 g_VoteMenu = INVALID_HANDLE;
708 case MenuAction_Display:
710 decl String:buffer[255];
711 Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1);
713 new Handle:panel = Handle:param2;
714 SetPanelTitle(panel, buffer);
717 case MenuAction_DisplayItem:
719 if (GetMenuItemCount(menu) - 1 == param2)
721 decl String:map[64], String:buffer[255];
722 GetMenuItem(menu, param2, map, sizeof(map));
723 if (strcmp(map, VOTE_EXTEND, false) == 0)
725 Format(buffer, sizeof(buffer), "%T", "Extend Map", param1);
726 return RedrawMenuItem(buffer);
728 else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
730 Format(buffer, sizeof(buffer), "%T", "Dont Change", param1);
731 return RedrawMenuItem(buffer);
736 case MenuAction_VoteCancel:
738 // If we receive 0 votes, pick at random.
739 if (param1 == VoteCancel_NoVotes && GetConVarBool(g_Cvar_NoVoteMode))
741 new count = GetMenuItemCount(menu);
742 new item = GetRandomInt(0, count - 1);
744 GetMenuItem(menu, item, map, sizeof(map));
746 while (strcmp(map, VOTE_EXTEND, false) == 0)
748 item = GetRandomInt(0, count - 1);
749 GetMenuItem(menu, item, map, sizeof(map));
756 // We were actually cancelled. What should we do?
757 g_HasVoteStarted = false;
759 SetupTimeleftTimer();
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 ServerCommand("changelevel \"%s\"", map);
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 return g_MapVoteCompleted;
937 public Native_GetExcludeMapList(Handle:plugin, numParams)
939 new Handle:array = Handle:GetNativeCell(1);
941 if (array == INVALID_HANDLE)
947 new size = GetArraySize(g_OldMapList);
950 for (new i=0; i<size; i++)
952 GetArrayString(g_OldMapList, i, map, sizeof(map));
953 PushArrayString(array, map);