Random options - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Random options (
/showthread.php?tid=299026)
Random options -
HondaCBR - 23.11.2011
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?
Re: Random options -
TheArcher - 23.11.2011
use random function e.g random(30) wherever you want to put the function.
Re: Random options - Sinc - 23.11.2011
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.
Re: Random options -
HondaCBR - 23.11.2011
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.
Re: Random options - Sinc - 23.11.2011
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;
}
Re: Random options -
HondaCBR - 23.11.2011
so removeplayerfromvehicle option is that the 70% or 30% chance?
Re: Random options - Sinc - 23.11.2011
Quote:
Originally Posted by HondaCBR
so removeplayerfromvehicle option is that the 70% or 30% chance?
|
70%.