plugins/basecommands/map.sp
author Nicholas Hastings <skamonkey@gmail.com>
Mon Apr 08 08:00:13 2013 -0400 (2013-04-08)
changeset 3887 3e8a8d9903ce
parent 2289 44045ead61cd
permissions -rw-r--r--
Allow localizaton of more base plugin strings (bug 5120, r=asherkin).
ferret99gt@1789
     1
/**
ferret99gt@1789
     2
 * vim: set ts=4 :
ferret99gt@1789
     3
 * =============================================================================
ferret99gt@1789
     4
 * SourceMod Basecommands Plugin
ferret99gt@1789
     5
 * Provides map functionality
ferret99gt@1789
     6
 *
ds@1947
     7
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ferret99gt@1789
     8
 * =============================================================================
ferret99gt@1789
     9
 *
ferret99gt@1789
    10
 * This program is free software; you can redistribute it and/or modify it under
ferret99gt@1789
    11
 * the terms of the GNU General Public License, version 3.0, as published by the
ferret99gt@1789
    12
 * Free Software Foundation.
ferret99gt@1789
    13
 * 
ferret99gt@1789
    14
 * This program is distributed in the hope that it will be useful, but WITHOUT
ferret99gt@1789
    15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ferret99gt@1789
    16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ferret99gt@1789
    17
 * details.
ferret99gt@1789
    18
 *
ferret99gt@1789
    19
 * You should have received a copy of the GNU General Public License along with
ferret99gt@1789
    20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ferret99gt@1789
    21
 *
ferret99gt@1789
    22
 * As a special exception, AlliedModders LLC gives you permission to link the
ferret99gt@1789
    23
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ferret99gt@1789
    24
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ferret99gt@1789
    25
 * by the Valve Corporation.  You must obey the GNU General Public License in
ferret99gt@1789
    26
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ferret99gt@1789
    27
 * this exception to all derivative works.  AlliedModders LLC defines further
ferret99gt@1789
    28
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ferret99gt@1789
    29
 * or <http://www.sourcemod.net/license.php>.
ferret99gt@1789
    30
 *
ds@1990
    31
 * Version: $Id$
ferret99gt@1789
    32
 */
ferret99gt@1789
    33
 
pred@1536
    34
public MenuHandler_ChangeMap(Handle:menu, MenuAction:action, param1, param2)
pred@1536
    35
{
pred@1536
    36
	if (action == MenuAction_Cancel)
pred@1536
    37
	{
pred@1536
    38
		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
pred@1536
    39
		{
pred@1536
    40
			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
pred@1536
    41
		}
pred@1536
    42
	}
pred@1536
    43
	else if (action == MenuAction_Select)
pred@1536
    44
	{
pred@1536
    45
		decl String:map[64];
pred@1536
    46
		
pred@1536
    47
		GetMenuItem(menu, param2, map, sizeof(map));
pred@1536
    48
	
dvander@1623
    49
		ShowActivity2(param1, "[SM] ", "%t", "Changing map", map);
pred@1536
    50
pred@1536
    51
		LogAction(param1, -1, "\"%L\" changed map to \"%s\"", param1, map);
pred@1536
    52
pred@1536
    53
		new Handle:dp;
pred@1536
    54
		CreateDataTimer(3.0, Timer_ChangeMap, dp);
pred@1536
    55
		WritePackString(dp, map);
skamonkey@3887
    56
	}
skamonkey@3887
    57
	else if (action == MenuAction_Display)
skamonkey@3887
    58
	{
skamonkey@3887
    59
		decl String:title[128];
skamonkey@3887
    60
		Format(title, sizeof(title), "%T", "Please select a map", param1);
skamonkey@3887
    61
		SetPanelTitle(Handle:param2, title);
pred@1536
    62
	}
pred@1536
    63
}
pred@1536
    64
pred@1536
    65
public AdminMenu_Map(Handle:topmenu, 
pred@1536
    66
							  TopMenuAction:action,
pred@1536
    67
							  TopMenuObject:object_id,
pred@1536
    68
							  param,
pred@1536
    69
							  String:buffer[],
pred@1536
    70
							  maxlength)
pred@1536
    71
{
pred@1536
    72
	if (action == TopMenuAction_DisplayOption)
pred@1536
    73
	{
pred@1536
    74
		Format(buffer, maxlength, "%T", "Choose Map", param);
pred@1536
    75
	}
pred@1536
    76
	else if (action == TopMenuAction_SelectOption)
pred@1536
    77
	{
pred@1536
    78
		DisplayMenu(g_MapList, param, MENU_TIME_FOREVER);
pred@1536
    79
	}
pred@1536
    80
}
pred@1536
    81
pred@1536
    82
public Action:Command_Map(client, args)
pred@1536
    83
{
pred@1536
    84
	if (args < 1)
pred@1536
    85
	{
pred@1536
    86
		ReplyToCommand(client, "[SM] Usage: sm_map <map>");
pred@1536
    87
		return Plugin_Handled;
pred@1536
    88
	}
pred@1536
    89
pred@1536
    90
	decl String:map[64];
pred@1536
    91
	GetCmdArg(1, map, sizeof(map));
pred@1536
    92
pred@1536
    93
	if (!IsMapValid(map))
pred@1536
    94
	{
pred@1536
    95
		ReplyToCommand(client, "[SM] %t", "Map was not found", map);
pred@1536
    96
		return Plugin_Handled;
pred@1536
    97
	}
pred@1536
    98
dvander@1623
    99
	ShowActivity2(client, "[SM] ", "%t", "Changing map", map);
pred@1536
   100
pred@1536
   101
	LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map);
pred@1536
   102
pred@1536
   103
	new Handle:dp;
pred@1536
   104
	CreateDataTimer(3.0, Timer_ChangeMap, dp);
pred@1536
   105
	WritePackString(dp, map);
pred@1536
   106
pred@1536
   107
	return Plugin_Handled;
pred@1536
   108
}
pred@1536
   109
pred@1536
   110
public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
pred@1536
   111
{
pred@1536
   112
	decl String:map[65];
pred@1536
   113
pred@1536
   114
	ResetPack(dp);
pred@1536
   115
	ReadPackString(dp, map, sizeof(map));
pred@1536
   116
pred@2203
   117
	ForceChangeLevel(map, "sm_map Command");
pred@1536
   118
pred@1536
   119
	return Plugin_Stop;
pred@1536
   120
}
pred@1536
   121
dvander@1738
   122
new Handle:g_map_array = INVALID_HANDLE;
dvander@1738
   123
new g_map_serial = -1;
dvander@1738
   124
ferret99gt@1606
   125
LoadMapList(Handle:menu)
pred@1536
   126
{
dvander@1738
   127
	new Handle:map_array;
pred@1536
   128
	
dvander@1738
   129
	if ((map_array = ReadMapList(g_map_array,
dvander@1738
   130
			g_map_serial,
pred@1740
   131
			"sm_map menu",
dvander@1738
   132
			MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER))
dvander@1738
   133
		!= INVALID_HANDLE)
pred@1536
   134
	{
dvander@1738
   135
		g_map_array = map_array;
pred@1536
   136
	}
pred@1536
   137
	
dvander@1738
   138
	if (g_map_array == INVALID_HANDLE)
pred@1536
   139
	{
pred@1580
   140
		return 0;
pred@1580
   141
	}
pred@1580
   142
	
dvander@1738
   143
	RemoveAllMenuItems(menu);
pred@1580
   144
	
dvander@1738
   145
	decl String:map_name[64];
dvander@1738
   146
	new map_count = GetArraySize(g_map_array);
dvander@1738
   147
	
dvander@1738
   148
	for (new i = 0; i < map_count; i++)
pred@1580
   149
	{
dvander@1738
   150
		GetArrayString(g_map_array, i, map_name, sizeof(map_name));
dvander@1738
   151
		AddMenuItem(menu, map_name, map_name);
dvander@1738
   152
	}
dvander@1738
   153
	
dvander@1738
   154
	return map_count;
dvander@1592
   155
}