looks like valve is trying to degrade radio menus to deprecate them. thanks guys, quality!
3 * =============================================================================
4 * SourceMod Map Management Plugin
5 * Provides all map related functionality, including map changing, map voting,
8 * SourceMod (C)2004-2008 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 = "Map Management",
45 version = SOURCEMOD_VERSION,
46 url = "http://www.sourcemod.net/"
49 #include "mapmanager/globals.sp"
50 #include "mapmanager/commands.sp"
51 #include "mapmanager/events.sp"
52 #include "mapmanager/functions.sp"
53 #include "mapmanager/functions_menu.sp"
54 #include "mapmanager/menus.sp"
55 #include "mapmanager/timers.sp"
56 #include "mapmanager/votes.sp"
58 public OnPluginStart()
60 LoadTranslations("mapmanager.phrases");
62 // Prepare nextmap functionality.
63 g_VGUIMenu = GetUserMessageId("VGUIMenu");
64 if (g_VGUIMenu == INVALID_MESSAGE_ID)
66 LogError("FATAL: Cannot find VGUIMenu user message id. MapManager crippled.");
67 g_NextMapEnabled = false;
69 HookUserMessage(g_VGUIMenu, UserMsg_VGUIMenu);
71 // Create all of the arrays, sized for a 64 character string.
72 new arraySize = ByteCountToCells(64);
73 g_MapCycle = CreateArray(arraySize);
74 g_MapList = CreateArray(arraySize);
75 g_MapHistory = CreateArray(arraySize);
76 g_NextVoteMaps = CreateArray(arraySize);
77 g_SelectedMaps = CreateArray(arraySize);
78 g_NominatedMaps = CreateArray(arraySize);
80 g_TeamScores = CreateArray(2);
83 RegConsoleCmd("say", Command_Say);
84 RegConsoleCmd("say_team", Command_Say);
86 // Register all commands.
87 RegAdminCmd("sm_map", Command_Map, ADMFLAG_CHANGEMAP, "sm_map <map> [r/e]");
88 RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap <map>");
89 RegAdminCmd("sm_votemap", Command_Votemap, ADMFLAG_VOTE|ADMFLAG_CHANGEMAP, "sm_votemap <mapname> [mapname2] ... [mapname5] ");
90 RegAdminCmd("sm_maplist", Command_List, ADMFLAG_GENERIC, "sm_maplist");
91 RegAdminCmd("sm_nominate", Command_Nominate, ADMFLAG_CHANGEMAP, "sm_nominate <mapname> - Nominates a map for RockTheVote and MapChooser. Overrides existing nominations.");
92 RegAdminCmd("sm_mapvote", Command_Mapvote, ADMFLAG_CHANGEMAP, "sm_mapvote - Forces the MapChooser vote to occur.");
94 if (GetCommandFlags("nextmap") == INVALID_FCVAR_FLAGS)
96 RegServerCmd("nextmap", Command_Nextmap);
99 // Register all convars
100 g_Cvar_NextMap = CreateConVar("sm_nextmap", "", "Sets the Next Map", FCVAR_NOTIFY);
102 g_Cvar_MapCount = CreateConVar("sm_mm_maps", "4", "Number of maps to be voted on at end of map or RTV. 2 to 6. (Def 4)", 0, true, 2.0, true, 6.0);
103 g_Cvar_Excludes = CreateConVar("sm_mm_exclude", "5", "Specifies how many past maps to exclude from end of map vote and RTV.", _, true, 0.0);
105 g_Cvar_MapChooser = CreateConVar("sm_mm_mapchooser", "0", "Enables MapChooser (End of Map voting)", 0, true, 0.0, true, 1.0);
106 g_Cvar_RockTheVote = CreateConVar("sm_mm_rockthevote", "0", "Enables RockTheVote (Player initiated map votes)", 0, true, 0.0, true, 1.0);
107 g_Cvar_Randomize = CreateConVar("sm_mm_randomize", "0", "Enabled Randomizer (Randomly picks the next map)", 0, true, 0.0, true, 1.0);
108 g_Cvar_Nominate = CreateConVar("sm_mm_nominate", "1", "Enables nomination system.", 0, true, 0.0, true, 1.0);
110 g_Cvar_VoteMap = CreateConVar("sm_mm_votemap", "0.60", "Percentage required for successful sm_votemap.", 0, true, 0.05, true, 1.0);
111 g_Cvar_RTVLimit = CreateConVar("sm_mm_rtvlimit", "0.60", "Required percentage of players needed to rockthevote", 0, true, 0.05, true, 1.0);
112 g_Cvar_MinPlayers = CreateConVar("sm_mm_minplayers", "0", "Number of players required before RTV will be enabled.", 0, true, 0.0, true, float(MAXPLAYERS));
114 g_Cvar_StartTime = CreateConVar("sm_mapvote_start", "3.0", "Specifies when to start the vote based on time remaining.", _, true, 1.0);
115 g_Cvar_StartRounds = CreateConVar("sm_mapvote_startround", "2.0", "Specifies when to start the vote based on rounds remaining.", _, true, 1.0);
116 g_Cvar_StartFrags = CreateConVar("sm_mapvote_startfrags", "5.0", "Specifies when to start the vote base on frags remaining.", _, true, 1.0);
117 g_Cvar_ExtendTimeMax = CreateConVar("sm_extendmap_maxtime", "90", "Specifies the maximum amount of time a map can be extended", _, true, 0.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_ExtendRoundMax = CreateConVar("sm_extendmap_maxrounds", "30", "Specfies the maximum amount of rounds a map can be extended", _, true, 0.0);
120 g_Cvar_ExtendRoundStep = CreateConVar("sm_extendmap_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 5.0);
121 g_Cvar_ExtendFragMax = CreateConVar("sm_extendmap_maxfrags", "150", "Specfies the maximum frags allowed that a map can be extended.", _, true, 0.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_Mapfile = CreateConVar("sm_mapvote_file", "configs/maps.ini", "Map file to use. (Def sourcemod/configs/maps.ini)");
124 g_Cvar_ExcludeMaps = CreateConVar("sm_mapvote_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0);
125 g_Cvar_IncludeMaps = CreateConVar("sm_mapvote_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 6.0);
126 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);
127 g_Cvar_Extend = CreateConVar("sm_mapvote_extend", "1", "Specifies whether or not MapChooser will allow the map to be extended.", _, true, 0.0, true, 1.0);
131 g_Cvar_Chattime = FindConVar("mp_chattime");
132 g_Cvar_Winlimit = FindConVar("mp_winlimit");
133 g_Cvar_Maxrounds = FindConVar("mp_maxrounds");
134 g_Cvar_Fraglimit = FindConVar("mp_fraglimit");
136 if (GetCommandFlags("nextmap") == INVALID_FCVAR_FLAGS)
138 RegServerCmd("nextmap", Command_Nextmap);
142 HookEvent("round_end", Event_RoundEnd); // We always require round_end
143 if (g_Cvar_Fraglimit != INVALID_HANDLE)
145 HookEvent("player_death", Event_PlayerDeath);
148 // Set to the current map so OnMapStart() will know what to do
149 decl String:currentMap[64];
150 GetCurrentMap(currentMap, 64);
151 SetNextMap(currentMap);
153 // Create necessary menus for TopMenu
154 g_Menu_Map = CreateMenu(MenuHandler_Map);
155 SetMenuTitle(g_Menu_Map, "Please select a map");
156 SetMenuExitBackButton(g_Menu_Map, true);
158 g_Menu_Votemap = CreateMenu(MenuHandler_VoteMap, MenuAction_DrawItem);
159 SetMenuTitle(g_Menu_Votemap, "Please select a map");
160 SetMenuExitBackButton(g_Menu_Votemap, true);
162 // Bind TopMenu commands to adminmenu_maplist.ini, in cases it doesn't exist in maplists.cfg
163 decl String:mapListPath[PLATFORM_MAX_PATH];
164 BuildPath(Path_SM, mapListPath, sizeof(mapListPath), "configs/adminmenu_maplist.ini");
165 SetMapListCompatBind("sm_map menu", mapListPath);
166 SetMapListCompatBind("sm_votemap menu", mapListPath);
168 // Account for late loading
170 if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
172 OnAdminMenuReady(topmenu);
175 AutoExecConfig(true, "mapmanager");
178 public OnAdminMenuReady(Handle:topmenu)
180 /* Block us from being called twice */
181 if (topmenu == hTopMenu)
186 /* Save the Handle */
189 new TopMenuObject:server_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_SERVERCOMMANDS);
191 if (server_commands != INVALID_TOPMENUOBJECT)
193 AddToTopMenu(hTopMenu,
202 new TopMenuObject:voting_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_VOTINGCOMMANDS);
204 if (voting_commands != INVALID_TOPMENUOBJECT)
206 AddToTopMenu(hTopMenu,
212 ADMFLAG_VOTE|ADMFLAG_CHANGEMAP);
216 public OnLibraryRemoved(const String:name[])
218 if (strcmp(name, "adminmenu") == 0)
220 hTopMenu = INVALID_HANDLE;
224 public OnConfigsExecuted()
226 // Add map logic here
228 // Get the current and last maps.
229 decl String:lastMap[64], String:currentMap[64];
230 GetConVarString(g_Cvar_NextMap, lastMap, 64);
231 GetCurrentMap(currentMap, 64);
233 // Why am I doing this? If we switched to a new map, but it wasn't what we expected (Due to sm_map, sm_votemap, or
234 // some other plugin/command), we don't want to scramble the map cycle. Or for example, admin switches to a custom map
235 // not in mapcyclefile. So we keep it set to the last expected nextmap. - ferret
236 if (strcmp(lastMap, currentMap) == 0)
241 // Build map menus for sm_map, sm_votemap, and RTV.
242 /* TODO: Figure out wtf I'm supposed to do here */
243 BuildMapMenu(g_Menu_Map);
244 BuildMapMenu(g_Menu_Votemap);
247 // If the Randomize option is on, randomize!
248 if (GetConVarBool(g_Cvar_Randomize))
250 CreateTimer(5.0, Timer_RandomizeNextmap);
253 // If MapChooser is active, start it up!
254 if (GetConVarBool(g_Cvar_MapChooser))
256 SetupTimeleftTimer();
257 SetConVarString(g_Cvar_NextMap, "Pending Vote");
261 // If RockTheVote is active, start it up!
262 if (GetConVarBool(g_Cvar_RockTheVote))
264 BuildMapMenu(g_Menu_RTV, list);
265 CreateTimer(30.0, Timer_DelayRTV);
270 // Reinitialize all our various globals
273 if (g_Menu_Nominate != INVALID_HANDLE)
275 ClearArray(g_Menu_Nominate);
278 if (g_TeamScores != INVALID_HANDLE)
280 ClearArray(g_TeamScores);
287 g_RTV_VotesNeeded = 0;
288 g_RTV_Started = false;
292 // Reset globals as necessary and kill timers
295 g_IntermissionCalled = false;
296 g_HasVoteStarted = false;
298 g_RTV_Allowed = false;
300 if (g_VoteTimer != INVALID_HANDLE)
302 KillTimer(g_VoteTimer);
303 g_VoteTimer = INVALID_HANDLE;
306 if (g_RetryTimer != INVALID_HANDLE)
308 KillTimer(g_RetryTimer);
309 g_RetryTimer = INVALID_HANDLE;
313 public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
315 if (IsFakeClient(client))
320 // If RTV is active, deal with vote counting.
321 if (GetConVarBool(g_Cvar_RockTheVote))
323 g_RTV_Voted[client] = false;
325 g_RTV_VotesNeeded = RoundToFloor(float(g_RTV_Voters) * GetConVarFloat(g_Cvar_RTVLimit));
328 // If Nominate is active, let the new client nominate
329 if (GetConVarBool(g_Cvar_Nominate))
331 g_Nominated[client] = false;
337 public OnClientDisconnect(client)
339 if (IsFakeClient(client))
344 // If RTV is active, deal with vote counting.
345 if (GetConVarBool(g_Cvar_RockTheVote))
347 if(g_RTV_Voted[client])
353 g_RTV_VotesNeeded = RoundToFloor(float(g_RTV_Voters) * GetConVarFloat(g_Cvar_RTVLimit));
355 // If this client caused us to fall below the RTV threshold and its allowed be started, start it.
356 if (g_RTV_Votes && g_RTV_Voters && g_RTV_Votes >= g_RTV_VotesNeeded && g_RTV_Allowed && !g_RTV_Started)
358 g_RTV_Started = true;
359 CreateTimer(2.0, Timer_StartRTV, TIMER_FLAG_NO_MAPCHANGE);
364 public OnMapTimeLeftChanged()
366 if (GetConVarBool(g_Cvar_MapChooser))
368 SetupTimeleftTimer();