Raised This Month: $51 Target: $400
 12% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 04-21-2022 , 21:46   Re: how to add item for the category number 8 of the menu
Reply With Quote #11

The problem is that ArraySize is returning the number of items of both "Locations", 1 and 2, altogether.
To fix that, either create one array for each "Location" or implement your own ArraySize ignoring all "Locations" but the specified.

Code:
LocationItemCount(location) {     new total         for (new i, count = ArraySize(g_menuItems), data[ArrayTest]; i < count; i++)     {         ArrayGetArray(g_menuItems, i, data)         if (location == data[Location])         {             total++         }     }     return total }

Personally, I would create one array for each menu, it's simpler and easier to maintain, the way you are doing it now is overcomplicated and won't get any real benefit compared to multiple arrays, but that's just my opinion, you're free to use whatever method you want.
__________________








CrazY. is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-21-2022 , 22:15   Re: how to add item for the category number 8 of the menu
Reply With Quote #12

Quote:
The problem is that ArraySize is returning the number of items of both "Locations", 1 and 2, altogether.
To fix that, either create one array for each "Location" or implement your own ArraySize ignoring all "Locations" but the specified.

Code:
LocationItemCount(location) {     new total         for (new i, count = ArraySize(g_menuItems), data[ArrayTest]; i < count; i++)     {         ArrayGetArray(g_menuItems, i, data)         if (location == data[Location])         {             total++         }     }     return total }
I tried this but it doesn't work.

Quote:
Personally, I would create one array for each menu, it's simpler and easier to maintain, the way you are doing it now is overcomplicated and won't get any real benefit compared to multiple arrays, but that's just my opinion, you're free to use whatever method you want.
Can you give me an example
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 04-22-2022 , 08:42   Re: how to add item for the category number 8 of the menu
Reply With Quote #13

Just copy and paste the "Cool Menu" stuff and rename it to something else. You may need to reset the page whenever you open a menu, g_playerMenuPage[id] = 0

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

new Array:g_menuItems, Array:g_anotherMenuItems

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

public plugin_init()
{
	g_menuItems = ArrayCreate(32)
	g_anotherMenuItems = ArrayCreate(32)

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


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

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

	register_menu("CoolMenu", -1, "MenuHandler")
	register_menu("AnotherMenu", -1, "AnotherMenuHandler")
}

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, "CoolMenu")
}

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
}

public ShowAnotherMenu(index)
{
	const itemsPerPage = 7
	new itemCount = ArraySize(g_anotherMenuItems)
	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), "\yAnother Cool 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_anotherMenuItems, 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, "AnotherMenu")
}

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

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

			ShowAnotherMenu(index)
		}
	}

	return PLUGIN_HANDLED
}
__________________









Last edited by CrazY.; 04-22-2022 at 08:43.
CrazY. is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-22-2022 , 10:35   Re: how to add item for the category number 8 of the menu
Reply With Quote #14

I thought about something else, using one array per menu would make the code very long because I'm creating a big project from nine menus, while all menus will be similer, I tried to use the code you posted in the previous post but it doesn't work or I'm not using it correctly can you give me an example of how to fix the issue with one menu and one array , I was using this method in the new menu style but I never had this problem
__________________
Youtube.com/Supremache

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

Last edited by Supremache; 04-22-2022 at 10:36.
Supremache is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 04-23-2022 , 05:01   Re: how to add item for the category number 8 of the menu
Reply With Quote #15

Supremache, take a look in my Cs pick up manager, you have an example there if i didnt miss your question.

Here: https://github.com/CraxorAMXX/CSPick...er/csum1.6.cpp
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-23-2022 , 11:02   Re: how to add item for the category number 8 of the menu
Reply With Quote #16

I'm trying to use the old menu style to replace an item in category 8 instead of 'back' with one array because all menu will be the same, But I get a problem with the menu still reading all the data of the array, test this plugin for understand what i mean, i really need this.
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 04-24-2022 , 00:58   Re: how to add item for the category number 8 of the menu
Reply With Quote #17

I readed the post but still dont understand , neither i trust crazy code .

Pleass tell me your end goal not.your coding goal .

What kind of plugin are you trying to do , what is suppose to do ?

Also check EFFx reply.
__________________
Project: Among Us

Last edited by Craxor; 04-24-2022 at 01:00.
Craxor is offline
Send a message via ICQ to Craxor
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-24-2022 , 02:23   Re: how to add item for the category number 8 of the menu
Reply With Quote #18

Quote:
Originally Posted by Craxor View Post
I readed the post but still dont understand , neither i trust crazy code .

Pleass tell me your end goal not.your coding goal .

What kind of plugin are you trying to do , what is suppose to do ?

Also check EFFx reply.
Test this plugin and you will understand my problem

I am creating an API shop plugin with many menu with the same data
New menu style:
1. Weapons skins
2. Models
3. Back and head skins
4. Items shop
5. Powerful shop
etc..
8. back
9. More
10. Exit

I am using the old style for adding a menu in catatory 8 instead of 'back' for all these menus but in old style menu The array is saved, not like the new menu, so if the first menu show up 5 items from the array it still reading all data on the array for example:

Title: First Shop ( 5 items )
1. Array Data 1
2. Array Data 2
3. Array Data 3
4. Array Data 4
5. Array Data 5

8. Shop time [ Working at X time ]
9. More
10. Exit

Title: Secound Shop ( 5 items too ) 1/2 | Title: Secound Shop ( 5 items Page 2 ) 2/2
1. Array Data 1 ( 6 ) | 1. Array Data 3 ( 8 )
2. Array Data 2 ( 7 ) | 2. Array Data 4 ( 9 )
| 3. Array Data 5 ( 10 )


8. Shop time [ Working at X time ]
9. More
10. Exit
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 04-24-2022 , 03:05   Re: how to add item for the category number 8 of the menu
Reply With Quote #19

So you are basicaly want to create Menu Inside menu .

1.There is no point in using an Array, il show you later .
2. I still see no point in hacking item number 8, after all, you hae 7 items per page and then the user will go on next page right? So, why do you wanna so hard to modify the item number 8? Even if you do , you have EFFx reply, i already told you to check it .
3. I see no point in using the old menu at all . If im not wrong in effx link, arkshine show an example using the neu menus

Edit: if you wann set 8 as Back thats also pointlrss, 0 Become back when you go to next page and Exit when.you are on the main page . So why??
__________________
Project: Among Us

Last edited by Craxor; 04-24-2022 at 03:13.
Craxor is offline
Send a message via ICQ to Craxor
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 04-24-2022 , 10:58   Re: how to add item for the category number 8 of the menu
Reply With Quote #20

Just renaming the "back" option won't work as MENU_BACK and MENU_NEXT don't trigger the menu handler.

Not sure what you mean by "I don't trust that code", if you are not aware, newmenus is just a oldmenu but made with the intent to make the developer's life easier whenever one needs a menu with dynamic items/pagination.

Newmenus does store the items in a vector, as I did with arrays

Code:
menuitem *Menu::AddItem(const char *name, const char *cmd, int access)
{
	menuitem *pItem = new menuitem;

	pItem->name = name;
	pItem->cmd = cmd;
	pItem->access = access;
	pItem->id = m_Items.length();
	pItem->handler = -1;
	pItem->isBlank = false;
	pItem->pfn = NULL;

	m_Items.append(pItem);

	return pItem;
}
If you check the source code of newmenus, you will clearly see that it does pretty much the same thing under the hood.

https://github.com/alliedmodders/amx...menus.cpp#L350

So again, I don't get your point, maybe you should provide a working solution, otherwise whatever you say is irrelevant.

-----------------

menu_additem doesn't actually add an item to the menu, it just stores it to a list of items to be used later when you call menu_display.

The problem with the oldmenu approach is that it assumes all items to be available in the menu when calculating the pagination, no matter the location, for that reason, skipping an item from being added won't behave as newmenus.

To get that done, you first have to define which items should be skipped. A solution would be to loop through all items and store the indexes of the ones to be added in a temporary array and use that array to create the menu instead of the g_menuItems one.

Working solution:

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 )
{
	new Array:itemsToAdd = ArrayCreate()

	for (new i = 0, data[ArrayTest], count = ArraySize(g_menuItems); i < count; i++)
	{
		// Add any item skipping logic here

		ArrayGetArray(g_menuItems, i, data)

		if (data[Location] && data[Location] != iLocation)
		{
			continue
		}

		ArrayPushCell(itemsToAdd, i)
	}

	const itemsPerPage = 7
	new itemCount = ArraySize(itemsToAdd)

	if (itemCount == 0)
	{
		client_print(index, print_chat, "No items to display.")
		return
	}

	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, itemId, limit = min(itemCount, offset + itemsPerPage); i < limit; i++)
	{
		itemId = ArrayGetCell(itemsToAdd, i)
		
		ArrayGetArray(g_menuItems, itemId, eData )
		
		g_playerMenuItemData[index][key] = itemId
		
		len += formatex(menu[len], charsmax(menu) - len, "\r%d. \w%s^n", ++key, eData[ Item ])
	}

	ArrayDestroy(itemsToAdd)

	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
}
__________________








CrazY. is offline
Reply



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 10:29.


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