Random options
#1

I want to have random options, for example you type in /jump
and there is 30% chance of getting option one and 70% chance of getting option 2, how can I do that?
Reply
#2

use random function e.g random(30) wherever you want to put the function.
Reply
#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
#4

So where can I store the options? lets say option 1 will send you a message and option 2 will remove you from vehicle. Could you please add that.
Reply
#5

Quote:
Originally Posted by HondaCBR
Посмотреть сообщение
So where can I store the options? lets say option 1 will send you a message and option 2 will remove you from vehicle. Could you please add that.
pawn Код:
if (strcmp("/jump", cmdtext, true, 5) == 0)
    {
        new rand = random(9);
        if(rand < 7)
        {
            new vehicle = GetPlayerVehicleID(playerid);
            if(IsPlayerInVehicle(playerid, vehicle))
                RemovePlayerFromVehicle(playerid);
        }
        else SendClientMessage(playerid, -1, "Message");
        return 1;
    }
Reply
#6

so removeplayerfromvehicle option is that the 70% or 30% chance?
Reply
#7

Quote:
Originally Posted by HondaCBR
Посмотреть сообщение
so removeplayerfromvehicle option is that the 70% or 30% chance?
70%.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)