2014-08-04 12:12:15 +00:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
//
|
|
|
|
// Admin Help Plugin
|
|
|
|
//
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2004-03-05 19:35:38 +00:00
|
|
|
#include <amxmodx>
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
const MaxMapLength = 32;
|
|
|
|
const MaxDefaultEntries = 10;
|
|
|
|
const MaxCommandLength = 32;
|
|
|
|
const MaxCommandInfoLength = 128;
|
|
|
|
const DefaultMsgTime = 15;
|
|
|
|
|
|
|
|
new const HelpCommand[] = "amx_help";
|
|
|
|
new const SearchCommand[] = "amx_searchcmd";
|
|
|
|
|
|
|
|
new CvarDisplayClientMessage;
|
|
|
|
new CvarDisplayMessageTime;
|
|
|
|
new CvarHelpAmount;
|
|
|
|
|
|
|
|
new CvarNextmap[MaxMapLength];
|
|
|
|
new Float:CvarTimeLimit;
|
|
|
|
|
|
|
|
new bool:DisplayClientMessage[MAX_PLAYERS + 1 char];
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2005-09-12 21:06:24 +00:00
|
|
|
public plugin_init()
|
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
register_plugin("Admin Help", AMXX_VERSION_STR, "AMXX Dev Team");
|
|
|
|
register_dictionary("adminhelp.txt");
|
2014-07-27 12:59:09 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
register_concmd(HelpCommand , "@ConsoleCommand_Help" , ADMIN_ALL, "HELP_CMD_INFO" , .info_ml = true);
|
|
|
|
register_concmd(SearchCommand, "@ConsoleCommand_Search", ADMIN_ALL, "SEARCH_CMD_INFO", .info_ml = true);
|
|
|
|
|
|
|
|
bind_pcvar_num(create_cvar("amx_help_display_msg" , "1" , .has_min = true, .min_val = 0.0, .has_max = true, .max_val = 1.0), CvarDisplayClientMessage);
|
|
|
|
bind_pcvar_num(create_cvar("amx_help_display_msg_time", "15", .has_min = true, .min_val = 0.0), CvarDisplayMessageTime);
|
|
|
|
bind_pcvar_num(create_cvar("amx_help_amount_per_page" , "10", .has_min = true, .min_val = 0.0), CvarHelpAmount);
|
|
|
|
}
|
|
|
|
|
|
|
|
public OnConfigsExecuted()
|
|
|
|
{
|
|
|
|
new const pointer = get_cvar_pointer("amx_nextmap");
|
|
|
|
|
|
|
|
if (pointer)
|
|
|
|
{
|
|
|
|
bind_pcvar_string(pointer, CvarNextmap, charsmax(CvarNextmap));
|
|
|
|
}
|
|
|
|
|
|
|
|
bind_pcvar_float(get_cvar_pointer("mp_timelimit"), CvarTimeLimit);
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
2005-09-12 21:06:24 +00:00
|
|
|
public client_putinserver(id)
|
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
if (CvarDisplayClientMessage > 0 && !is_user_bot(id))
|
2014-07-27 12:59:09 +00:00
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
DisplayClientMessage{id} = true;
|
|
|
|
|
|
|
|
new Float:messageTime = float(CvarDisplayMessageTime <= 0 ? DefaultMsgTime : CvarDisplayMessageTime);
|
|
|
|
set_task(messageTime, "@Task_DisplayMessage", id);
|
2014-07-27 12:59:09 +00:00
|
|
|
}
|
2004-08-13 11:20:12 +00:00
|
|
|
}
|
2005-02-21 00:31:52 +00:00
|
|
|
|
2015-07-16 22:26:30 +00:00
|
|
|
public client_disconnected(id)
|
2005-09-12 21:06:24 +00:00
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
if (DisplayClientMessage{id})
|
|
|
|
{
|
|
|
|
DisplayClientMessage{id} = false;
|
|
|
|
remove_task(id);
|
|
|
|
}
|
2005-02-21 00:31:52 +00:00
|
|
|
}
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
@ConsoleCommand_Search(id, level, cid)
|
2005-09-12 21:06:24 +00:00
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
new entry[MaxCommandLength];
|
|
|
|
read_argv(1, entry, charsmax(entry));
|
2014-07-27 12:59:09 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
return ProcessHelp(id, .start_argindex = 2, .do_search = true, .main_command = SearchCommand, .search = entry);
|
|
|
|
}
|
2014-07-27 12:59:09 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
@ConsoleCommand_Help(id, level, cid)
|
|
|
|
{
|
|
|
|
return ProcessHelp(id, .start_argindex = 1, .do_search = false, .main_command = HelpCommand);
|
|
|
|
}
|
2014-07-27 12:59:09 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
ProcessHelp(id, start_argindex, bool:do_search, const main_command[], const search[] = "")
|
|
|
|
{
|
|
|
|
new user_flags = get_user_flags(id);
|
2004-05-16 11:31:41 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
// HACK: ADMIN_ADMIN is never set as a user's actual flags, so those types of commands never show
|
|
|
|
if (user_flags > 0 && !(user_flags & ADMIN_USER))
|
2014-07-27 12:59:09 +00:00
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
user_flags |= ADMIN_ADMIN;
|
2014-07-27 12:59:09 +00:00
|
|
|
}
|
2004-05-16 11:31:41 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
new clcmdsnum = get_concmdsnum(user_flags, id);
|
2004-05-16 11:31:41 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
if (CvarHelpAmount <= 0)
|
2014-07-27 12:59:09 +00:00
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
CvarHelpAmount = MaxDefaultEntries;
|
2014-07-27 12:59:09 +00:00
|
|
|
}
|
2004-05-16 11:31:41 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
new start = clamp(read_argv_int(start_argindex), .min = 1, .max = clcmdsnum) - 1; // Zero-based list;
|
|
|
|
new amount = !id ? read_argv_int(start_argindex + 1) : CvarHelpAmount;
|
|
|
|
new end = min(start + (amount > 0 ? amount : CvarHelpAmount), clcmdsnum);
|
2004-05-16 11:31:41 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
console_print(id, "^n----- %l -----", "HELP_COMS");
|
|
|
|
|
|
|
|
new info[MaxCommandInfoLength];
|
|
|
|
new command[MaxCommandLength];
|
|
|
|
new command_flags;
|
|
|
|
new bool:is_info_ml;
|
|
|
|
new entries_found;
|
|
|
|
new total_entries;
|
|
|
|
new index;
|
2004-05-16 11:31:41 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
if (do_search)
|
2005-09-12 21:06:24 +00:00
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
for (index = 0; index < clcmdsnum; ++index)
|
|
|
|
{
|
|
|
|
get_concmd(index, command, charsmax(command), command_flags, info, charsmax(info), user_flags, id, is_info_ml);
|
|
|
|
|
|
|
|
if (containi(command, search) != -1 && ++entries_found > start && (total_entries = entries_found) <= end)
|
|
|
|
{
|
|
|
|
if (is_info_ml)
|
|
|
|
{
|
|
|
|
LookupLangKey(info, charsmax(info), info, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
console_print(id, "%3d: %s %s", entries_found, command, info);
|
|
|
|
}
|
|
|
|
}
|
2016-02-02 22:07:53 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
if (!entries_found || entries_found > total_entries)
|
2016-02-02 22:07:53 +00:00
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
console_print(id, "%l", "NO_MATCHING_RESULTS");
|
|
|
|
return PLUGIN_HANDLED;
|
2016-02-02 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
index = entries_found;
|
|
|
|
clcmdsnum = total_entries;
|
|
|
|
end = min(end, clcmdsnum);
|
2004-05-16 11:31:41 +00:00
|
|
|
}
|
2017-08-01 20:56:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for (index = start; index < end; ++index)
|
|
|
|
{
|
|
|
|
get_concmd(index, command, charsmax(command), command_flags, info, charsmax(info), user_flags, id, is_info_ml);
|
|
|
|
|
|
|
|
if (is_info_ml)
|
|
|
|
{
|
|
|
|
LookupLangKey(info, charsmax(info), info, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
console_print(id, "%3d: %s %s", index + 1, command, info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console_print(id, "----- %l -----", "HELP_ENTRIES", start + 1, end, clcmdsnum);
|
|
|
|
|
|
|
|
formatex(command, charsmax(command), "%s%c%s", main_command, do_search ? " " : "", search);
|
2004-05-16 11:31:41 +00:00
|
|
|
|
|
|
|
if (end < clcmdsnum)
|
2014-07-27 12:59:09 +00:00
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
console_print(id, "----- %l -----", "HELP_USE_MORE", command, end + 1);
|
2014-07-27 12:59:09 +00:00
|
|
|
}
|
2017-08-01 20:56:21 +00:00
|
|
|
else if (start || index != clcmdsnum)
|
2014-07-27 12:59:09 +00:00
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
console_print(id, "----- %l -----", "HELP_USE_BEGIN", command);
|
2014-07-27 12:59:09 +00:00
|
|
|
}
|
2004-05-16 11:31:41 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
return PLUGIN_HANDLED;
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
@Task_DisplayMessage(id)
|
2005-09-12 21:06:24 +00:00
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
client_print(id, print_chat, "%l", "TYPE_HELP", HelpCommand, SearchCommand);
|
2013-08-05 15:44:15 +00:00
|
|
|
|
2017-08-01 20:56:21 +00:00
|
|
|
if (CvarTimeLimit > 0.0)
|
2013-08-05 15:44:15 +00:00
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
new timeleft = get_timeleft();
|
2013-08-05 15:44:15 +00:00
|
|
|
|
2005-09-12 21:06:24 +00:00
|
|
|
if (timeleft > 0)
|
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
client_print(id, print_chat, "%l", "TIME_INFO_1", timeleft / 60, timeleft % 60, CvarNextmap);
|
2014-07-27 12:59:09 +00:00
|
|
|
}
|
2017-08-01 20:56:21 +00:00
|
|
|
else if (CvarNextmap[0] != EOS)
|
2014-07-27 12:59:09 +00:00
|
|
|
{
|
2017-08-01 20:56:21 +00:00
|
|
|
client_print(id, print_chat, "%l", "TIME_INFO_2", CvarNextmap);
|
2005-09-12 21:06:24 +00:00
|
|
|
}
|
|
|
|
}
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|