Raised This Month: $ Target: $400
 0% 

Solved how to add item for the category number 8 of the menu


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 02-26-2022 , 08:44   Re: how to add item for the category number 8 of the menu
Reply With Quote #8

You can easily make a new menu out of the old menu.
Say /menu to pop up our cool menu.

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

new Array:g_menuItems

new g_playerMenuPage[33]
new g_playerMenuItemData[33][10]

public plugin_init()
{
	g_menuItems = ArrayCreate(32)

	for (new i = 1; i <= 20; i++)
	{
		ArrayPushString(g_menuItems, fmt("Item %d", i))
	}

	register_clcmd("say /menu", "ShowMenu")

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

public ShowMenu(index)
{
	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

	new buffer[32], 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++)
	{
		ArrayGetString(g_menuItems, i, buffer, charsmax(buffer))
		g_playerMenuItemData[index][key] = i
		len += formatex(menu[len], charsmax(menu) - len, "\r%d. \w%s^n", ++key, buffer)
	}

	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)
		}
		case 8:
		{
			// More
			g_playerMenuPage[index] += 1
			ShowMenu(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)
		}
	}

	return PLUGIN_HANDLED
}
__________________









Last edited by CrazY.; 02-26-2022 at 08:44.
CrazY. is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:20.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode