Random options
#3

The random function requires a max value input of an integer.
Код:
7/10 = 70% 
3/10 = 30%.
pawn Код:
main()
{
    new
        rand = random(9)
    ;
    printf("%d", rand);
    if(rand < 7)
        print("option 2");
    else print("option 1");
}
An example of how your command might work. The random function evaluates the condition (9) meaning selective values of 0-9 which are actually 10 numbers. We then output the random selected number to the console. The if expression then checks if the value of rand is less than 7 (as the random selection begins at 0). If true it will output option 2, otherwise option is outputted.

pawn Код:
if (strcmp("/jump", cmdtext, true, 5) == 0)
    {
        new rand = random(9);
        if(rand < 7) SendClientMessage(playerid, -1, "Option 2");
        else SendClientMessage(playerid, -1, "Option 1");
        return 1;
    }
Test command.
Reply


Messages In This Thread
Random options - by HondaCBR - 23.11.2011, 20:19
Re: Random options - by TheArcher - 23.11.2011, 20:22
Re: Random options - by Sinc - 23.11.2011, 20:45
Re: Random options - by HondaCBR - 23.11.2011, 20:47
Re: Random options - by Sinc - 23.11.2011, 20:51
Re: Random options - by HondaCBR - 23.11.2011, 21:09
Re: Random options - by Sinc - 23.11.2011, 21:14

Forum Jump:


Users browsing this thread: 1 Guest(s)