View Single Post
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-21-2022 , 18:28   Re: how to add item for the category number 8 of the menu
Reply With Quote #10

@CrazY.
I tried using the code you posted but I ran into a problem when I tried to create multiple menus together and I don't know how to fix it, this what i did:

Code:
#include <amxmodx>
#include <amxmisc>

new Array:g_menuItems

enum _:ArrayTest
{
	Location,
	Item[ 32 ]
}

new g_playerMenuPage[33]
new g_menuloction[33]
new g_playerMenuItemData[33][10]
new eData[ ArrayTest ]

public plugin_init()
{
	g_menuItems = ArrayCreate(ArrayTest)

	for (new i = 1; i <= 5; i++)
	{
		eData[ Location ] = 1;
		copy( eData[ Item ], charsmax( eData[ Item ] ), fmt( "Item %d", i ) )
		ArrayPushArray(g_menuItems, eData )
	}
	
	for (new i = 1; i <= 5; i++)
	{
		eData[ Location ] = 2;
		copy( eData[ Item ], charsmax( eData[ Item ] ), fmt( "ItemPlus %d", i ) )
		ArrayPushArray(g_menuItems, eData )
	}

	register_clcmd("say /menu", "@TestMenu")

	register_menu("Cool Menu", -1, "MenuHandler")
}

@TestMenu( id )
{
	new iMenu = menu_create( "\yTest Menu:", "@TestHandler" );
	
	menu_additem( iMenu, "Location One", "1" );
	menu_additem( iMenu, "Location Two", "2" );
	
	menu_display(id, iMenu)
	return PLUGIN_HANDLED;
}

@TestHandler( id, iMenu, iItem ) 
{
	if(iItem != MENU_EXIT) 
	{
		new szData[ 10 ], iUnused;
		menu_item_getinfo( iMenu, iItem, iUnused, szData, charsmax( szData ), .callback = iUnused )
		
		new iItemID = str_to_num( szData ); 
		
		ShowMenu(id, iItemID )
	}
	menu_destroy(iMenu);
	return PLUGIN_HANDLED;

}


public ShowMenu(index, iLocation )
{
	const itemsPerPage = 7
	new itemCount = ArraySize(g_menuItems)
	new pageCount = floatround(itemCount / float(itemsPerPage), floatround_ceil)
	new page = clamp(g_playerMenuPage[index], 0, pageCount - 1)
	new offset = page * itemsPerPage
	g_menuloction[ index ] = iLocation
	new menu[MAX_MENU_LENGTH], len, key

	len = copy(menu, charsmax(menu), "\yCool Menu")

	if (pageCount > 1)
	{
		len += formatex(menu[len], charsmax(menu) - len, " %d/%d", page + 1, pageCount)
	}

	len += copy(menu[len], charsmax(menu) - len, "^n^n")

	arrayset(g_playerMenuItemData[index], -1, sizeof g_playerMenuItemData[])

	for (new i = offset, limit = min(itemCount, offset + itemsPerPage); i < limit; i++)
	{
		ArrayGetArray(g_menuItems, i, eData )
		
		if( eData[ Location ] && eData[ Location ] != iLocation )
		{
			continue;
		}
		
		g_playerMenuItemData[index][key] = i
		
		len += formatex(menu[len], charsmax(menu) - len, "\r%d. \w%s^n", ++key, eData[ Item ])
		
	}

	for (new i = key; i <= itemsPerPage; i++)
	{
		len += copy(menu[len], charsmax(menu) - len, "^n")
	}

	if (pageCount > 1)
	{
		if (page > 0)
		{
			len += copy(menu[len], charsmax(menu) - len, "\r8. \wBack^n")
		}
		else
		{
			len += copy(menu[len], charsmax(menu) - len, "\r8. \dBack^n")
		}
		
		if (page < pageCount - 1)
		{
			len += copy(menu[len], charsmax(menu) - len, "\r9. \wMore^n")
		}
		else
		{
			len += copy(menu[len], charsmax(menu) - len, "\r9. \dMore^n")
		}
	}

	len += copy(menu[len], charsmax(menu) - len, "\r0. \wExit")

	g_playerMenuPage[index] = page

	show_menu(index, -1, menu, -1, "Cool Menu")
}

public MenuHandler(index, key)
{
	switch (key)
	{
		case 7:
		{
			// Back
			g_playerMenuPage[index] -= 1
			ShowMenu(index, g_menuloction[ index ])
		}
		case 8:
		{
			// More
			g_playerMenuPage[index] += 1
			ShowMenu(index, g_menuloction[ index ])
		}
		case 9:
		{
			// Exit
		}
		default:
		{
			new item = g_playerMenuItemData[index][key]

			if (0 <= item < ArraySize(g_menuItems))
			{
				new buffer[32]
				ArrayGetString(g_menuItems, item, buffer, charsmax(buffer))
				client_print(index, print_chat, "You've selected ^"%s^"", buffer)
			}

			ShowMenu(index, g_menuloction[ index ])
		}
	}

	return PLUGIN_HANDLED
}
Menu number one:



Menu number two:



As you can see, they are combined, each menu is reading the same number, not like the new menu style, Please try to test the code to understand more about the issue.
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline