From fea209fa7f5e18e84c0443a2bed47fdf041d72b0 Mon Sep 17 00:00:00 2001 From: xPaw Date: Sun, 27 Jul 2014 15:59:09 +0300 Subject: [PATCH] Replace hardcoded defines in adminhelp with cvars --- configs/amxx.cfg | 10 ++++++++ plugins/adminhelp.sma | 53 ++++++++++++++++++++++++++++++------------- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/configs/amxx.cfg b/configs/amxx.cfg index dd4f920c..5dd44b3f 100755 --- a/configs/amxx.cfg +++ b/configs/amxx.cfg @@ -151,6 +151,16 @@ amx_client_languages 1 // Default value: 1 amx_language_display_msg 1 +// If you set this to 0, clients will not see a message about amx_help when they join the server +// +// Default value: 1 +amx_help_display_msg 1 + +// Amount of commands per amx_help page +// +// Default value: 10 +amx_help_amount_per_page 10 + // Plugin Debug mode // 0 - No debugging (garbage line numbers) // 1 - Plugins with "debug" option in plugins.ini are put into debug mode diff --git a/plugins/adminhelp.sma b/plugins/adminhelp.sma index bcb65074..0223c144 100755 --- a/plugins/adminhelp.sma +++ b/plugins/adminhelp.sma @@ -34,61 +34,78 @@ #include -#define DISPLAY_MSG // Comment to disable message on join -#define HELPAMOUNT 10 // Number of commands per page +new g_cvarDisplayClientMessage; +new g_cvarHelpAmount; public plugin_init() { register_plugin("Admin Help", AMXX_VERSION_STR, "AMXX Dev Team") register_dictionary("adminhelp.txt") register_concmd("amx_help", "cmdHelp", 0, " [nr of cmds (only for server)] - displays this help") + + g_cvarDisplayClientMessage = register_cvar("amx_help_display_msg", "1") + g_cvarHelpAmount = register_cvar("amx_help_amount_per_page", "10") } -#if defined DISPLAY_MSG public client_putinserver(id) { - if (is_user_bot(id)) - return - - set_task(15.0, "dispInfo", id) + if (get_pcvar_num(g_cvarDisplayClientMessage) && !is_user_bot(id)) + { + set_task(15.0, "dispInfo", id) + } } public client_disconnect(id) { remove_task(id) } -#endif public cmdHelp(id, level, cid) { new arg1[8], flags = get_user_flags(id) new start = read_argv(1, arg1, charsmax(arg1)) ? str_to_num(arg1) : 1 - new lHelpAmount = HELPAMOUNT - + new lHelpAmount = get_pcvar_num(g_cvarHelpAmount) + // HACK: ADMIN_ADMIN is never set as a user's actual flags, so those types of commands never show if (flags > 0 && !(flags & ADMIN_USER)) { flags |= ADMIN_ADMIN; } - + if (id == 0 && read_argc() == 3) - lHelpAmount = read_argv(2, arg1, charsmax(arg1)) ? str_to_num(arg1) : HELPAMOUNT + { + if (read_argv(2, arg1, charsmax(arg1))) + { + lHelpAmount = str_to_num(arg1); + } + } + + if (lHelpAmount <= 0) + { + lHelpAmount = 10 + } if (--start < 0) + { start = 0 + } new clcmdsnum = get_concmdsnum(flags, id) if (start >= clcmdsnum) + { start = clcmdsnum - 1 + } console_print(id, "^n----- %L -----", id, "HELP_COMS") new info[128], cmd[32], eflags - new end = start + lHelpAmount // HELPAMOUNT + new end = start + lHelpAmount if (end > clcmdsnum) + { end = clcmdsnum + } for (new i = start; i < end; i++) { @@ -99,14 +116,17 @@ public cmdHelp(id, level, cid) console_print(id, "----- %L -----", id, "HELP_ENTRIES", start + 1, end, clcmdsnum) if (end < clcmdsnum) + { console_print(id, "----- %L -----", id, "HELP_USE_MORE", end + 1) + } else + { console_print(id, "----- %L -----", id, "HELP_USE_BEGIN") + } return PLUGIN_HANDLED } -#if defined DISPLAY_MSG public dispInfo(id) { client_print(id, print_chat, "%L", id, "TYPE_HELP") @@ -131,9 +151,10 @@ public dispInfo(id) if (timeleft > 0) { client_print(id, print_chat, "%L", id, "TIME_INFO_1", timeleft / 60, timeleft % 60, nextmap) - } else if (amx_nextmap) { + } + else if (amx_nextmap) + { client_print(id, print_chat, "%L", id, "TIME_INFO_2", nextmap) } } } -#endif