Chances with percentage -
AndreiWow - 04.01.2017
How can I make two options but one have 10% chance to succes and other one has 90%?
Re: Chances with percentage -
BiosMarcel - 04.01.2017
create a random number between 0 - 9 and check if it is 0 (10%) , if yes , success
if u want for example a 40% chance, you check if it is between 0 and 3.
Might be the sexest soliution, but it would work ^^
Re: Chances with percentage -
coool - 04.01.2017
Make random of 10 numbers and in the if statement check only 1 number like this
PHP код:
new rand = random(11); //random 11 because it will only have 10 numbers.
if(rand == 1) //if the random result is 1 or what ever number you like
{
//Do some thing here
}
We get random of 10 numbers but we check if the random results 1 that means 1 out of 10
EDIT: Marcel was fast || Ok random of 11
Re: Chances with percentage -
AndreiWow - 04.01.2017
Is dis guud?
Код:
new luck = random(9), panels, doors, lights, tires;
if(luck == 0)
{
SendClientMessage(playerid, COLOR_WHITE, "Ai umflat roata prea mult si aceasta a explodat.");
}
else if(luck > 0)
{
vehicle = GetPlayerVehicleID(playerid);
GetVehicleDamageStatus(vehicle, panels, doors, lights, tires);
UpdateVehicleDamageStatus(vehicle, panels, doors, lights, 15);
}
Re: Chances with percentage -
coool - 04.01.2017
yes, but identity is not good.
Re: Chances with percentage -
BiosMarcel - 04.01.2017
Quote:
Originally Posted by coool
yes, but identity is not good.
|
indentation* #GrammarNazi
Re: Chances with percentage -
AndreiWow - 04.01.2017
Not sure what you mean, the way code is placed? It looks good in gamemode, when I pasted it here it just changed the position.
Re: Chances with percentage -
BiosMarcel - 04.01.2017
I guess you are using spaces and tabs mixed

but indentation is annoying, especially when using Pawno, because pawno is shit
Sublime for example can autoindent and convert tabs to spaces and the other way around
Re: Chances with percentage -
GoldenLion - 04.01.2017
You don't need else if there, just else.
Re: Chances with percentage -
SyS - 04.01.2017
Quote:
Originally Posted by coool
Make random of 10 numbers and in the if statement check only 1 number like this
PHP код:
new rand = random(9); //random 9 because it will only have 10 numbers.
We get random of 10 numbers but we check if the random results 1 that means 1 out of 10
EDIT: Marcel was fast
|
wrong random(9) will have only 9 numbers (0 - 8 )