Update menufront.sma
Just a minor update the plugin and change work in lang-key: you can now add the file through the menu items with the lang-key.
This commit is contained in:
parent
c4497ff17d
commit
45b63c4394
@ -20,24 +20,47 @@
|
||||
#define MENUITEMSPERPAGE 8
|
||||
//#define MENUS_NUMBER 16
|
||||
|
||||
new g_coloredMenus
|
||||
new g_menuPosition[MAX_PLAYERS + 1]
|
||||
|
||||
new g_menusNumber = 0
|
||||
new g_menuBody[MAXMENUS][STRINGSIZE]
|
||||
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[MAX_PLAYERS + 1]
|
||||
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]
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Menus Front-End", AMXX_VERSION_STR, "AMXX Dev Team")
|
||||
register_dictionary("menufront.txt")
|
||||
register_dictionary("common.txt")
|
||||
|
||||
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 | plugin filename> - Add a menu item to Menus Front-End")
|
||||
register_srvcmd("amx_addclientmenuitem", "addclientmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name | plugin filename> - Add a menu item to Client Menus Front-End")
|
||||
|
||||
g_coloredMenus = colored_menus()
|
||||
}
|
||||
|
||||
public plugin_cfg()
|
||||
{
|
||||
AddDefaultMenus()
|
||||
|
||||
new configs[128]
|
||||
get_configsdir(configs, charsmax(configs))
|
||||
server_cmd("exec %s/custommenuitems.cfg", configs)
|
||||
}
|
||||
|
||||
// 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
|
||||
@ -51,35 +74,13 @@ public AddMenu(const menuBody[], const menuCmd[], const menuAccess, const menuPl
|
||||
}
|
||||
|
||||
copy(g_menuBody[g_menusNumber], STRINGLENGTH, menuBody)
|
||||
g_menuBodyPhrase[g_menusNumber] = false
|
||||
|
||||
copy(g_menuCmd[g_menusNumber], STRINGLENGTH, menuCmd)
|
||||
g_menuAccess[g_menusNumber] = menuAccess
|
||||
|
||||
copy(g_menuPlugin[g_menusNumber], STRINGLENGTH, menuPlugin)
|
||||
|
||||
g_menusNumber++
|
||||
server_print("Menu item %d added to Menus Front-End: ^"%s^" from plugin ^"%s^"", g_menusNumber, menuBody, menuPlugin)
|
||||
}
|
||||
|
||||
public AddMenuLang(const menuBody[], const menuCmd[], const menuAccess, const menuPlugin[])
|
||||
{
|
||||
if (g_menusNumber + 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_menuBody[g_menusNumber], STRINGLENGTH, menuBody)
|
||||
g_menuBodyPhrase[g_menusNumber] = true
|
||||
|
||||
copy(g_menuCmd[g_menusNumber], STRINGLENGTH, menuCmd)
|
||||
g_menuAccess[g_menusNumber] = menuAccess
|
||||
|
||||
copy(g_menuPlugin[g_menusNumber], STRINGLENGTH, menuPlugin)
|
||||
g_menusNumber++
|
||||
|
||||
//server_print("Menu item %d added to Menus Front-End: ^"%s^" (LANG) from plugin ^"%s^"", g_menusNumber, menuBody, menuPlugin)
|
||||
// server_print("Menu item %d added to Menus Front-End: ^"%s^" from plugin ^"%s^"", g_menusNumber, menuBody, menuPlugin)
|
||||
}
|
||||
|
||||
public AddClientMenu(const menuBody[], const menuCmd[], const menuAccess, const menuPlugin[])
|
||||
@ -91,8 +92,6 @@ public AddClientMenu(const menuBody[], const menuCmd[], const menuAccess, const
|
||||
}
|
||||
|
||||
copy(g_clientMenuBody[g_clientMenusNumber], STRINGLENGTH, menuBody)
|
||||
g_clientMenuBodyPhrase[g_clientMenusNumber] = false
|
||||
|
||||
copy(g_clientMenuCmd[g_clientMenusNumber], STRINGLENGTH, menuCmd)
|
||||
g_clientMenuAccess[g_clientMenusNumber] = menuAccess
|
||||
|
||||
@ -105,23 +104,24 @@ public AddClientMenu(const menuBody[], const menuCmd[], const menuAccess, const
|
||||
AddDefaultMenus()
|
||||
{
|
||||
new flags;
|
||||
AddMenuLang("KICK_PLAYER", "amx_kickmenu", get_clcmd_flags("amx_kickmenu", flags) ? flags : ADMIN_KICK , "Players Menu")
|
||||
AddMenuLang("BAN_PLAYER", "amx_banmenu", get_clcmd_flags("amx_banmenu", flags) ? flags : ADMIN_BAN, "Players Menu")
|
||||
AddMenuLang("SLAP_SLAY", "amx_slapmenu", get_clcmd_flags("amx_slapmenu", flags) ? flags : ADMIN_SLAY, "Players Menu")
|
||||
AddMenuLang("TEAM_PLAYER", "amx_teammenu", get_clcmd_flags("amx_teammenu", flags) ? flags : ADMIN_LEVEL_A, "Players Menu")
|
||||
AddMenuLang("CHANGEL", "amx_mapmenu", get_clcmd_flags("amx_mapmenu", flags) ? flags : ADMIN_MAP, "Maps Menu")
|
||||
AddMenuLang("VOTE_MAPS", "amx_votemapmenu", get_clcmd_flags("amx_votemapmenu", flags) ? flags : ADMIN_VOTE, "Maps Menu")
|
||||
AddMenuLang("SPECH_STUFF", "amx_speechmenu", get_clcmd_flags("amx_speechmenu", flags) ? flags : ADMIN_MENU, "Commands Menu")
|
||||
AddMenuLang("CLIENT_COM", "amx_clcmdmenu", get_clcmd_flags("amx_clcmdmenu", flags) ? flags : ADMIN_LEVEL_A, "Players Menu")
|
||||
AddMenuLang("SERVER_COM", "amx_cmdmenu", get_clcmd_flags("amx_cmdmenu", flags) ? flags : ADMIN_MENU, "Commands Menu")
|
||||
AddMenuLang("CVARS_SET", "amx_cvarmenu", get_clcmd_flags("amx_cvarmenu", flags) ? flags : ADMIN_CVAR, "Commands Menu")
|
||||
AddMenuLang("CONFIG", "amx_cfgmenu", get_clcmd_flags("amx_cfgmenu", flags) ? flags : ADMIN_MENU, "Commands Menu")
|
||||
AddMenuLang("LANG_SET", "amx_langmenu", get_clcmd_flags("amx_langmenu", flags) ? flags : ADMIN_CFG, "Multi-Lingual System")
|
||||
AddMenuLang("STATS_SET", "amx_statscfgmenu", get_clcmd_flags("amx_statscfgmenu", flags) ? flags : ADMIN_CFG, "Stats Configuration")
|
||||
AddMenuLang("PAUSE_PLUG", "amx_pausecfgmenu", get_clcmd_flags("amx_pausecfgmenu", flags) ? flags : ADMIN_CFG, "Pause Plugins")
|
||||
AddMenuLang("RES_WEAP", "amx_restmenu", get_clcmd_flags("amx_restmenu", flags) ? flags : ADMIN_CFG, "Restrict Weapons")
|
||||
AddMenuLang("TELE_PLAYER", "amx_teleportmenu", get_clcmd_flags("amx_teleportmenu", flags) ? flags : ADMIN_CFG, "Teleport Menu")
|
||||
AddMenu("KICK_PLAYER", "amx_kickmenu", get_clcmd_flags("amx_kickmenu", flags) ? flags : ADMIN_KICK , "Players Menu")
|
||||
AddMenu("BAN_PLAYER", "amx_banmenu", get_clcmd_flags("amx_banmenu", flags) ? flags : ADMIN_BAN, "Players Menu")
|
||||
AddMenu("SLAP_SLAY", "amx_slapmenu", get_clcmd_flags("amx_slapmenu", flags) ? flags : ADMIN_SLAY, "Players Menu")
|
||||
AddMenu("TEAM_PLAYER", "amx_teammenu", get_clcmd_flags("amx_teammenu", flags) ? flags : ADMIN_LEVEL_A, "Players Menu")
|
||||
AddMenu("CHANGEL", "amx_mapmenu", get_clcmd_flags("amx_mapmenu", flags) ? flags : ADMIN_MAP, "Maps Menu")
|
||||
AddMenu("VOTE_MAPS", "amx_votemapmenu", get_clcmd_flags("amx_votemapmenu", flags) ? flags : ADMIN_VOTE, "Maps Menu")
|
||||
AddMenu("SPECH_STUFF", "amx_speechmenu", get_clcmd_flags("amx_speechmenu", flags) ? flags : ADMIN_MENU, "Commands Menu")
|
||||
AddMenu("CLIENT_COM", "amx_clcmdmenu", get_clcmd_flags("amx_clcmdmenu", flags) ? flags : ADMIN_LEVEL_A, "Players Menu")
|
||||
AddMenu("SERVER_COM", "amx_cmdmenu", get_clcmd_flags("amx_cmdmenu", flags) ? flags : ADMIN_MENU, "Commands Menu")
|
||||
AddMenu("CVARS_SET", "amx_cvarmenu", get_clcmd_flags("amx_cvarmenu", flags) ? flags : ADMIN_CVAR, "Commands Menu")
|
||||
AddMenu("CONFIG", "amx_cfgmenu", get_clcmd_flags("amx_cfgmenu", flags) ? flags : ADMIN_MENU, "Commands Menu")
|
||||
AddMenu("LANG_SET", "amx_langmenu", get_clcmd_flags("amx_langmenu", flags) ? flags : ADMIN_CFG, "Multi-Lingual System")
|
||||
AddMenu("STATS_SET", "amx_statscfgmenu", get_clcmd_flags("amx_statscfgmenu", flags) ? flags : ADMIN_CFG, "Stats Configuration")
|
||||
AddMenu("PAUSE_PLUG", "amx_pausecfgmenu", get_clcmd_flags("amx_pausecfgmenu", flags) ? flags : ADMIN_CFG, "Pause Plugins")
|
||||
AddMenu("RES_WEAP", "amx_restmenu", get_clcmd_flags("amx_restmenu", flags) ? flags : ADMIN_CFG, "Restrict Weapons")
|
||||
AddMenu("TELE_PLAYER", "amx_teleportmenu", get_clcmd_flags("amx_teleportmenu", flags) ? flags : ADMIN_CFG, "Teleport Menu")
|
||||
}
|
||||
|
||||
stock bool:get_clcmd_flags(const search_command[], &flags)
|
||||
{
|
||||
new count = get_clcmdsnum(-1);
|
||||
@ -142,15 +142,15 @@ stock bool:get_clcmd_flags(const search_command[], &flags)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public actionMenu(id, key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 8: displayMenu(id, ++g_menuPosition[id])
|
||||
case 9: displayMenu(id, --g_menuPosition[id])
|
||||
default: client_cmd(id, "%s", g_menuCmd[g_menuPosition[id] * 8 + key])
|
||||
default: client_cmd(id, "%s", g_menuCmd[g_menuPosition[id] * 8 + key]) // may need to replace : amxclient_cmd?
|
||||
}
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
@ -158,11 +158,10 @@ public clientActionMenu(id, key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 8: clientDisplayMenu(id, ++g_clientMenuPosition[id])
|
||||
case 9: clientDisplayMenu(id, --g_clientMenuPosition[id])
|
||||
default: client_cmd(id, "%s", g_clientMenuCmd[g_clientMenuPosition[id] * 8 + key])
|
||||
case 8: clientDisplayMenu(id, ++g_menuPosition[id])
|
||||
case 9: clientDisplayMenu(id, --g_menuPosition[id])
|
||||
default: client_cmd(id, "%s", g_clientMenuCmd[g_menuPosition[id] * 8 + key]) // may need to replace : amxclient_cmd?
|
||||
}
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
@ -182,21 +181,19 @@ displayMenu(id, pos)
|
||||
|
||||
g_coloredMenus ? "\yAMX Mod X Menu\R%d/%d^n\w^n" : "AMX Mod X Menu %d/%d^n^n" , pos + 1, (g_menusNumber / MENUITEMSPERPAGE) + (((g_menusNumber % MENUITEMSPERPAGE) > 0) ? 1 : 0))
|
||||
|
||||
new end = start + MENUITEMSPERPAGE
|
||||
new end = min(start + MENUITEMSPERPAGE, g_menusNumber);
|
||||
new keys = MENU_KEY_0
|
||||
|
||||
if (end > g_menusNumber) // MENUS_NUMBER
|
||||
end = g_menusNumber // MENUS_NUMBER
|
||||
|
||||
new iUserFlags = get_user_flags(id);
|
||||
for (new a = start; a < end; ++a)
|
||||
{
|
||||
if ( access(id, g_menuAccess[a]) &&
|
||||
if ( iUserFlags & g_menuAccess[a] &&
|
||||
((is_plugin_loaded(g_menuPlugin[a]) != -1) || // search plugins for registered name
|
||||
(is_plugin_loaded(g_menuPlugin[a], true) != -1))) // search plugins for filename
|
||||
{
|
||||
keys |= (1<<b)
|
||||
|
||||
if (g_menuBodyPhrase[a])
|
||||
if (GetLangTransKey(g_menuBody[a]) != TransKey_Bad)
|
||||
len += format(menuBody[len], charsmax(menuBody) - len, "%d. %L^n", ++b, id, g_menuBody[a])
|
||||
else
|
||||
len += format(menuBody[len], charsmax(menuBody) - len, "%d. %s^n", ++b, g_menuBody[a])
|
||||
@ -205,12 +202,12 @@ displayMenu(id, pos)
|
||||
|
||||
if (g_coloredMenus)
|
||||
{
|
||||
if (g_menuBodyPhrase[a])
|
||||
if (GetLangTransKey(g_menuBody[a]) != TransKey_Bad)
|
||||
len += format(menuBody[len], charsmax(menuBody) - len, "\d%d. %L^n\w", b, id, g_menuBody[a])
|
||||
else
|
||||
len += format(menuBody[len], charsmax(menuBody) - len, "\d%d. %s^n\w", b, g_menuBody[a])
|
||||
} else {
|
||||
if (g_menuBodyPhrase[a])
|
||||
if (GetLangTransKey(g_menuBody[a]) != TransKey_Bad)
|
||||
len += format(menuBody[len], charsmax(menuBody) - len, "#. %L^n", id, g_menuBody[a])
|
||||
else
|
||||
len += format(menuBody[len], charsmax(menuBody) - len, "#. %s^n", g_menuBody[a])
|
||||
@ -239,25 +236,23 @@ clientDisplayMenu(id, pos)
|
||||
new start = pos * MENUITEMSPERPAGE
|
||||
|
||||
if (start >= g_clientMenusNumber) // MENUS_NUMBER
|
||||
start = pos = g_clientMenuPosition[id] = 0
|
||||
start = pos = g_menuPosition[id] = 0
|
||||
|
||||
new len = format(menuBody, charsmax(menuBody), 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 end = min(start + MENUITEMSPERPAGE, g_clientMenusNumber);
|
||||
new keys = MENU_KEY_0
|
||||
|
||||
if (end > g_clientMenusNumber) // MENUS_NUMBER
|
||||
end = g_clientMenusNumber // MENUS_NUMBER
|
||||
|
||||
new iUserFlags = get_user_flags(id);
|
||||
for (new a = start; a < end; ++a)
|
||||
{
|
||||
if ( access(id, g_clientMenuAccess[a]) &&
|
||||
if ( iUserFlags & g_clientMenuAccess[a] &&
|
||||
((is_plugin_loaded(g_clientMenuPlugin[a]) != -1) || // search plugins for registered name
|
||||
(is_plugin_loaded(g_clientMenuPlugin[a], true) != -1))) // search plugins for file name
|
||||
{
|
||||
keys |= (1<<b)
|
||||
|
||||
if (g_clientMenuBodyPhrase[a])
|
||||
if (GetLangTransKey(g_clientMenuBody[a]) != TransKey_Bad)
|
||||
len += format(menuBody[len], charsmax(menuBody) - len, "%d. %L^n", ++b, id, g_clientMenuBody[a])
|
||||
else
|
||||
len += format(menuBody[len], charsmax(menuBody) - len, "%d. %s^n", ++b, g_clientMenuBody[a])
|
||||
@ -266,12 +261,12 @@ clientDisplayMenu(id, pos)
|
||||
|
||||
if (g_coloredMenus)
|
||||
{
|
||||
if (g_clientMenuBodyPhrase[a])
|
||||
if (GetLangTransKey(g_clientMenuBody[a]) != TransKey_Bad)
|
||||
len += format(menuBody[len], charsmax(menuBody) - len, "\d%d. %L^n\w", b, id, g_clientMenuBody[a])
|
||||
else
|
||||
len += format(menuBody[len], charsmax(menuBody) - len, "\d%d. %s^n\w", b, g_clientMenuBody[a])
|
||||
} else {
|
||||
if (g_clientMenuBodyPhrase[a])
|
||||
if (GetLangTransKey(g_clientMenuBody[a]) != TransKey_Bad)
|
||||
len += format(menuBody[len], charsmax(menuBody) - len, "#. %L^n", id, g_clientMenuBody[a])
|
||||
else
|
||||
len += format(menuBody[len], charsmax(menuBody) - len, "#. %s^n", g_clientMenuBody[a])
|
||||
@ -301,7 +296,7 @@ public cmdMenu(id, level, cid)
|
||||
public clientCmdMenu(id, level, cid)
|
||||
{
|
||||
if (cmd_access(id, level, cid, 1))
|
||||
clientDisplayMenu(id, g_clientMenuPosition[id] = 0)
|
||||
clientDisplayMenu(id, g_menuPosition[id] = 0)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
@ -341,30 +336,3 @@ public addclientmenuitem_cmd(id, level, cid)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Menus Front-End", AMXX_VERSION_STR, "AMXX Dev Team")
|
||||
register_dictionary("menufront.txt")
|
||||
register_dictionary("common.txt")
|
||||
|
||||
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 | plugin filename> - Add a menu item to Menus Front-End")
|
||||
register_srvcmd("amx_addclientmenuitem", "addclientmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name | plugin filename> - Add a menu item to Client Menus Front-End")
|
||||
|
||||
g_coloredMenus = colored_menus()
|
||||
|
||||
|
||||
}
|
||||
public plugin_cfg()
|
||||
{
|
||||
AddDefaultMenus()
|
||||
|
||||
new configs[128]
|
||||
get_configsdir(configs, charsmax(configs))
|
||||
server_cmd("exec %s/custommenuitems.cfg", configs)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user