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

randomize menus


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EDUTz
Senior Member
Join Date: Jun 2010
Location: Dracula's Homeland
Old 09-30-2014 , 06:10   randomize menus
Reply With Quote #1

I want to randomize some constants but i'm having trouble with it.

Code:
new const constants[][] =
{
        "constant1",
        "constant2",
        "constant3",
        "constant4",
        "constant5",
        "constan6"
}
so i wanna generate the menu to be displayed randomly, i took a look over here: https://forums.alliedmods.net/showth...=74666?t=74666 but it's a little bit tricky.

Code:
public menu_display(id)
{
	new menu = menu_create("Constantss", "handler_constants");
	/* for (new i = 0; i <sizeof(constants); i++)
	{
		menu_additem(menu, constants[i], "", 0); // case 0
	} */
        //Here it should be randomized to additem randomly according to what's in the constantans list
	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
	menu_display(id, menu, 0);
	return PLUGIN_HANDLED;
}
Code:
public handler_constants(id, menu, item)
{
	if(item == MENU_EXIT)
	{
		menu_cancel(id);
		return PLUGIN_HANDLED;
	}
        //client_print(id, print_chat, "You have selected %s", constants[item])
        //Here the randomized list generated above should be called corectly.
	menu_destroy(menu);
	return PLUGIN_HANDLED;
}
Any ideas how to do that ? I'm thinking pushing them into the arrays, but i don't know how to corectly use them in the handler....
EDUTz is offline
bat
Veteran Member
Join Date: Jul 2012
Old 09-30-2014 , 07:06   Re: randomize menus
Reply With Quote #2

Try
PHP Code:
constants([random_num(0sizeof constants -1)]) 
__________________

Last edited by bat; 09-30-2014 at 07:07. Reason: Forget -1
bat is offline
Send a message via Skype™ to bat
EDUTz
Senior Member
Join Date: Jun 2010
Location: Dracula's Homeland
Old 09-30-2014 , 07:49   Re: randomize menus
Reply With Quote #3

that's 100% incorrect, even if you put it this way showing the menu, you have to exclude the ones already shown ... so it's definetly incorrect. Even if you show it like that, you don't have a method for the callback .. it should be another way ...
EDUTz is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 10-01-2014 , 02:46   Re: randomize menus
Reply With Quote #4

how about you create a new variable for each random menu content
like
new funtions[64][32]
functions[1]="give_usp(id)"
functions[2]="give_health(id)"

and in the handler function
new data[6], iName[64];
new access, callback;

menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
new key = str_to_num(data); <--this is so you can store unique ids for each menu item above 1->8
for(int i=1;i<=MAX_FUNCTIONS(whatever);i++)
{
if(i==key)
{
functions[key]
}
}

I'm not sure this will work or even if you understand what I'm talking about
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-01-2014 , 05:07   Re: randomize menus
Reply With Quote #5

You can't directly execute code that is in a string.

The "data" field of the 'new menus' should be used to keep appropriate associations between the options in the menu and the menu handler.

So, you would need one array for the menu options and another for the unique data identifier (this value will be an integer that will be used in the switch of the menu handler). Simply get your random value with what ever method you want. Use that cached random value to register the menu item with the menu option and the data identifier.

Your menu handler will never need to change.
__________________

Last edited by fysiks; 10-01-2014 at 05:08.
fysiks is online now
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-01-2014 , 09:27   Re: randomize menus
Reply With Quote #6

You can push everything in an array, get a random data, clear it and so on.
__________________
HamletEagle 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 00:53.


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