2008-03-30 09:00:22 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
|
|
|
* SourceMod Basecommands Plugin
|
|
|
|
* Provides map functionality
|
|
|
|
*
|
|
|
|
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
2008-04-11 19:16:36 +02:00
|
|
|
* Version: $Id$
|
2008-03-30 09:00:22 +02:00
|
|
|
*/
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
public int MenuHandler_ChangeMap(Menu menu, MenuAction action, int param1, int param2)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (action == MenuAction_Cancel)
|
|
|
|
{
|
2014-10-29 03:03:38 +01:00
|
|
|
if (param2 == MenuCancel_ExitBack && hTopMenu)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2014-10-29 03:03:38 +01:00
|
|
|
hTopMenu.Display(param1, TopMenuPosition_LastCategory);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (action == MenuAction_Select)
|
|
|
|
{
|
2017-03-13 23:52:37 +01:00
|
|
|
char map[PLATFORM_MAX_PATH];
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.GetItem(param2, map, sizeof(map));
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
ShowActivity2(param1, "[SM] ", "%t", "Changing map", map);
|
|
|
|
|
|
|
|
LogAction(param1, -1, "\"%L\" changed map to \"%s\"", param1, map);
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
DataPack dp;
|
2008-03-30 09:00:22 +02:00
|
|
|
CreateDataTimer(3.0, Timer_ChangeMap, dp);
|
2016-05-11 16:44:58 +02:00
|
|
|
dp.WriteString(map);
|
2013-04-08 14:00:13 +02:00
|
|
|
}
|
|
|
|
else if (action == MenuAction_Display)
|
|
|
|
{
|
2016-05-11 16:44:58 +02:00
|
|
|
char title[128];
|
2013-04-08 14:00:13 +02:00
|
|
|
Format(title, sizeof(title), "%T", "Please select a map", param1);
|
2016-05-11 16:44:58 +02:00
|
|
|
|
|
|
|
Panel panel = view_as<Panel>(param2);
|
|
|
|
panel.SetTitle(title);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
2021-08-04 16:46:15 +02:00
|
|
|
|
|
|
|
return 0;
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
public void AdminMenu_Map(TopMenu topmenu,
|
|
|
|
TopMenuAction action,
|
|
|
|
TopMenuObject object_id,
|
|
|
|
int param,
|
|
|
|
char[] buffer,
|
|
|
|
int maxlength)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (action == TopMenuAction_DisplayOption)
|
|
|
|
{
|
|
|
|
Format(buffer, maxlength, "%T", "Choose Map", param);
|
|
|
|
}
|
|
|
|
else if (action == TopMenuAction_SelectOption)
|
|
|
|
{
|
2014-11-16 01:30:45 +01:00
|
|
|
g_MapList.Display(param, MENU_TIME_FOREVER);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
public Action Command_Map(int client, int args)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (args < 1)
|
|
|
|
{
|
Update to sm_ban, sm_kick, & sm_map in chat with no args to display menu (#838)
This change makes it so /kick, /ban, and /map open the already created methods for displaying their menus when there are no args.
The reason for the feature is to take advantage of menus that already exist and to make the commands easier to use.
The client == 0 check prevents them from opening if it was ran via rcon, sm_rcon, or server command. Client auth is also checked because its a registered admin command.
Usage params will display if client == 0 and args < min
For example, a moderator wants to change a map, instead of running through the admin menu, they can instead type just /map to display available maps and choose one.
If a mod wants to quickly ban or kick someone without having to either run through the admin menu or type it out, they could then type the corresponding commands with no args to open the menus.
2018-09-04 01:41:22 +02:00
|
|
|
if ((GetCmdReplySource() == SM_REPLY_TO_CHAT) && (client != 0))
|
|
|
|
{
|
|
|
|
g_MapList.SetTitle("%T", "Choose Map", client);
|
|
|
|
g_MapList.Display(client, MENU_TIME_FOREVER);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ReplyToCommand(client, "[SM] Usage: sm_map <map>");
|
|
|
|
}
|
2008-03-30 09:00:22 +02:00
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2017-03-13 23:52:37 +01:00
|
|
|
char map[PLATFORM_MAX_PATH];
|
|
|
|
char displayName[PLATFORM_MAX_PATH];
|
2008-03-30 09:00:22 +02:00
|
|
|
GetCmdArg(1, map, sizeof(map));
|
|
|
|
|
2017-03-13 23:52:37 +01:00
|
|
|
if (FindMap(map, displayName, sizeof(displayName)) == FindMap_NotFound)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
ReplyToCommand(client, "[SM] %t", "Map was not found", map);
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2017-03-13 23:52:37 +01:00
|
|
|
GetMapDisplayName(displayName, displayName, sizeof(displayName));
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2017-03-13 23:52:37 +01:00
|
|
|
ShowActivity2(client, "[SM] ", "%t", "Changing map", displayName);
|
2008-03-30 09:00:22 +02:00
|
|
|
LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map);
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
DataPack dp;
|
2008-03-30 09:00:22 +02:00
|
|
|
CreateDataTimer(3.0, Timer_ChangeMap, dp);
|
2016-05-11 16:44:58 +02:00
|
|
|
dp.WriteString(map);
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
public Action Timer_ChangeMap(Handle timer, DataPack dp)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2017-03-13 23:52:37 +01:00
|
|
|
char map[PLATFORM_MAX_PATH];
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
dp.Reset();
|
|
|
|
dp.ReadString(map, sizeof(map));
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2008-07-13 07:13:37 +02:00
|
|
|
ForceChangeLevel(map, "sm_map Command");
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
return Plugin_Stop;
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
Handle g_map_array = null;
|
|
|
|
int g_map_serial = -1;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
int LoadMapList(Menu menu)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2016-05-11 16:44:58 +02:00
|
|
|
Handle map_array;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
if ((map_array = ReadMapList(g_map_array,
|
|
|
|
g_map_serial,
|
|
|
|
"sm_map menu",
|
2018-08-19 13:41:53 +02:00
|
|
|
MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER))
|
2014-11-16 01:30:45 +01:00
|
|
|
!= null)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
g_map_array = map_array;
|
|
|
|
}
|
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
if (g_map_array == null)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
menu.RemoveAllItems();
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2017-03-13 23:52:37 +01:00
|
|
|
char map_name[PLATFORM_MAX_PATH];
|
2014-11-16 01:30:45 +01:00
|
|
|
int map_count = GetArraySize(g_map_array);
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
for (int i = 0; i < map_count; i++)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2019-10-07 20:15:36 +02:00
|
|
|
char displayName[PLATFORM_MAX_PATH];
|
2008-03-30 09:00:22 +02:00
|
|
|
GetArrayString(g_map_array, i, map_name, sizeof(map_name));
|
2019-10-07 20:15:36 +02:00
|
|
|
GetMapDisplayName(map_name, displayName, sizeof(displayName));
|
|
|
|
menu.AddItem(map_name, displayName);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return map_count;
|
|
|
|
}
|