ferret99gt@1789: /** ferret99gt@1789: * vim: set ts=4 : ferret99gt@1789: * ============================================================================= ferret99gt@1789: * SourceMod Basecommands Plugin ferret99gt@1789: * Provides map functionality ferret99gt@1789: * ds@1947: * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. ferret99gt@1789: * ============================================================================= ferret99gt@1789: * ferret99gt@1789: * This program is free software; you can redistribute it and/or modify it under ferret99gt@1789: * the terms of the GNU General Public License, version 3.0, as published by the ferret99gt@1789: * Free Software Foundation. ferret99gt@1789: * ferret99gt@1789: * This program is distributed in the hope that it will be useful, but WITHOUT ferret99gt@1789: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ferret99gt@1789: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ferret99gt@1789: * details. ferret99gt@1789: * ferret99gt@1789: * You should have received a copy of the GNU General Public License along with ferret99gt@1789: * this program. If not, see . ferret99gt@1789: * ferret99gt@1789: * As a special exception, AlliedModders LLC gives you permission to link the ferret99gt@1789: * code of this program (as well as its derivative works) to "Half-Life 2," the ferret99gt@1789: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ferret99gt@1789: * by the Valve Corporation. You must obey the GNU General Public License in ferret99gt@1789: * all respects for all other code used. Additionally, AlliedModders LLC grants ferret99gt@1789: * this exception to all derivative works. AlliedModders LLC defines further ferret99gt@1789: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ferret99gt@1789: * or . ferret99gt@1789: * ds@1990: * Version: $Id$ ferret99gt@1789: */ ferret99gt@1789: pred@1536: public MenuHandler_ChangeMap(Handle:menu, MenuAction:action, param1, param2) pred@1536: { pred@1536: if (action == MenuAction_Cancel) pred@1536: { pred@1536: if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE) pred@1536: { pred@1536: DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory); pred@1536: } pred@1536: } pred@1536: else if (action == MenuAction_Select) pred@1536: { pred@1536: decl String:map[64]; pred@1536: pred@1536: GetMenuItem(menu, param2, map, sizeof(map)); pred@1536: dvander@1623: ShowActivity2(param1, "[SM] ", "%t", "Changing map", map); pred@1536: pred@1536: LogAction(param1, -1, "\"%L\" changed map to \"%s\"", param1, map); pred@1536: pred@1536: new Handle:dp; pred@1536: CreateDataTimer(3.0, Timer_ChangeMap, dp); pred@1536: WritePackString(dp, map); pred@1536: pred@1536: } pred@1536: } pred@1536: pred@1536: public AdminMenu_Map(Handle:topmenu, pred@1536: TopMenuAction:action, pred@1536: TopMenuObject:object_id, pred@1536: param, pred@1536: String:buffer[], pred@1536: maxlength) pred@1536: { pred@1536: if (action == TopMenuAction_DisplayOption) pred@1536: { pred@1536: Format(buffer, maxlength, "%T", "Choose Map", param); pred@1536: } pred@1536: else if (action == TopMenuAction_SelectOption) pred@1536: { pred@1536: DisplayMenu(g_MapList, param, MENU_TIME_FOREVER); pred@1536: } pred@1536: } pred@1536: pred@1536: public Action:Command_Map(client, args) pred@1536: { pred@1536: if (args < 1) pred@1536: { pred@1536: ReplyToCommand(client, "[SM] Usage: sm_map "); pred@1536: return Plugin_Handled; pred@1536: } pred@1536: pred@1536: decl String:map[64]; pred@1536: GetCmdArg(1, map, sizeof(map)); pred@1536: pred@1536: if (!IsMapValid(map)) pred@1536: { pred@1536: ReplyToCommand(client, "[SM] %t", "Map was not found", map); pred@1536: return Plugin_Handled; pred@1536: } pred@1536: dvander@1623: ShowActivity2(client, "[SM] ", "%t", "Changing map", map); pred@1536: pred@1536: LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map); pred@1536: pred@1536: new Handle:dp; pred@1536: CreateDataTimer(3.0, Timer_ChangeMap, dp); pred@1536: WritePackString(dp, map); pred@1536: pred@1536: return Plugin_Handled; pred@1536: } pred@1536: pred@1536: public Action:Timer_ChangeMap(Handle:timer, Handle:dp) pred@1536: { pred@1536: decl String:map[65]; pred@1536: pred@1536: ResetPack(dp); pred@1536: ReadPackString(dp, map, sizeof(map)); pred@1536: pred@2203: ForceChangeLevel(map, "sm_map Command"); pred@1536: pred@1536: return Plugin_Stop; pred@1536: } pred@1536: dvander@1738: new Handle:g_map_array = INVALID_HANDLE; dvander@1738: new g_map_serial = -1; dvander@1738: ferret99gt@1606: LoadMapList(Handle:menu) pred@1536: { dvander@1738: new Handle:map_array; pred@1536: dvander@1738: if ((map_array = ReadMapList(g_map_array, dvander@1738: g_map_serial, pred@1740: "sm_map menu", dvander@1738: MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER)) dvander@1738: != INVALID_HANDLE) pred@1536: { dvander@1738: g_map_array = map_array; pred@1536: } pred@1536: dvander@1738: if (g_map_array == INVALID_HANDLE) pred@1536: { pred@1580: return 0; pred@1580: } pred@1580: dvander@1738: RemoveAllMenuItems(menu); pred@1580: dvander@1738: decl String:map_name[64]; dvander@1738: new map_count = GetArraySize(g_map_array); dvander@1738: dvander@1738: for (new i = 0; i < map_count; i++) pred@1580: { dvander@1738: GetArrayString(g_map_array, i, map_name, sizeof(map_name)); dvander@1738: AddMenuItem(menu, map_name, map_name); dvander@1738: } dvander@1738: dvander@1738: return map_count; dvander@1592: }