AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Q.?] random_num (https://forums.alliedmods.net/showthread.php?t=185042)

kketan77 05-12-2012 06:37

[Q.?] random_num
 
PHP Code:

public menu_handler(idmenuitem
{
    .
    .
    .
    switch(
key)
    {
        case 
1
        {
        
abc
        
}
        case 
2
        {
        
abc
        
}
        case 
3
        {
        
abc
        
}
        case 
4
        {
        
abc
        
}
        case 
5:
        {
            
menu_handler(idmenurandom_num(03))
        }
    }
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED




:arrow:menu_handler(id, menu, random_num(0, 3)) is this correct?
:arrow:or it should be menu_handler(id, menu, random_num(1, 4))?
:arrow:or it should be menu_handler(id, menu, random_num(1, 2, 3, 4))?

Which one is correct? I am confused! :?:

mottzi 05-12-2012 06:39

Re: [Q.?] random_num
 
What are you trying to do? Explain bether.

kketan77 05-12-2012 06:47

Re: [Q.?] random_num
 
I what to set case 5 as random case selector which select random case from 1 to 4.

Larcyn 05-12-2012 07:00

Re: [Q.?] random_num
 
Do it easier for yourself,

at case 5 add this:

PHP Code:

switch(random_num(14))
{
    case 
1// If random num is 1 add code here.
    
case 2// If random num is 2 add code here.
    
case 3// If random num is 3 add code here.
    
case 4// If random num is 4 add code here.



kketan77 05-12-2012 07:05

Re: [Q.?] random_num
 
menu_handler(id, menu, random_num(1, 4)) is correct!

I did not make it simple, bcos i want to make custom choose menu for public from case 1 to case 4.

By the way ThnxLarcyn

Larcyn 05-12-2012 07:13

Re: [Q.?] random_num
 
Oh, I even misunderstood you, lol.

kketan77 05-12-2012 07:36

Re: [Q.?] random_num
 
Ohh really? :)

Code:

Q.I just want to know which one is correct syntax?

1. menu_handler(id, menu, random_num(0, 3))
2. menu_handler(id, menu, random_num(1, 4))
3. menu_handler(id, menu, random_num(1, 2, 3, 4))

Larcyn your example help me to know which one is correct syntax. :)
Indirectly you give me answer which is menu_handler(id, menu, random_num(1, 4))

Thnx :wink:

Aooka 05-12-2012 07:51

Re: [Q.?] random_num
 
You can go to : http://www.amxmodx.org/funcwiki.php?go=func&id=286
Good luck.

fysiks 05-12-2012 12:52

Re: [Q.?] random_num
 
Quote:

Originally Posted by kketan77 (Post 1707304)
menu_handler(id, menu, random_num(1, 4)) is correct!

That is not correct.

You will have errors because you are destroy the same menu twice. You should do this:

PHP Code:

switch( key == random_num(1,4) : key )
{
    case 
1
    {
        
// abc
    
}
    case 
2
    {
        
// abc
    
}
    case 
3
    {
        
// abc
    
}
    case 
4
    {
        
// abc
    
}



kketan77 05-12-2012 22:39

Re: [Q.?] random_num
 
PHP Code:

public classmenu_handler(idmenuitem)
{   
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);        
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);
    
    new 
key str_to_num(data);
    
    switch(
key)
    {
        case 
1:
        {
            
cs_reset_user_model(id)
            new 
CsTeams:team cs_get_user_team(id)
            if (
team == CS_TEAM_CT)
            {
                
cs_set_user_model (id"swatboy")
                
client_print(0print_chat"Your Class Set as 'SWATBOY'!")
            }
            else if (
team == CS_TEAM_T)
            {
                
cs_set_user_model (id"trxboy")
                
client_print(0print_chat"Your Class Set as 'TRXBOY'!")
            }
        }
        case 
2:
        {
            
cs_reset_user_model(id)
            new 
CsTeams:team cs_get_user_team(id)
            if (
team == CS_TEAM_CT)
            {
                
cs_set_user_model (id"swatgirl")
                
client_print(0print_chat"Your Class Set as 'SWATGIRL'!")
            }
            else if (
team == CS_TEAM_T)
            {
                
cs_set_user_model (id"trxgirl")
                
client_print(0print_chat"Your Class Set as 'TRXGIRL'!")
            }
        }
        case 
5:
        {
            
classmenu_handler(idmenurandom_num(12))
        }
    }
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;


Tell me above code is correct or not?


All times are GMT -4. The time now is 00:29.

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