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