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.
This commit is contained in:
parent
188023b5ac
commit
e343d224ce
@ -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;
|
||||
}
|
@ -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<<b)
|
||||
if (g_clientMenuBodyPhrase[a])
|
||||
len += format(menuBody[len],511-len,"%d. %L^n",++b, id, g_clientMenuBody[ a ] )
|
||||
else
|
||||
len += format(menuBody[len],511-len,"%d. %s^n",++b, g_clientMenuBody[ a ] )
|
||||
}
|
||||
else {
|
||||
++b
|
||||
if ( g_coloredMenus ) {
|
||||
if (g_clientMenuBodyPhrase[a])
|
||||
len += format(menuBody[len],511-len, "\d%d. %L^n\w",b, id, g_clientMenuBody[ a ] )
|
||||
else
|
||||
len += format(menuBody[len],511-len, "\d%d. %s^n\w",b, g_clientMenuBody[ a ] )
|
||||
}
|
||||
else {
|
||||
if (g_clientMenuBodyPhrase[a])
|
||||
len += format(menuBody[len],511-len, "#. %L^n", id, g_clientMenuBody[ a ] )
|
||||
else
|
||||
len += format(menuBody[len],511-len, "#. %s^n", g_clientMenuBody[ a ] )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (end != g_clientMenusNumber ) { // MENUS_NUMBER
|
||||
format(menuBody[len],511-len,"^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT")
|
||||
keys |= MENU_KEY_9
|
||||
}
|
||||
else {
|
||||
format(menuBody[len],511-len,"^n0. %L", id, pos ? "BACK" : "EXIT")
|
||||
}
|
||||
|
||||
show_menu(id, keys, menuBody)
|
||||
}
|
||||
|
||||
public cmdMenu(id,level,cid) {
|
||||
if (cmd_access(id,level,cid,1))
|
||||
displayMenu(id,g_menuPosition[id] = 0)
|
||||
displayMenu(id, g_menuPosition[id] = 0)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
public clientCmdMenu(id,level,cid) {
|
||||
if (cmd_access(id, level, cid, 1))
|
||||
clientDisplayMenu(id, g_clientMenuPosition[id] = 0)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
public addmenuitem_cmd(id, level, cid) {
|
||||
if (!cmd_access(id, level, cid, 5))
|
||||
@ -196,24 +292,44 @@ public addmenuitem_cmd(id, level, cid) {
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
public addclientmenuitem_cmd(id, level, cid) {
|
||||
if (!cmd_access(id, level, cid, 5))
|
||||
return PLUGIN_HANDLED
|
||||
|
||||
// AddMenu(const menuBody[], const menuCmd[], const menuAccess, const menuPlugin[])
|
||||
new menuBody[STRINGSIZE], menuCmd[STRINGSIZE], flags[STRINGSIZE], menuAccess = 0, menuPlugin[STRINGSIZE]
|
||||
read_argv(1, menuBody, STRINGLENGTH)
|
||||
read_argv(2, menuCmd, STRINGLENGTH)
|
||||
read_argv(3, flags, STRINGLENGTH)
|
||||
menuAccess = read_flags(flags)
|
||||
read_argv(4, menuPlugin, STRINGLENGTH)
|
||||
|
||||
|
||||
AddClientMenu(menuBody, menuCmd, menuAccess, menuPlugin)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
public plugin_init() {
|
||||
register_plugin("Menus Front-End",AMXX_VERSION_STR,"AMXX Dev Team")
|
||||
register_plugin("Menus Front-End",AMXX_VERSION_STR,"AMXX Dev Team")
|
||||
|
||||
register_dictionary("menufront.txt")
|
||||
register_dictionary("common.txt")
|
||||
register_dictionary("menufront.txt")
|
||||
register_dictionary("common.txt")
|
||||
|
||||
register_menucmd(register_menuid("AMX Mod X Menu"),1023,"actionMenu")
|
||||
register_clcmd("amxmodmenu","cmdMenu",ADMIN_MENU,"- displays menus")
|
||||
register_menucmd(register_menuid("AMX Mod X Menu"), 1023, "actionMenu")
|
||||
register_menucmd(register_menuid("AMX Mod X Client Menu"), 1023, "clientActionMenu")
|
||||
register_clcmd("amxmodmenu", "cmdMenu", ADMIN_MENU, "- displays menus")
|
||||
register_clcmd("amx_menu", "clientCmdMenu", 0, "- displays menus available to client")
|
||||
|
||||
register_srvcmd("amx_addmenuitem", "addmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name> - Add a menu item to Menus Front-End")
|
||||
register_srvcmd("amx_addmenuitem", "addmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name> - Add a menu item to Menus Front-End")
|
||||
register_srvcmd("amx_addclientmenuitem", "addclientmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name> - 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user