plugins/basecommands/map.sp
branchrefac-jit
changeset 2168 c24a6fa957db
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/basecommands/map.sp	Sun Jul 06 04:49:55 2008 +0000
     1.3 @@ -0,0 +1,150 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod Basecommands Plugin
     1.8 + * Provides map functionality
     1.9 + *
    1.10 + * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
    1.11 + * =============================================================================
    1.12 + *
    1.13 + * This program is free software; you can redistribute it and/or modify it under
    1.14 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.15 + * Free Software Foundation.
    1.16 + * 
    1.17 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.18 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.19 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.20 + * details.
    1.21 + *
    1.22 + * You should have received a copy of the GNU General Public License along with
    1.23 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.24 + *
    1.25 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.26 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.27 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.28 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.29 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.30 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.31 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.32 + * or <http://www.sourcemod.net/license.php>.
    1.33 + *
    1.34 + * Version: $Id$
    1.35 + */
    1.36 + 
    1.37 +public MenuHandler_ChangeMap(Handle:menu, MenuAction:action, param1, param2)
    1.38 +{
    1.39 +	if (action == MenuAction_Cancel)
    1.40 +	{
    1.41 +		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
    1.42 +		{
    1.43 +			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
    1.44 +		}
    1.45 +	}
    1.46 +	else if (action == MenuAction_Select)
    1.47 +	{
    1.48 +		decl String:map[64];
    1.49 +		
    1.50 +		GetMenuItem(menu, param2, map, sizeof(map));
    1.51 +	
    1.52 +		ShowActivity2(param1, "[SM] ", "%t", "Changing map", map);
    1.53 +
    1.54 +		LogAction(param1, -1, "\"%L\" changed map to \"%s\"", param1, map);
    1.55 +
    1.56 +		new Handle:dp;
    1.57 +		CreateDataTimer(3.0, Timer_ChangeMap, dp);
    1.58 +		WritePackString(dp, map);
    1.59 +
    1.60 +	}
    1.61 +}
    1.62 +
    1.63 +public AdminMenu_Map(Handle:topmenu, 
    1.64 +							  TopMenuAction:action,
    1.65 +							  TopMenuObject:object_id,
    1.66 +							  param,
    1.67 +							  String:buffer[],
    1.68 +							  maxlength)
    1.69 +{
    1.70 +	if (action == TopMenuAction_DisplayOption)
    1.71 +	{
    1.72 +		Format(buffer, maxlength, "%T", "Choose Map", param);
    1.73 +	}
    1.74 +	else if (action == TopMenuAction_SelectOption)
    1.75 +	{
    1.76 +		DisplayMenu(g_MapList, param, MENU_TIME_FOREVER);
    1.77 +	}
    1.78 +}
    1.79 +
    1.80 +public Action:Command_Map(client, args)
    1.81 +{
    1.82 +	if (args < 1)
    1.83 +	{
    1.84 +		ReplyToCommand(client, "[SM] Usage: sm_map <map>");
    1.85 +		return Plugin_Handled;
    1.86 +	}
    1.87 +
    1.88 +	decl String:map[64];
    1.89 +	GetCmdArg(1, map, sizeof(map));
    1.90 +
    1.91 +	if (!IsMapValid(map))
    1.92 +	{
    1.93 +		ReplyToCommand(client, "[SM] %t", "Map was not found", map);
    1.94 +		return Plugin_Handled;
    1.95 +	}
    1.96 +
    1.97 +	ShowActivity2(client, "[SM] ", "%t", "Changing map", map);
    1.98 +
    1.99 +	LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map);
   1.100 +
   1.101 +	new Handle:dp;
   1.102 +	CreateDataTimer(3.0, Timer_ChangeMap, dp);
   1.103 +	WritePackString(dp, map);
   1.104 +
   1.105 +	return Plugin_Handled;
   1.106 +}
   1.107 +
   1.108 +public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
   1.109 +{
   1.110 +	decl String:map[65];
   1.111 +
   1.112 +	ResetPack(dp);
   1.113 +	ReadPackString(dp, map, sizeof(map));
   1.114 +
   1.115 +	ServerCommand("changelevel \"%s\"", map);
   1.116 +
   1.117 +	return Plugin_Stop;
   1.118 +}
   1.119 +
   1.120 +new Handle:g_map_array = INVALID_HANDLE;
   1.121 +new g_map_serial = -1;
   1.122 +
   1.123 +LoadMapList(Handle:menu)
   1.124 +{
   1.125 +	new Handle:map_array;
   1.126 +	
   1.127 +	if ((map_array = ReadMapList(g_map_array,
   1.128 +			g_map_serial,
   1.129 +			"sm_map menu",
   1.130 +			MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER))
   1.131 +		!= INVALID_HANDLE)
   1.132 +	{
   1.133 +		g_map_array = map_array;
   1.134 +	}
   1.135 +	
   1.136 +	if (g_map_array == INVALID_HANDLE)
   1.137 +	{
   1.138 +		return 0;
   1.139 +	}
   1.140 +	
   1.141 +	RemoveAllMenuItems(menu);
   1.142 +	
   1.143 +	decl String:map_name[64];
   1.144 +	new map_count = GetArraySize(g_map_array);
   1.145 +	
   1.146 +	for (new i = 0; i < map_count; i++)
   1.147 +	{
   1.148 +		GetArrayString(g_map_array, i, map_name, sizeof(map_name));
   1.149 +		AddMenuItem(menu, map_name, map_name);
   1.150 +	}
   1.151 +	
   1.152 +	return map_count;
   1.153 +}