3 * =============================================================================
4 * SourceMod Basecommands Plugin
5 * Provides map functionality
7 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
8 * =============================================================================
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License, version 3.0, as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
22 * As a special exception, AlliedModders LLC gives you permission to link the
23 * code of this program (as well as its derivative works) to "Half-Life 2," the
24 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
25 * by the Valve Corporation. You must obey the GNU General Public License in
26 * all respects for all other code used. Additionally, AlliedModders LLC grants
27 * this exception to all derivative works. AlliedModders LLC defines further
28 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
29 * or <http://www.sourcemod.net/license.php>.
34 public MenuHandler_ChangeMap(Handle:menu, MenuAction:action, param1, param2)
36 if (action == MenuAction_Cancel)
38 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
40 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
43 else if (action == MenuAction_Select)
47 GetMenuItem(menu, param2, map, sizeof(map));
49 ShowActivity2(param1, "[SM] ", "%t", "Changing map", map);
51 LogAction(param1, -1, "\"%L\" changed map to \"%s\"", param1, map);
54 CreateDataTimer(3.0, Timer_ChangeMap, dp);
55 WritePackString(dp, map);
60 public AdminMenu_Map(Handle:topmenu,
62 TopMenuObject:object_id,
67 if (action == TopMenuAction_DisplayOption)
69 Format(buffer, maxlength, "%T", "Choose Map", param);
71 else if (action == TopMenuAction_SelectOption)
73 DisplayMenu(g_MapList, param, MENU_TIME_FOREVER);
77 public Action:Command_Map(client, args)
81 ReplyToCommand(client, "[SM] Usage: sm_map <map>");
82 return Plugin_Handled;
86 GetCmdArg(1, map, sizeof(map));
90 ReplyToCommand(client, "[SM] %t", "Map was not found", map);
91 return Plugin_Handled;
94 ShowActivity2(client, "[SM] ", "%t", "Changing map", map);
96 LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map);
99 CreateDataTimer(3.0, Timer_ChangeMap, dp);
100 WritePackString(dp, map);
102 return Plugin_Handled;
105 public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
110 ReadPackString(dp, map, sizeof(map));
112 ForceChangeLevel(map, "sm_map Command");
117 new Handle:g_map_array = INVALID_HANDLE;
118 new g_map_serial = -1;
120 LoadMapList(Handle:menu)
122 new Handle:map_array;
124 if ((map_array = ReadMapList(g_map_array,
127 MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER))
130 g_map_array = map_array;
133 if (g_map_array == INVALID_HANDLE)
138 RemoveAllMenuItems(menu);
140 decl String:map_name[64];
141 new map_count = GetArraySize(g_map_array);
143 for (new i = 0; i < map_count; i++)
145 GetArrayString(g_map_array, i, map_name, sizeof(map_name));
146 AddMenuItem(menu, map_name, map_name);