From e343d224ce823d6c0e6fe5de3933caa2e4f7dde1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Bergstr=C3=B6m?= Date: Sat, 15 Jan 2005 09:58:51 +0000 Subject: [PATCH] amx_menu: A new menu also reachable by non-admin clients. Scripters can add their plugin menus as an item in this menu (Wc3 menu, Superhero info, etc...) so that a client don't have to bind/know a million different menu commands. This could become a one-stop-shop for all of the clients menu needs. Let's hope it catches on. :-) For this menufront.sma adds: "amx_addclientmenuitem" where server admins can add menu items from plugins that don't support this yet. amxmisc.inc is also updated to support this. --- plugins/include/amxmisc.inc | 55 +++++-------- plugins/menufront.sma | 156 +++++++++++++++++++++++++++++++----- 2 files changed, 154 insertions(+), 57 deletions(-) diff --git a/plugins/include/amxmisc.inc b/plugins/include/amxmisc.inc index 48854e33..aeaeda17 100755 --- a/plugins/include/amxmisc.inc +++ b/plugins/include/amxmisc.inc @@ -59,11 +59,11 @@ stock cmd_target(id,const arg[],flags = 1) { if (player) { if ( player != find_player("blj",arg) ) { console_print(id,"%L",id,"MORE_CL_MATCHT") - return 0 + return 0 } } else if ( ( player = find_player("c",arg) )==0 && arg[0]=='#' && arg[1] ) - player = find_player("k",str_to_num(arg[1])) + player = find_player("k",str_to_num(arg[1])) if (!player) { console_print(id,"%L",id,"CL_NOT_FOUND") return 0 @@ -79,7 +79,7 @@ stock cmd_target(id,const arg[],flags = 1) { if (flags & 4) { if (!is_user_alive(player)) { new imname[32] - get_user_name(player,imname,31) + get_user_name(player,imname,31) console_print(id,"%L",id,"CANT_PERF_DEAD",imname) return 0 } @@ -87,10 +87,10 @@ stock cmd_target(id,const arg[],flags = 1) { if (flags & 8) { if (is_user_bot(player)) { new imname[32] - get_user_name(player,imname,31) + get_user_name(player,imname,31) console_print(id,"%L",id,"CANT_PERF_BOT",imname) return 0 - } + } } return player } @@ -144,13 +144,23 @@ stock register_menu(title[],keys,function[],outside=0) stock get_customdir(name[],len) return get_localinfo("amxx_configsdir",name,len) -/* Add a menu item to Menus Front-End plugin: +/* Add a menu item to Menus Front-End plugin ("amxmodmenu"): * MENU_TEXT: Text that will be shown for this item in menu * MENU_CMD: Command that should be executed to start menu * MENU_ACCESS: Access required for menu -* MENU_PLUGIN: The exact case-insensitive name of plugin holding the menu command +* MENU_PLUGIN: The exact case-insensitive name of plugin holding the menu command */ stock AddMenuItem(const MENU_TEXT[], const MENU_CMD[], const MENU_ACCESS, const MENU_PLUGIN[]) { + AddMenuItem_call(MENU_TEXT, MENU_CMD, MENU_ACCESS, MENU_PLUGIN, false) +} +/* Just like above, but add menu item to "amx_menu", that should also be accessible by non-admins. +*/ +stock AddClientMenuItem(const MENU_TEXT[], const MENU_CMD[], const MENU_ACCESS, const MENU_PLUGIN[]) { + AddMenuItem_call(MENU_TEXT, MENU_CMD, MENU_ACCESS, MENU_PLUGIN, true) +} + +// Internal function used by above stocks. +stock AddMenuItem_call(const MENU_TEXT[], const MENU_CMD[], const MENU_ACCESS, const MENU_PLUGIN[], const bool:ADD_TO_CLIENT_MENU) { new pluginid = is_plugin_loaded("Menus Front-End") if (pluginid == -1) { log_amx("Can't add menu item ^"%s^" from plugin ^"%s^" to menu set because the Menus Front-End plugin itself is not loaded!", MENU_TEXT, MENU_PLUGIN) @@ -160,7 +170,7 @@ stock AddMenuItem(const MENU_TEXT[], const MENU_CMD[], const MENU_ACCESS, const new filename[64], b[1] get_plugin(pluginid, filename, 63, b, 0, b, 0, b, 0, b, 0) - new status = callfunc_begin("AddMenu", filename) + new status = callfunc_begin(ADD_TO_CLIENT_MENU ? "AddClientMenu" : "AddMenu", filename) new bool:failed = true switch (status) { case 1: failed = false @@ -180,33 +190,4 @@ stock AddMenuItem(const MENU_TEXT[], const MENU_CMD[], const MENU_ACCESS, const callfunc_push_str(MENU_PLUGIN) callfunc_end() -} - -/* Find plugin by an attribute */ -stock find_plugin_byfile(pname[], bool:ignorecase=true) -{ - new num_of_plugins = get_pluginsnum(); - new dummy[1]; - new name[64]; - for (new i = 0; i < num_of_plugins; ++i) - { - get_plugin(i, name, 0, dummy, 63, dummy, 0, dummy, 0, dummy, 0); - if (ignorecase ? equali(name, pname) : equal(name, pname)) - return i; - } - return -1; -} - -stock find_plugin_bydesc(pdesc[], bool:ignorecase=true) -{ - new num_of_plugins = get_pluginsnum(); - new dummy[1]; - new desc[64]; - for (new i = 0; i < num_of_plugins; ++i) - { - get_plugin(i, dummy, 0, desc, 63, dummy, 0, dummy, 0, dummy, 0); - if (ignorecase ? equali(desc, pdesc) : equal(desc, pdesc)) - return i; - } - return -1; } \ No newline at end of file diff --git a/plugins/menufront.sma b/plugins/menufront.sma index a2b80500..1ea601fa 100755 --- a/plugins/menufront.sma +++ b/plugins/menufront.sma @@ -48,8 +48,17 @@ new bool:g_menuBodyPhrase[MAXMENUS] new g_menuCmd[MAXMENUS][STRINGSIZE] new g_menuAccess[MAXMENUS] new g_menuPlugin[MAXMENUS][STRINGSIZE] + new g_coloredMenus +new g_clientMenuPosition[33] +new g_clientMenusNumber = 0 +new g_clientMenuBody[MAXMENUS][STRINGSIZE] +new bool:g_clientMenuBodyPhrase[MAXMENUS] +new g_clientMenuCmd[MAXMENUS][STRINGSIZE] +new g_clientMenuAccess[MAXMENUS] +new g_clientMenuPlugin[MAXMENUS][STRINGSIZE] + // menuBody: Text that will be shown for this item in menu // menuCmd: Command that should be executed to start menu // menuAccess: Access required for menu @@ -85,6 +94,22 @@ public AddMenuLang(const menuBody[], const menuCmd[], const menuAccess, const me //server_print("Menu item %d added to Menus Front-End: ^"%s^" (LANG) from plugin ^"%s^"", g_menusNumber, menuBody, menuPlugin) } +public AddClientMenu(const menuBody[], const menuCmd[], const menuAccess, const menuPlugin[]) { + if (g_clientMenusNumber + 1 == MAXMENUS) { + log_amx("Error: Plugin ^"%s^" tried to add a menu item to Menu Front-End plugin with maximum menu items reached!", menuPlugin) + return + } + + copy(g_clientMenuBody[g_clientMenusNumber], STRINGLENGTH, menuBody) + g_clientMenuBodyPhrase[g_clientMenusNumber] = false + copy(g_clientMenuCmd[g_clientMenusNumber], STRINGLENGTH, menuCmd) + g_clientMenuAccess[g_clientMenusNumber] = menuAccess + copy(g_clientMenuPlugin[g_clientMenusNumber], STRINGLENGTH, menuPlugin) + + g_clientMenusNumber++ + + server_print("Client menu item %d added to Client Menus Front-End: ^"%s^" from plugin ^"%s^"", g_clientMenusNumber, menuBody, menuPlugin) +} AddDefaultMenus() { AddMenuLang("KICK_PLAYER", "amx_kickmenu", ADMIN_KICK, "Players Menu") @@ -106,15 +131,23 @@ AddDefaultMenus() { } public actionMenu(id,key) { - switch (key) { - case 8: displayMenu(id,++g_menuPosition[id]) - case 9: displayMenu(id,--g_menuPosition[id]) - default: client_cmd(id, g_menuCmd[ g_menuPosition[id] * 8 + key ] ) - } - return PLUGIN_HANDLED + switch (key) { + case 8: displayMenu(id,++g_menuPosition[id]) + case 9: displayMenu(id,--g_menuPosition[id]) + default: client_cmd(id, g_menuCmd[ g_menuPosition[id] * 8 + key ] ) + } + return PLUGIN_HANDLED +} +public clientActionMenu(id,key) { + switch (key) { + case 8: clientDisplayMenu(id, ++g_clientMenuPosition[id]) + case 9: clientDisplayMenu(id, --g_clientMenuPosition[id]) + default: client_cmd(id, g_clientMenuCmd[ g_clientMenuPosition[id] * 8 + key ]) + } + return PLUGIN_HANDLED } -displayMenu(id,pos) { +displayMenu(id, pos) { if (pos < 0) return @@ -171,13 +204,76 @@ displayMenu(id,pos) { show_menu(id,keys,menuBody) } +clientDisplayMenu(id,pos) { + if (pos < 0) + return + + new menuBody[512] + new b = 0 + new start = pos * MENUITEMSPERPAGE + + if ( start >= g_clientMenusNumber ) // MENUS_NUMBER + start = pos = g_clientMenuPosition[id] = 0 + + new len = format(menuBody,511, + g_coloredMenus ? "\yAMX Mod X Client Menu\R%d/%d^n\w^n" : "AMX Mod X Client Menu %d/%d^n^n" , pos+1, (g_clientMenusNumber / MENUITEMSPERPAGE) + (((g_clientMenusNumber % MENUITEMSPERPAGE) > 0) ? 1 : 0)) + + new end = start + MENUITEMSPERPAGE + new keys = MENU_KEY_0 + + if (end > g_clientMenusNumber ) // MENUS_NUMBER + end = g_clientMenusNumber // MENUS_NUMBER + + new flags = get_user_flags(id) + + for (new a = start; a < end; ++a) { + if ( (flags & g_clientMenuAccess[a]) && ( is_plugin_loaded(g_clientMenuPlugin[a])!=-1 ) ) { + keys |= (1< - Add a menu item to Menus Front-End") + register_srvcmd("amx_addmenuitem", "addmenuitem_cmd", 0, " - Add a menu item to Menus Front-End") + register_srvcmd("amx_addclientmenuitem", "addclientmenuitem_cmd", 0, " - Add a menu item to Client Menus Front-End") - g_coloredMenus = colored_menus() + g_coloredMenus = colored_menus() - AddDefaultMenus() + AddDefaultMenus() - // Add custom menu items - new configs[128] - get_configsdir(configs, 127) - server_cmd("exec %s/custommenuitems.cfg", configs) + // Add custom menu items + new configs[128] + get_configsdir(configs, 127) + server_cmd("exec %s/custommenuitems.cfg", configs) } \ No newline at end of file