plugins/basecommands/map.sp
author Scott Ehlert <ds@alliedmods.net>
Mon Nov 24 09:41:46 2008 -0600 (2008-11-24)
changeset 2424 d95d696a82e5
parent 2289 44045ead61cd
child 3887 3e8a8d9903ce
permissions -rw-r--r--
Added /MP back to core and sdktools MSVC project files.
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);
pred@1536
    56
pred@1536
    57
	}
pred@1536
    58
}
pred@1536
    59
pred@1536
    60
public AdminMenu_Map(Handle:topmenu, 
pred@1536
    61
							  TopMenuAction:action,
pred@1536
    62
							  TopMenuObject:object_id,
pred@1536
    63
							  param,
pred@1536
    64
							  String:buffer[],
pred@1536
    65
							  maxlength)
pred@1536
    66
{
pred@1536
    67
	if (action == TopMenuAction_DisplayOption)
pred@1536
    68
	{
pred@1536
    69
		Format(buffer, maxlength, "%T", "Choose Map", param);
pred@1536
    70
	}
pred@1536
    71
	else if (action == TopMenuAction_SelectOption)
pred@1536
    72
	{
pred@1536
    73
		DisplayMenu(g_MapList, param, MENU_TIME_FOREVER);
pred@1536
    74
	}
pred@1536
    75
}
pred@1536
    76
pred@1536
    77
public Action:Command_Map(client, args)
pred@1536
    78
{
pred@1536
    79
	if (args < 1)
pred@1536
    80
	{
pred@1536
    81
		ReplyToCommand(client, "[SM] Usage: sm_map <map>");
pred@1536
    82
		return Plugin_Handled;
pred@1536
    83
	}
pred@1536
    84
pred@1536
    85
	decl String:map[64];
pred@1536
    86
	GetCmdArg(1, map, sizeof(map));
pred@1536
    87
pred@1536
    88
	if (!IsMapValid(map))
pred@1536
    89
	{
pred@1536
    90
		ReplyToCommand(client, "[SM] %t", "Map was not found", map);
pred@1536
    91
		return Plugin_Handled;
pred@1536
    92
	}
pred@1536
    93
dvander@1623
    94
	ShowActivity2(client, "[SM] ", "%t", "Changing map", map);
pred@1536
    95
pred@1536
    96
	LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map);
pred@1536
    97
pred@1536
    98
	new Handle:dp;
pred@1536
    99
	CreateDataTimer(3.0, Timer_ChangeMap, dp);
pred@1536
   100
	WritePackString(dp, map);
pred@1536
   101
pred@1536
   102
	return Plugin_Handled;
pred@1536
   103
}
pred@1536
   104
pred@1536
   105
public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
pred@1536
   106
{
pred@1536
   107
	decl String:map[65];
pred@1536
   108
pred@1536
   109
	ResetPack(dp);
pred@1536
   110
	ReadPackString(dp, map, sizeof(map));
pred@1536
   111
pred@2203
   112
	ForceChangeLevel(map, "sm_map Command");
pred@1536
   113
pred@1536
   114
	return Plugin_Stop;
pred@1536
   115
}
pred@1536
   116
dvander@1738
   117
new Handle:g_map_array = INVALID_HANDLE;
dvander@1738
   118
new g_map_serial = -1;
dvander@1738
   119
ferret99gt@1606
   120
LoadMapList(Handle:menu)
pred@1536
   121
{
dvander@1738
   122
	new Handle:map_array;
pred@1536
   123
	
dvander@1738
   124
	if ((map_array = ReadMapList(g_map_array,
dvander@1738
   125
			g_map_serial,
pred@1740
   126
			"sm_map menu",
dvander@1738
   127
			MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER))
dvander@1738
   128
		!= INVALID_HANDLE)
pred@1536
   129
	{
dvander@1738
   130
		g_map_array = map_array;
pred@1536
   131
	}
pred@1536
   132
	
dvander@1738
   133
	if (g_map_array == INVALID_HANDLE)
pred@1536
   134
	{
pred@1580
   135
		return 0;
pred@1580
   136
	}
pred@1580
   137
	
dvander@1738
   138
	RemoveAllMenuItems(menu);
pred@1580
   139
	
dvander@1738
   140
	decl String:map_name[64];
dvander@1738
   141
	new map_count = GetArraySize(g_map_array);
dvander@1738
   142
	
dvander@1738
   143
	for (new i = 0; i < map_count; i++)
pred@1580
   144
	{
dvander@1738
   145
		GetArrayString(g_map_array, i, map_name, sizeof(map_name));
dvander@1738
   146
		AddMenuItem(menu, map_name, map_name);
dvander@1738
   147
	}
dvander@1738
   148
	
dvander@1738
   149
	return map_count;
dvander@1592
   150
}