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

show_menu with loop for


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mikka
Member
Join Date: Dec 2018
Old 11-03-2023 , 07:10   show_menu with loop for
Reply With Quote #1

Hello, at the outset, I would like to inform you that I don't want to use menu_additem. I need information on how to add a list of items to my menu using a for loop. The code below doesn't display it correctly (it only displays the last element of the loop)..

Code:
public my_menu(id) {
	new format_menu[1024];
	
	formatex(format_menu, charsmax(format_menu), "\ySelect item:^nCountdown: %d!^n^n", timer);
	
	for(new i=0; i < items; i++) {
		formatex(format_menu, charsmax(format_menu), "%d. %s", i+1, itemsName[i])
	        show_menu(id, M_KEYS, format_menu, -1, "Item lists");
}
	return PLUGIN_HANDLED;
}
Mikka is offline
Leech_v2
Senior Member
Join Date: Mar 2011
Location: Chinese GuangDong
Old 11-03-2023 , 13:36   Re: show_menu with loop for
Reply With Quote #2

Array elements can be used as string parameters. The meaning is to start filling in the content at the element position.At this point, The capacity of a string needs to be reduced by element index.
Otherwise, out of bounds characters will be filled into other variables adjacent to the array in memory
PHP Code:
byteId += formatex(array[byteId], charsmax(array) - byteId"new line^n"

Last edited by Leech_v2; 11-03-2023 at 14:25. Reason: = change to +=
Leech_v2 is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 11-03-2023 , 13:43   Re: show_menu with loop for
Reply With Quote #3

first of all you format menu body then call show_menu:

Code:
#include <amxmodx> public my_menu(id) {     new format_menu[1024], iCounter;         iCounter = formatex(format_menu, charsmax(format_menu), "\ySelect item:^nCountdown: %d!^n^n", timer);         for(new i=0; i < items; i++)     {         iCounter += formatex(format_menu[iCounter], charsmax(format_menu), "%d. %s^n", i+1, itemsName[i])     }     show_menu(id, M_KEYS, format_menu, -1, "Item lists"); }
lexzor 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 08:06.


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