Big changes to dynamic menu. Removed constant kv tracking. Tested everything.
Import of config files.
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>.
38 public Plugin:myinfo =
41 author = "AlliedModders LLC",
42 description = "Map Management",
43 version = SOURCEMOD_VERSION,
44 url = "http://www.sourcemod.net/"
47 #include "mapmanagement/globals.sp"
48 #include "mapmanagement/commands.sp"
49 #include "mapmanagement/events.sp"
50 #include "mapmanagement/functions.sp"
51 #include "mapmanagement/menus.sp"
52 #include "mapmanagement/timers.sp"
53 #include "mapmanagement/votes.sp"
55 public OnPluginStart()
57 LoadTranslations("mapmanager.phrases");
59 // Prepare nextmap functionality.
60 g_VGUIMenu = GetUserMessageId("VGUIMenu");
61 if (g_VGUIMenu == INVALID_MESSAGE_ID)
63 LogError("FATAL: Cannot find VGUIMenu user message id. MapManager crippled.");
64 g_NextMapEnabled = false;
66 HookUserMessage(g_VGUIMenu, UserMsg_VGUIMenu);
68 // Create all of the arrays, sized for a 64 character string.
69 new arraySize = ByteCountToCells(64);
70 g_MapCycle = CreateArray(arraySize);
71 g_MapList = CreateArray(arraySize);
72 g_MapHistory = CreateArray(arraySize);
73 g_NextVoteMaps = CreateArray(arraySize);
74 g_SelectedMaps = CreateArray(arraySize);
75 g_NominatedMaps = CreateArray(arraySize);
77 g_TeamScores = CreateArray(2);
80 RegConsoleCmd("say", Command_Say);
81 RegConsoleCmd("say_team", Command_Say);
83 // Register all commands.
84 RegAdminCmd("sm_map", Command_Map, ADMFLAG_CHANGEMAP, "sm_map <map> [r/e]");
85 RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap <map>");
86 RegAdminCmd("sm_votemap", Command_Votemap, ADMFLAG_VOTE|ADMFLAG_CHANGEMAP, "sm_votemap <mapname> [mapname2] ... [mapname5] ");
87 RegAdminCmd("sm_maplist", Command_List, ADMFLAG_GENERIC, "sm_maplist");
88 RegAdminCmd("sm_nominate", Command_Addmap, ADMFLAG_CHANGEMAP, "sm_nominate <mapname> - Nominates a map for RockTheVote and MapChooser. Overrides existing nominations.");
89 RegAdminCmd("sm_mapvote", Command_Mapvote, ADMFLAG_CHANGEMAP, "sm_mapvote - Forces the MapChooser vote to occur.");
91 if (GetCommandFlags("nextmap") == INVALID_FCVAR_FLAGS)
93 RegServerCmd("nextmap", Command_Nextmap);
96 // Register all convars
97 g_Cvar_Nextmap = CreateConVar("sm_nextmap", "", "Sets the Next Map", FCVAR_NOTIFY);
99 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);
100 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);
102 g_Cvar_MapChooser = CreateConVar("sm_mm_mapchooser", "0", "Enables MapChooser (End of Map voting)", 0, true, 0.0, true, 1.0);
103 g_Cvar_RockTheVote = CreateConVar("sm_mm_rockthevote", "0", "Enables RockTheVote (Player initiated map votes)", 0, true, 0.0, true, 1.0);
104 g_Cvar_Randomize = CreateConVar("sm_mm_randomize", "0", "Enabled Randomizer (Randomly picks the next map)", 0, true, 0.0, true, 1.0);
105 g_Cvar_Nominate = CreateConVar("sm_mm_nominate", "1", "Enables nomination system.", 0, true, 0.0, true, 1.0);
107 g_Cvar_VoteMap = CreateConVar("sm_mm_votemap", "0.60", "Percentage required for successful sm_votemap.", 0, true, 0.05, true, 1.0);
108 g_Cvar_RTVLimit = CreateConVar("sm_mm_rtvlimit", "0.60", "Required percentage of players needed to rockthevote", 0, true, 0.05, true, 1.0);
109 g_Cvar_MinPlayers = CreateConVar("sm_mm_minplayers", "0", "Number of players required before RTV will be enabled.", 0, true, 0.0, true, float(MAXPLAYERS));
111 g_Cvar_StartTime = CreateConVar("sm_mapvote_start", "3.0", "Specifies when to start the vote based on time remaining.", _, true, 1.0);
112 g_Cvar_StartRounds = CreateConVar("sm_mapvote_startround", "2.0", "Specifies when to start the vote based on rounds remaining.", _, true, 1.0);
113 g_Cvar_StartFrags = CreateConVar("sm_mapvote_startfrags", "5.0", "Specifies when to start the vote base on frags remaining.", _, true, 1.0);
114 g_Cvar_ExtendTimeMax = CreateConVar("sm_extendmap_maxtime", "90", "Specifies the maximum amount of time a map can be extended", _, true, 0.0);
115 g_Cvar_ExtendTimeStep = CreateConVar("sm_extendmap_timestep", "15", "Specifies how much many more minutes each extension makes", _, true, 5.0);
116 g_Cvar_ExtendRoundMax = CreateConVar("sm_extendmap_maxrounds", "30", "Specfies the maximum amount of rounds a map can be extended", _, true, 0.0);
117 g_Cvar_ExtendRoundStep = CreateConVar("sm_extendmap_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 5.0);
118 g_Cvar_ExtendFragMax = CreateConVar("sm_extendmap_maxfrags", "150", "Specfies the maximum frags allowed that a map can be extended.", _, true, 0.0);
119 g_Cvar_ExtendFragStep = CreateConVar("sm_extendmap_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0);
120 g_Cvar_Mapfile = CreateConVar("sm_mapvote_file", "configs/maps.ini", "Map file to use. (Def sourcemod/configs/maps.ini)");
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", "1", "Specifies whether or not MapChooser will allow the map to be extended.", _, true, 0.0, true, 1.0);
127 g_Cvar_Chattime = FindConVar("mp_chattime");
128 g_Cvar_Winlimit = FindConVar("mp_winlimit");
129 g_Cvar_Maxrounds = FindConVar("mp_maxrounds");
130 g_Cvar_Fraglimit = FindConVar("mp_fraglimit");
132 if (GetCommandFlags("nextmap") == INVALID_FCVAR_FLAGS)
134 RegServerCmd("nextmap", Command_Nextmap);
138 HookEvent("round_end", Event_RoundEnd); // We always require round_end
139 if (g_Cvar_Fraglimit != INVALID_HANDLE)
141 HookEvent("player_death", Event_PlayerDeath);
144 // Set to the current map so OnMapStart() will know what to do
145 decl String:currentMap[64];
146 GetCurrentMap(currentMap, 64);
147 SetNextmap(currentMap);
149 // Create necessary menus for TopMenu
150 g_Menu_Map = CreateMenu(MenuHandler_Map);
151 SetMenuTitle(g_Menu_Map, "Please select a map");
152 SetMenuExitBackButton(g_Menu_Map, true);
154 g_Menu_Votemap = CreateMenu(MenuHandler_VoteMap, MenuAction_DrawItem);
155 SetMenuTitle(g_Menu_Votemap, "Please select a map");
156 SetMenuExitBackButton(g_Menu_Votemap, true);
158 // Bind TopMenu commands to adminmenu_maplist.ini, in cases it doesn't exist in maplists.cfg
159 decl String:mapListPath[PLATFORM_MAX_PATH];
160 BuildPath(Path_SM, mapListPath, sizeof(mapListPath), "configs/adminmenu_maplist.ini");
161 SetMapListCompatBind("sm_map menu", mapListPath);
162 SetMapListCompatBind("sm_votemap menu", mapListPath);
164 // Account for late loading
166 if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
168 OnAdminMenuReady(topmenu);
171 AutoExecConfig(true, "mapmanager");
174 public OnAdminMenuReady(Handle:topmenu)
176 /* Block us from being called twice */
177 if (topmenu == hTopMenu)
182 /* Save the Handle */
185 new TopMenuObject:server_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_SERVERCOMMANDS);
187 if (server_commands != INVALID_TOPMENUOBJECT)
189 AddToTopMenu(hTopMenu,
198 new TopMenuObject:voting_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_VOTINGCOMMANDS);
200 if (voting_commands != INVALID_TOPMENUOBJECT)
202 AddToTopMenu(hTopMenu,
208 ADMFLAG_VOTE|ADMFLAG_CHANGEMAP);
212 public OnLibraryRemoved(const String:name[])
214 if (strcmp(name, "adminmenu") == 0)
216 hTopMenu = INVALID_HANDLE;
220 public OnConfigsExecuted()
222 // Add map logic here
224 // Get the current and last maps.
225 decl String:lastMap[64], String:currentMap[64];
226 GetConVarString(g_Cvar_Nextmap, lastMap, 64);
227 GetCurrentMap(currentMap, 64);
229 // 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
230 // some other plugin/command), we don't want to scramble the map cycle. Or for example, admin switches to a custom map
231 // not in mapcyclefile. So we keep it set to the last expected nextmap. - ferret
232 if (strcmp(lastMap, currentMap) == 0)
237 // Build map menus for sm_map, sm_votemap, and RTV.
238 BuildMapMenu(g_Menu_Map, list);
239 BuildMapMenu(g_Menu_VoteMap, list);
241 // If the Randomize option is on, randomize!
242 if (GetConVarBool(g_Cvar_Randomize))
244 CreateTimer(5.0, Timer_RandomizeNextmap);
247 // If MapChooser is active, start it up!
248 if (GetConVarBool(g_Cvar_MapChooser))
250 SetupTimeleftTimer();
251 SetConVarString(g_Cvar_Nextmap, "Pending Vote");
254 // If RockTheVote is active, start it up!
255 if (GetConVarBool(g_Cvar_RockTheVote))
257 BuildMapMenu(g_Menu_RTV, list);
258 CreateTimer(30.0, Timer_DelayRTV);
262 // Reinitialize all our various globals
265 if (g_Nominate != INVALID_HANDLE)
267 ClearArray(g_Nominate);
270 if (g_TeamScores != INVALID_HANDLE)
272 ClearArray(g_TeamScores);
279 g_RTV_VotesNeeded = 0;
280 g_RTV_Started = false;
284 // Reset globals as necessary and kill timers
287 g_IntermissionCalled = false;
288 g_HasVoteStarted = false;
290 g_RTV_Allowed = false;
292 if (g_VoteTimer != INVALID_HANDLE)
294 KillTimer(g_VoteTimer);
295 g_VoteTimer = INVALID_HANDLE;
298 if (g_RetryTimer != INVALID_HANDLE)
300 KillTimer(g_RetryTimer);
301 g_RetryTimer = INVALID_HANDLE;
305 public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
307 if (IsFakeClient(client))
312 // If RTV is active, deal with vote counting.
313 if (GetConVarBool(g_Cvar_RockTheVote))
315 g_RTV_Voted[client] = false;
317 g_RTV_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
320 // If Nominate is active, let the new client nominate
321 if (GetConVarBool(g_Cvar_Nominate))
323 g_Nominated[client] = false;
329 public OnClientDisconnect(client)
331 if (IsFakeClient(client))
336 // If RTV is active, deal with vote counting.
337 if (GetConVarBool(g_Cvar_RockTheVote))
339 if(g_RTV_Voted[client])
345 g_RTV_VotesNeeded = RoundToFloor(float(g_RTV_Voters) * GetConVarFloat(g_Cvar_RTVLimit));
347 // If this client caused us to fall below the RTV threshold and its allowed be started, start it.
348 if (g_RTV_Votes && g_RTV_Voters && g_RTV_Votes >= g_RTV_VotesNeeded && g_RTV_Allowed && !g_RTV_Started)
350 g_RTV_Started = true;
351 CreateTimer(2.0, Timer_StartRTV, TIMER_FLAG_NO_MAPCHANGE);
356 public OnMapTimeLeftChanged()
358 if (GetConVarBool(g_Cvar_MapChooser))
360 SetupTimeleftTimer();