SA:MP Function - Something between random and probability? -
nGen.SoNNy - 03.10.2015
Hello fellows! Is there a way of making someting to give cash to someone but for example:
I use randomEx( min, max ); but i want that maximum value to have 1% probability of getting it or 20%.
Also i want it to use it in a farm job. Most of the time to get bags of food and sometime to have the probability to receive cash not bags...
Re: SA:MP Function - Something between random and probability? -
BroZeus - 03.10.2015
PHP код:
new bagtype = random(5) ? BAG_FOOD : BAG_CASH;//according to this code 1/5 chances of getting bag_cash
new cash = random(10) ? randomEx( 100, 200 ) : randomEx( 500, 600 );
//up here cash has 1/10(10 percent) chance of getting cash between 500-600 and 90% chance of cash between 100-200
Re: SA:MP Function - Something between random and probability? -
nGen.SoNNy - 03.10.2015
Thanks for the reply. I'm looking to make a function using probability as a var.
Can you show me an example with 1% chance of getting something? I have to use random(100) right?
Re: SA:MP Function - Something between random and probability? -
AbyssMorgan - 03.10.2015
You enter % chance of from 1 to 99
If you give more, it returns true or if you give less, it returns false
Код:
bool:IsDropAllow(chance){
if(chance <= 0) return false;
if(chance >= 100) return true;
new los = random(100), drop = (0);
for(new i = 0;i <= chance-1;i++){
if(los == i){
drop = (1);
break;
}
}
if(drop == 1) return true;
return false;
}
Re: SA:MP Function - Something between random and probability? -
BroZeus - 03.10.2015
You can do it in the following method
PHP код:
if(!random(100))
{
//the thing with 1% chance goes HERE
}
else
{
//the thing with 99% chance goes HERE
}
Or use it in the format i gave in last post, and yes use random(100) there if you want in that format.
Re: SA:MP Function - Something between random and probability? -
Kevln - 03.10.2015
I'd do it like this:
pawn Код:
switch(random(100))
{
case 0: // 1 percent chance
default: // 99 percent chance
}
Another example of 5 & 95 percent:
pawn Код:
switch(random(100))
{
case 0..4: // 5 percent chance
default: // 95 percent chance
}
Re: SA:MP Function - Something between random and probability? -
nGen.SoNNy - 04.10.2015
Код:
stock RandomChange( most, rare, probability )
{
new NMB = random( probability ) ? most : rare;
return NMB;
}
RandomChange( 5, randomEx(200, 500), 20 );