AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   randomize menus (https://forums.alliedmods.net/showthread.php?t=249097)

EDUTz 09-30-2014 06:10

randomize menus
 
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....

bat 09-30-2014 07:06

Re: randomize menus
 
Try
PHP Code:

constants([random_num(0sizeof constants -1)]) 


EDUTz 09-30-2014 07:49

Re: randomize menus
 
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 ...

aron9forever 10-01-2014 02:46

Re: randomize menus
 
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

fysiks 10-01-2014 05:07

Re: randomize menus
 
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.

HamletEagle 10-01-2014 09:27

Re: randomize menus
 
You can push everything in an array, get a random data, clear it and so on.


All times are GMT -4. The time now is 17:39.

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