SA:MP Function - Something between random and probability?
#1

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...
Reply
#2

PHP код:
new bagtype random(5) ? BAG_FOOD BAG_CASH;//according to this code 1/5 chances of getting bag_cash

new cash random(10) ? randomEx100200 ) : randomEx500600 );
//up here cash has 1/10(10 percent) chance of getting cash between 500-600 and 90% chance of cash between 100-200 
Reply
#3

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?
Reply
#4

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;
}
Reply
#5

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.
Reply
#6

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
}
Reply
#7

Код:
stock RandomChange( most, rare, probability )
{
    new NMB = random( probability ) ? most : rare;
	return NMB;
}
RandomChange( 5, randomEx(200, 500), 20 );
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)