Updated cstrike ext WeaponPrice offset.
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 bool:g_ChangeMapInProgress;
88 new g_mapFileSerial = -1;
90 new g_NominateCount = 0;
91 new MapChange:g_ChangeTime;
93 new Handle:g_NominationsResetForward = INVALID_HANDLE;
94 new Handle:g_MapVoteStartedForward = 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");
106 LoadTranslations("common.phrases");
108 new arraySize = ByteCountToCells(33);
109 g_MapList = CreateArray(arraySize);
110 g_NominateList = CreateArray(arraySize);
111 g_NominateOwners = CreateArray(1);
112 g_OldMapList = CreateArray(arraySize);
113 g_NextMapList = CreateArray(arraySize);
115 g_Cvar_EndOfMapVote = CreateConVar("sm_mapvote_endvote", "1", "Specifies if MapChooser should run an end of map vote", _, true, 0.0, true, 1.0);
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);
130 RegAdminCmd("sm_mapvote", Command_Mapvote, ADMFLAG_CHANGEMAP, "sm_mapvote - Forces MapChooser to attempt to run a map vote now.");
131 RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap <map>");
133 g_Cvar_Winlimit = FindConVar("mp_winlimit");
134 g_Cvar_Maxrounds = FindConVar("mp_maxrounds");
135 g_Cvar_Fraglimit = FindConVar("mp_fraglimit");
136 g_Cvar_Bonusroundtime = FindConVar("mp_bonusroundtime");
138 if (g_Cvar_Winlimit != INVALID_HANDLE || g_Cvar_Maxrounds != INVALID_HANDLE)
140 HookEvent("round_end", Event_RoundEnd);
141 HookEventEx("teamplay_win_panel", Event_TeamPlayWinPanel);
142 HookEventEx("teamplay_restart_round", Event_TFRestartRound);
143 HookEventEx("arena_win_panel", Event_TeamPlayWinPanel);
146 if (g_Cvar_Fraglimit != INVALID_HANDLE)
148 HookEvent("player_death", Event_PlayerDeath);
151 AutoExecConfig(true, "mapchooser");
153 //Change the mp_bonusroundtime max so that we have time to display the vote
154 //If you display a vote during bonus time good defaults are 17 vote duration and 19 mp_bonustime
155 if (g_Cvar_Bonusroundtime != INVALID_HANDLE)
157 SetConVarBounds(g_Cvar_Bonusroundtime, ConVarBound_Upper, true, 30.0);
160 g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
161 g_MapVoteStartedForward = CreateGlobalForward("OnMapVoteStarted", ET_Ignore);
164 public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
166 RegPluginLibrary("mapchooser");
168 CreateNative("NominateMap", Native_NominateMap);
169 CreateNative("RemoveNominationByMap", Native_RemoveNominationByMap);
170 CreateNative("RemoveNominationByOwner", Native_RemoveNominationByOwner);
171 CreateNative("InitiateMapChooserVote", Native_InitiateVote);
172 CreateNative("CanMapChooserStartVote", Native_CanVoteStart);
173 CreateNative("HasEndOfMapVoteFinished", Native_CheckVoteDone);
174 CreateNative("GetExcludeMapList", Native_GetExcludeMapList);
175 CreateNative("GetNominatedMapList", Native_GetNominatedMapList);
176 CreateNative("EndOfMapVoteEnabled", Native_EndOfMapVoteEnabled);
178 return APLRes_Success;
181 public OnConfigsExecuted()
183 if (ReadMapList(g_MapList,
186 MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER)
190 if (g_mapFileSerial == -1)
192 LogError("Unable to create a valid map list.");
197 SetupTimeleftTimer();
203 g_MapVoteCompleted = false;
206 ClearArray(g_NominateList);
207 ClearArray(g_NominateOwners);
209 for (new i=0; i<MAXTEAMS; i++)
215 /* Check if mapchooser will attempt to start mapvote during bonus round time - TF2 Only */
216 if ((g_Cvar_Bonusroundtime != INVALID_HANDLE) && !GetConVarInt(g_Cvar_StartRounds))
218 if (GetConVarFloat(g_Cvar_Bonusroundtime) <= GetConVarFloat(g_Cvar_VoteDuration))
220 LogError("Warning - Bonus Round Time shorter than Vote Time. Votes during bonus round may not have time to complete");
227 g_HasVoteStarted = false;
228 g_WaitingForVote = false;
229 g_ChangeMapAtRoundEnd = false;
230 g_ChangeMapInProgress = false;
232 g_VoteTimer = INVALID_HANDLE;
233 g_RetryTimer = INVALID_HANDLE;
236 GetCurrentMap(map, sizeof(map));
237 PushArrayString(g_OldMapList, map);
239 if (GetArraySize(g_OldMapList) > GetConVarInt(g_Cvar_ExcludeMaps))
241 RemoveFromArray(g_OldMapList, 0);
245 public OnClientDisconnect(client)
247 new index = FindValueInArray(g_NominateOwners, client);
254 new String:oldmap[33];
255 GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap));
256 Call_StartForward(g_NominationsResetForward);
257 Call_PushString(oldmap);
258 Call_PushCell(GetArrayCell(g_NominateOwners, index));
261 RemoveFromArray(g_NominateOwners, index);
262 RemoveFromArray(g_NominateList, index);
266 public Action:Command_SetNextmap(client, args)
270 ReplyToCommand(client, "[SM] Usage: sm_setnextmap <map>");
271 return Plugin_Handled;
275 GetCmdArg(1, map, sizeof(map));
277 if (!IsMapValid(map))
279 ReplyToCommand(client, "[SM] %t", "Map was not found", map);
280 return Plugin_Handled;
283 ShowActivity(client, "%t", "Changed Next Map", map);
284 LogAction(client, -1, "\"%L\" changed nextmap to \"%s\"", client, map);
287 g_MapVoteCompleted = true;
289 return Plugin_Handled;
292 public OnMapTimeLeftChanged()
294 if (GetArraySize(g_MapList))
296 SetupTimeleftTimer();
303 if (GetMapTimeLeft(time) && time > 0)
305 new startTime = GetConVarInt(g_Cvar_StartTime) * 60;
306 if (time - startTime < 0 && GetConVarBool(g_Cvar_EndOfMapVote) && !g_MapVoteCompleted && !g_HasVoteStarted)
308 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
312 if (g_VoteTimer != INVALID_HANDLE)
314 KillTimer(g_VoteTimer);
315 g_VoteTimer = INVALID_HANDLE;
318 //g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE);
320 g_VoteTimer = CreateDataTimer(float(time - startTime), Timer_StartMapVote, data, TIMER_FLAG_NO_MAPCHANGE);
321 WritePackCell(data, _:MapChange_MapEnd);
322 WritePackCell(data, _:INVALID_HANDLE);
328 public Action:Timer_StartMapVote(Handle:timer, Handle:data)
330 if (timer == g_RetryTimer)
332 g_WaitingForVote = false;
333 g_RetryTimer = INVALID_HANDLE;
337 g_VoteTimer = INVALID_HANDLE;
340 if (!GetArraySize(g_MapList) || !GetConVarBool(g_Cvar_EndOfMapVote) || g_MapVoteCompleted || g_HasVoteStarted)
345 new MapChange:mapChange = MapChange:ReadPackCell(data);
346 new Handle:hndl = Handle:ReadPackCell(data);
348 InitiateVote(mapChange, hndl);
353 public Event_TFRestartRound(Handle:event, const String:name[], bool:dontBroadcast)
355 /* Game got restarted - reset our round count tracking */
359 public Event_TeamPlayWinPanel(Handle:event, const String:name[], bool:dontBroadcast)
361 if (g_ChangeMapAtRoundEnd)
363 g_ChangeMapAtRoundEnd = false;
364 CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
365 g_ChangeMapInProgress = true;
368 new bluescore = GetEventInt(event, "blue_score");
369 new redscore = GetEventInt(event, "red_score");
371 if(GetEventInt(event, "round_complete") == 1 || StrEqual(name, "arena_win_panel"))
375 if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted || !GetConVarBool(g_Cvar_EndOfMapVote))
380 CheckMaxRounds(g_TotalRounds);
382 switch(GetEventInt(event, "winning_team"))
386 CheckWinLimit(bluescore);
390 CheckWinLimit(redscore);
392 //We need to do nothing on winning_team == 0 this indicates stalemate.
400 /* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */
401 public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
403 if (g_ChangeMapAtRoundEnd)
405 g_ChangeMapAtRoundEnd = false;
406 CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
407 g_ChangeMapInProgress = true;
410 new winner = GetEventInt(event, "winner");
412 if (winner == 0 || winner == 1 || !GetConVarBool(g_Cvar_EndOfMapVote))
417 if (winner >= MAXTEAMS)
419 SetFailState("Mod exceed maximum team count - Please file a bug report.");
424 g_winCount[winner]++;
426 if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted)
431 CheckWinLimit(g_winCount[winner]);
432 CheckMaxRounds(g_TotalRounds);
435 public CheckWinLimit(winner_score)
437 if (g_Cvar_Winlimit != INVALID_HANDLE)
439 new winlimit = GetConVarInt(g_Cvar_Winlimit);
442 if (winner_score >= (winlimit - GetConVarInt(g_Cvar_StartRounds)))
444 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
450 public CheckMaxRounds(roundcount)
452 if (g_Cvar_Maxrounds != INVALID_HANDLE)
454 new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
457 if (roundcount >= (maxrounds - GetConVarInt(g_Cvar_StartRounds)))
459 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
465 public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
467 if (!GetArraySize(g_MapList) || g_Cvar_Fraglimit == INVALID_HANDLE || g_HasVoteStarted)
472 if (!GetConVarInt(g_Cvar_Fraglimit) || !GetConVarBool(g_Cvar_EndOfMapVote))
477 if (g_MapVoteCompleted)
482 new fragger = GetClientOfUserId(GetEventInt(event, "attacker"));
489 if (GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags)))
491 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
495 public Action:Command_Mapvote(client, args)
497 InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
499 return Plugin_Handled;
503 * Starts a new map vote
505 * @param when When the resulting map change should occur.
506 * @param inputlist Optional list of maps to use for the vote, otherwise an internal list of nominations + random maps will be used.
508 InitiateVote(MapChange:when, Handle:inputlist=INVALID_HANDLE)
510 g_WaitingForVote = true;
512 if (IsVoteInProgress())
514 // Can't start a vote, try again in 5 seconds.
515 //g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE);
518 g_RetryTimer = CreateDataTimer(5.0, Timer_StartMapVote, data, TIMER_FLAG_NO_MAPCHANGE);
519 WritePackCell(data, _:when);
520 WritePackCell(data, _:inputlist);
525 /* If the main map vote has completed (and chosen result) and its currently changing (not a delayed change) we block further attempts */
526 if (g_MapVoteCompleted && g_ChangeMapInProgress)
533 g_WaitingForVote = false;
535 g_HasVoteStarted = true;
536 g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
537 SetMenuTitle(g_VoteMenu, "Vote Nextmap");
538 SetVoteResultCallback(g_VoteMenu, Handler_MapVoteFinished);
540 /* Call OnMapVoteStarted() Forward */
541 Call_StartForward(g_MapVoteStartedForward);
545 * TODO: Make a proper decision on when to clear the nominations list.
546 * Currently it clears when used, and stays if an external list is provided.
547 * Is this the right thing to do? External lists will probably come from places
548 * like sm_mapvote from the adminmenu in the future.
553 /* No input given - User our internal nominations and maplist */
554 if (inputlist == INVALID_HANDLE)
556 new nominateCount = GetArraySize(g_NominateList);
557 new voteSize = GetConVarInt(g_Cvar_IncludeMaps);
559 /* Smaller of the two - It should be impossible for nominations to exceed the size though (cvar changed mid-map?) */
560 new nominationsToAdd = nominateCount >= voteSize ? voteSize : nominateCount;
563 for (new i=0; i<nominationsToAdd; i++)
565 GetArrayString(g_NominateList, i, map, sizeof(map));
566 AddMenuItem(g_VoteMenu, map, map);
568 /* Notify Nominations that this map is now free */
569 Call_StartForward(g_NominationsResetForward);
570 Call_PushString(map);
571 Call_PushCell(GetArrayCell(g_NominateOwners, i));
575 /* Clear out the rest of the nominations array */
576 for (new i=nominationsToAdd; i<nominateCount; i++)
578 GetArrayString(g_NominateList, i, map, sizeof(map));
580 /* Notify Nominations that this map is now free */
581 Call_StartForward(g_NominationsResetForward);
582 Call_PushString(map);
583 Call_PushCell(GetArrayCell(g_NominateOwners, i));
587 /* There should currently be 'nominationsToAdd' unique maps in the vote */
589 new i = nominationsToAdd;
591 new availableMaps = GetArraySize(g_NextMapList);
595 GetArrayString(g_NextMapList, count, map, sizeof(map));
598 //Check if this map is in the nominate list (and thus already in the vote) */
599 if (FindStringInArray(g_NominateList, map) == -1)
601 /* Insert the map and increment our count */
602 AddMenuItem(g_VoteMenu, map, map);
606 if (count >= availableMaps)
608 //Run out of maps, this will have to do.
613 /* Wipe out our nominations list - Nominations have already been informed of this */
614 ClearArray(g_NominateOwners);
615 ClearArray(g_NominateList);
617 else //We were given a list of maps to start the vote with
619 new size = GetArraySize(inputlist);
621 for (new i=0; i<size; i++)
623 GetArrayString(inputlist, i, map, sizeof(map));
627 AddMenuItem(g_VoteMenu, map, map);
632 /* Do we add any special items? */
633 if ((when == MapChange_Instant || when == MapChange_RoundEnd) && GetConVarBool(g_Cvar_DontChange))
635 AddMenuItem(g_VoteMenu, VOTE_DONTCHANGE, "Don't Change");
637 else if (GetConVarBool(g_Cvar_Extend) && g_Extends < GetConVarInt(g_Cvar_Extend))
639 AddMenuItem(g_VoteMenu, VOTE_EXTEND, "Extend Map");
642 new voteDuration = GetConVarInt(g_Cvar_VoteDuration);
644 SetMenuExitButton(g_VoteMenu, false);
645 VoteMenuToAll(g_VoteMenu, voteDuration);
647 LogAction(-1, -1, "Voting for next map has started.");
648 PrintToChatAll("[SM] %t", "Nextmap Voting Started");
651 public Handler_MapVoteFinished(Handle:menu,
654 const client_info[][2],
656 const item_info[][2])
660 LogError("No Votes recorded yet Advanced callback fired - Tell pRED* to fix this");
665 GetMenuItem(menu, item_info[0][VOTEINFO_ITEM_INDEX], map, sizeof(map));
667 if (strcmp(map, VOTE_EXTEND, false) == 0)
672 if (GetMapTimeLimit(time))
676 ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60);
680 if (g_Cvar_Winlimit != INVALID_HANDLE)
682 new winlimit = GetConVarInt(g_Cvar_Winlimit);
685 SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep));
689 if (g_Cvar_Maxrounds != INVALID_HANDLE)
691 new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
694 SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep));
698 if (g_Cvar_Fraglimit != INVALID_HANDLE)
700 new fraglimit = GetConVarInt(g_Cvar_Fraglimit);
703 SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep));
707 PrintToChatAll("[SM] %t", "Current Map Extended", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
708 LogAction(-1, -1, "Voting for next map has finished. The current map has been extended.");
710 // We extended, so we'll have to vote again.
711 g_HasVoteStarted = false;
713 SetupTimeleftTimer();
716 else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
718 PrintToChatAll("[SM] %t", "Current Map Stays", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
719 LogAction(-1, -1, "Voting for next map has finished. 'No Change' was the winner");
721 g_HasVoteStarted = false;
723 SetupTimeleftTimer();
727 if (g_ChangeTime == MapChange_MapEnd)
731 else if (g_ChangeTime == MapChange_Instant)
734 CreateDataTimer(2.0, Timer_ChangeMap, data);
735 WritePackString(data, map);
736 g_ChangeMapInProgress = false;
738 else // MapChange_RoundEnd
741 g_ChangeMapAtRoundEnd = true;
744 g_HasVoteStarted = false;
745 g_MapVoteCompleted = true;
747 PrintToChatAll("[SM] %t", "Nextmap Voting Finished", map, RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
748 LogAction(-1, -1, "Voting for next map has finished. Nextmap: %s.", map);
752 public Handler_MapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
758 g_VoteMenu = INVALID_HANDLE;
762 case MenuAction_Display:
764 decl String:buffer[255];
765 Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1);
767 new Handle:panel = Handle:param2;
768 SetPanelTitle(panel, buffer);
771 case MenuAction_DisplayItem:
773 if (GetMenuItemCount(menu) - 1 == param2)
775 decl String:map[64], String:buffer[255];
776 GetMenuItem(menu, param2, map, sizeof(map));
777 if (strcmp(map, VOTE_EXTEND, false) == 0)
779 Format(buffer, sizeof(buffer), "%T", "Extend Map", param1);
780 return RedrawMenuItem(buffer);
782 else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
784 Format(buffer, sizeof(buffer), "%T", "Dont Change", param1);
785 return RedrawMenuItem(buffer);
790 case MenuAction_VoteCancel:
792 // If we receive 0 votes, pick at random.
793 if (param1 == VoteCancel_NoVotes && GetConVarBool(g_Cvar_NoVoteMode))
795 new count = GetMenuItemCount(menu);
796 new item = GetRandomInt(0, count - 1);
798 GetMenuItem(menu, item, map, sizeof(map));
800 while (strcmp(map, VOTE_EXTEND, false) == 0)
802 item = GetRandomInt(0, count - 1);
803 GetMenuItem(menu, item, map, sizeof(map));
810 // We were actually cancelled. I guess we do nothing.
813 g_HasVoteStarted = false;
814 g_MapVoteCompleted = true;
821 public Action:Timer_ChangeMap(Handle:hTimer, Handle:dp)
823 g_ChangeMapInProgress = false;
827 if (dp == INVALID_HANDLE)
829 if (!GetNextMap(map, sizeof(map)))
831 //No passed map and no set nextmap. fail!
838 ReadPackString(dp, map, sizeof(map));
841 ForceChangeLevel(map, "Map Vote");
848 if(g_NextMapList != INVALID_HANDLE)
850 ClearArray(g_NextMapList);
854 new index, Handle:tempMaps = CloneArray(g_MapList);
856 GetCurrentMap(map, sizeof(map));
857 index = FindStringInArray(tempMaps, map);
860 RemoveFromArray(tempMaps, index);
863 if (GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps))
865 for (new i = 0; i < GetArraySize(g_OldMapList); i++)
867 GetArrayString(g_OldMapList, i, map, sizeof(map));
868 index = FindStringInArray(tempMaps, map);
871 RemoveFromArray(tempMaps, index);
876 new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(tempMaps) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(tempMaps));
877 for (new i = 0; i < limit; i++)
879 new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
880 GetArrayString(tempMaps, b, map, sizeof(map));
881 PushArrayString(g_NextMapList, map);
882 RemoveFromArray(tempMaps, b);
885 CloseHandle(tempMaps);
890 if (g_WaitingForVote || g_HasVoteStarted)
898 NominateResult:InternalNominateMap(String:map[], bool:force, owner)
900 if (!IsMapValid(map))
902 return Nominate_InvalidMap;
907 /* Look to replace an existing nomination by this client - Nominations made with owner = 0 aren't replaced */
908 if (owner && ((index = FindValueInArray(g_NominateOwners, owner)) != -1))
910 new String:oldmap[33];
911 GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap));
912 Call_StartForward(g_NominationsResetForward);
913 Call_PushString(oldmap);
914 Call_PushCell(owner);
917 SetArrayString(g_NominateList, index, map);
918 return Nominate_Replaced;
921 /* Too many nominated maps. */
922 if (g_NominateCount >= GetConVarInt(g_Cvar_IncludeMaps) && !force)
924 return Nominate_VoteFull;
927 /* Map already in the vote */
928 if (FindStringInArray(g_NominateList, map) != -1)
930 return Nominate_AlreadyInVote;
934 PushArrayString(g_NominateList, map);
935 PushArrayCell(g_NominateOwners, owner);
938 while (GetArraySize(g_NominateList) > GetConVarInt(g_Cvar_IncludeMaps))
940 new String:oldmap[33];
941 GetArrayString(g_NominateList, 0, oldmap, sizeof(oldmap));
942 Call_StartForward(g_NominationsResetForward);
943 Call_PushString(oldmap);
944 Call_PushCell(GetArrayCell(g_NominateOwners, 0));
947 RemoveFromArray(g_NominateList, 0);
948 RemoveFromArray(g_NominateOwners, 0);
951 return Nominate_Added;
954 /* Add natives to allow nominate and initiate vote to be call */
956 /* native bool:NominateMap(const String:map[], bool:force, &NominateError:error); */
957 public Native_NominateMap(Handle:plugin, numParams)
960 GetNativeStringLength(1, len);
967 new String:map[len+1];
968 GetNativeString(1, map, len+1);
970 return _:InternalNominateMap(map, GetNativeCell(2), GetNativeCell(3));
973 bool:InternalRemoveNominationByMap(String:map[])
975 for (new i = 0; i < GetArraySize(g_NominateList); i++)
977 new String:oldmap[33];
978 GetArrayString(g_NominateList, i, oldmap, sizeof(oldmap));
980 if(strcmp(map, oldmap, false) == 0)
982 Call_StartForward(g_NominationsResetForward);
983 Call_PushString(oldmap);
984 Call_PushCell(GetArrayCell(g_NominateOwners, i));
987 RemoveFromArray(g_NominateList, i);
988 RemoveFromArray(g_NominateOwners, i);
998 /* native bool:RemoveNominationByMap(const String:map[]); */
999 public Native_RemoveNominationByMap(Handle:plugin, numParams)
1002 GetNativeStringLength(1, len);
1009 new String:map[len+1];
1010 GetNativeString(1, map, len+1);
1012 return _:InternalRemoveNominationByMap(map);
1015 bool:InternalRemoveNominationByOwner(owner)
1019 if (owner && ((index = FindValueInArray(g_NominateOwners, owner)) != -1))
1021 new String:oldmap[33];
1022 GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap));
1024 Call_StartForward(g_NominationsResetForward);
1025 Call_PushString(oldmap);
1026 Call_PushCell(owner);
1029 RemoveFromArray(g_NominateList, index);
1030 RemoveFromArray(g_NominateOwners, index);
1039 /* native bool:RemoveNominationByOwner(owner); */
1040 public Native_RemoveNominationByOwner(Handle:plugin, numParams)
1042 return _:InternalRemoveNominationByOwner(GetNativeCell(1));
1045 /* native InitiateMapChooserVote(); */
1046 public Native_InitiateVote(Handle:plugin, numParams)
1048 new MapChange:when = MapChange:GetNativeCell(1);
1049 new Handle:inputarray = Handle:GetNativeCell(2);
1051 LogAction(-1, -1, "Starting map vote because outside request");
1052 InitiateVote(when, inputarray);
1055 public Native_CanVoteStart(Handle:plugin, numParams)
1057 return CanVoteStart();
1060 public Native_CheckVoteDone(Handle:plugin, numParams)
1062 return g_MapVoteCompleted;
1065 public Native_EndOfMapVoteEnabled(Handle:plugin, numParams)
1067 return GetConVarBool(g_Cvar_EndOfMapVote);
1070 public Native_GetExcludeMapList(Handle:plugin, numParams)
1072 new Handle:array = Handle:GetNativeCell(1);
1074 if (array == INVALID_HANDLE)
1078 new size = GetArraySize(g_OldMapList);
1079 decl String:map[33];
1081 for (new i=0; i<size; i++)
1083 GetArrayString(g_OldMapList, i, map, sizeof(map));
1084 PushArrayString(array, map);
1090 public Native_GetNominatedMapList(Handle:plugin, numParams)
1092 new Handle:maparray = Handle:GetNativeCell(1);
1093 new Handle:ownerarray = Handle:GetNativeCell(2);
1095 if (maparray == INVALID_HANDLE)
1098 decl String:map[33];
1100 for (new i = 0; i < GetArraySize(g_NominateList); i++)
1102 GetArrayString(g_NominateList, i, map, sizeof(map));
1103 PushArrayString(maparray, map);
1105 // If the optional parameter for an owner list was passed, then we need to fill that out as well
1106 if(ownerarray != INVALID_HANDLE)
1108 new index = GetArrayCell(g_NominateOwners, i);
1109 PushArrayCell(ownerarray, index);