plugins/basecommands/map.sp
author Peace-Maker <januk@freenet.de>
Sat May 10 05:42:33 2014 -0700 (2014-05-10)
changeset 4354 7011587e0021
parent 3887 3e8a8d9903ce
permissions -rw-r--r--
Remove LogMessageEx definition from logging.inc (bug 5897, r=kyles).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basecommands Plugin
     5  * Provides map functionality
     6  *
     7  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     8  * =============================================================================
     9  *
    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.
    13  * 
    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
    17  * details.
    18  *
    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/>.
    21  *
    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>.
    30  *
    31  * Version: $Id$
    32  */
    33  
    34 public MenuHandler_ChangeMap(Handle:menu, MenuAction:action, param1, param2)
    35 {
    36 	if (action == MenuAction_Cancel)
    37 	{
    38 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
    39 		{
    40 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
    41 		}
    42 	}
    43 	else if (action == MenuAction_Select)
    44 	{
    45 		decl String:map[64];
    46 		
    47 		GetMenuItem(menu, param2, map, sizeof(map));
    48 	
    49 		ShowActivity2(param1, "[SM] ", "%t", "Changing map", map);
    50 
    51 		LogAction(param1, -1, "\"%L\" changed map to \"%s\"", param1, map);
    52 
    53 		new Handle:dp;
    54 		CreateDataTimer(3.0, Timer_ChangeMap, dp);
    55 		WritePackString(dp, map);
    56 	}
    57 	else if (action == MenuAction_Display)
    58 	{
    59 		decl String:title[128];
    60 		Format(title, sizeof(title), "%T", "Please select a map", param1);
    61 		SetPanelTitle(Handle:param2, title);
    62 	}
    63 }
    64 
    65 public AdminMenu_Map(Handle:topmenu, 
    66 							  TopMenuAction:action,
    67 							  TopMenuObject:object_id,
    68 							  param,
    69 							  String:buffer[],
    70 							  maxlength)
    71 {
    72 	if (action == TopMenuAction_DisplayOption)
    73 	{
    74 		Format(buffer, maxlength, "%T", "Choose Map", param);
    75 	}
    76 	else if (action == TopMenuAction_SelectOption)
    77 	{
    78 		DisplayMenu(g_MapList, param, MENU_TIME_FOREVER);
    79 	}
    80 }
    81 
    82 public Action:Command_Map(client, args)
    83 {
    84 	if (args < 1)
    85 	{
    86 		ReplyToCommand(client, "[SM] Usage: sm_map <map>");
    87 		return Plugin_Handled;
    88 	}
    89 
    90 	decl String:map[64];
    91 	GetCmdArg(1, map, sizeof(map));
    92 
    93 	if (!IsMapValid(map))
    94 	{
    95 		ReplyToCommand(client, "[SM] %t", "Map was not found", map);
    96 		return Plugin_Handled;
    97 	}
    98 
    99 	ShowActivity2(client, "[SM] ", "%t", "Changing map", map);
   100 
   101 	LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map);
   102 
   103 	new Handle:dp;
   104 	CreateDataTimer(3.0, Timer_ChangeMap, dp);
   105 	WritePackString(dp, map);
   106 
   107 	return Plugin_Handled;
   108 }
   109 
   110 public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
   111 {
   112 	decl String:map[65];
   113 
   114 	ResetPack(dp);
   115 	ReadPackString(dp, map, sizeof(map));
   116 
   117 	ForceChangeLevel(map, "sm_map Command");
   118 
   119 	return Plugin_Stop;
   120 }
   121 
   122 new Handle:g_map_array = INVALID_HANDLE;
   123 new g_map_serial = -1;
   124 
   125 LoadMapList(Handle:menu)
   126 {
   127 	new Handle:map_array;
   128 	
   129 	if ((map_array = ReadMapList(g_map_array,
   130 			g_map_serial,
   131 			"sm_map menu",
   132 			MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER))
   133 		!= INVALID_HANDLE)
   134 	{
   135 		g_map_array = map_array;
   136 	}
   137 	
   138 	if (g_map_array == INVALID_HANDLE)
   139 	{
   140 		return 0;
   141 	}
   142 	
   143 	RemoveAllMenuItems(menu);
   144 	
   145 	decl String:map_name[64];
   146 	new map_count = GetArraySize(g_map_array);
   147 	
   148 	for (new i = 0; i < map_count; i++)
   149 	{
   150 		GetArrayString(g_map_array, i, map_name, sizeof(map_name));
   151 		AddMenuItem(menu, map_name, map_name);
   152 	}
   153 	
   154 	return map_count;
   155 }