Код:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "NewMenu"
#define VERSION "1.0"
#define AUTHOR "CrAsH"
new g_LoadMaps[81]
new g_MapsNum
new g_Maps[99][64]
new iPlayerPage[33]
new iPlayerAddBlank[33]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /menu", "ShowMenu")
}
public plugin_cfg()
{
new g_LoadDir[81]
get_configsdir(g_LoadDir, charsmax( g_LoadDir ))
formatex(g_LoadMaps, charsmax( g_LoadMaps ), "%s/maps.ini", g_LoadDir)
if(!file_exists( g_LoadMaps ))
{
//
}
new iFile = fopen(g_LoadMaps, "rt")
while(!feof( iFile ))
{
new szText[64]
fgets(iFile, szText, charsmax( szText ))
trim( szText )
if(!strlen( szText ) || szText[0] == ';' || (szText[0] == '/' && szText[1] == '/' ))
continue
++g_MapsNum
g_Maps[g_MapsNum] = szText
server_print("#%d - %s", g_MapsNum, g_Maps[g_MapsNum])
}
fclose( iFile )
}
public ShowMenu(id)
{
MainMenu(id)
}
stock MainMenu(id, iPage = 1)
{
new iPages = g_MapsNum / 6
new iItems = g_MapsNum - (iPages * 6)
if(iItems > 0)
{
++iPages
}
new iMenu = menu_create("Работа с файлами", "MainMenu_handler" )
for(new i = 1; i <= 6; i++)
{
if((iPage + i) > g_MapsNum)
break
new szStr[10]
num_to_str(i, szStr, charsmax( szStr ))
new iMap = GetMenuInfo(iPage, i)
if(iMap == 0)
{
++iPlayerAddBlank[id]
menu_addblank(iMenu, 1)
continue
}
new szMaps[64]
formatex(szMaps, charsmax( szMaps ), "%s%s", g_Maps[iMap], i == 6 ? "^n" : "")
menu_additem(iMenu, szMaps, szStr, 0)
}
menu_additem(iMenu, "Начать голосование^n", "7", 0)
menu_additem(iMenu, "Назад", "8", iPage > 1 ? 0 : ADMIN_ADMIN)
menu_additem(iMenu, "Вперед^n", "9", iPages != iPage ? 0 : ADMIN_ADMIN)
menu_additem(iMenu, "Выход", "0", 0)
menu_setprop(iMenu, MEXIT_ALL, 0)
menu_display(id, iMenu, 0)
iPlayerPage[id] = iPage
return PLUGIN_CONTINUE
}
public MainMenu_handler(id, iMenu, iItem)
{
if(iItem == MENU_EXIT)
{
menu_destroy( iMenu )
return PLUGIN_HANDLED
}
new szData[6], szName[64], iAccess,iCallback
menu_item_getinfo(iMenu, iItem, iAccess, szData, charsmax( szData ), szName, charsmax( szName ), iCallback)
new iKey = str_to_num( szData )
if(iPlayerAddBlank[id])
{
iKey -= iPlayerAddBlank[id]
iPlayerAddBlank[id] = 0
}
switch( iKey )
{
case 7:
{
client_print(id, print_chat, "startvote")
}
case 8:
{
--iPlayerPage[id]
MainMenu(id, iPlayerPage[id])
}
case 9:
{
++iPlayerPage[id]
MainMenu(id, iPlayerPage[id])
}
case 0:
{
menu_destroy( iMenu )
return PLUGIN_HANDLED
}
default:
{
new iMap = GetMenuInfo(iPlayerPage[id], iKey)
client_print(id, print_chat, "%s", g_Maps[iMap])
}
}
menu_destroy( iMenu )
return PLUGIN_HANDLED
}
stock GetMenuInfo(iPage, iItem)
{
if(iPage != 1)
{
iPage = (6 * iPage) - 5
}
for(new i = 1; i <= 6; i++)
{
if((i + iPage - 1) > g_MapsNum)
break
if(iItem != i)
continue
return (i + iPage) - 1
}
return 0
}