Random aint random -
milanosie - 18.02.2012
Hi there, I am making a bank robbery system but for some reason it always says
You failed to rob the bank!
code for the actuall money giving:
pawn Код:
forward robbing(playerid);
public robbing(playerid)
{
new succeed = RandomEx(01, 100);
if(succeed >= 30)
{
new str[128];
new moneyer = RandomEx(01, 10000);
GivePlayerCash(playerid, moneyer);
format(str, sizeof(str), "You succesfully robbed the bank and got $%d!", moneyer);
SCM(playerid, COLOR_GREEN, str);
SetTimerEx("canrobb", 1200000, false, "i", playerid);
}
else if(succeed < 30)
{
SCM(playerid, COLOR_GREEN, "You failed at robbing the bank!");
SetTimerEx("canrobb", 1200000, false, "i", playerid);
}
return 1;
}
Re: Random aint random -
DaRkM - 18.02.2012
Have you tried with just random(100) instead of RandomEx(01,100)?
Re: Random aint random -
aRoach - 18.02.2012
pawn Код:
forward robbing( playerid );
public robbing( playerid )
{
new succed = random( 100 );
if( succeed >= 30 )
{
new str[ 128 ];
new moneyer = random( 10000 );
GivePlayerCash( playerid, moneyer );
format( str, 128, "You succesfully robbed the bank and got $%d!", moneyer );
SCM( playerid, COLOR_GREEN, str );
SetTimerEx( "canrobb", 1200000, false, "i", playerid );
}
else
{
SCM( playerid, COLOR_GREEN, "You failed at robbing the bank!" );
SetTimerEx( "canrobb", 1200000, false, "i", playerid );
}
return 1;
}
Re: Random aint random -
milanosie - 18.02.2012
Quote:
Originally Posted by aRoach
pawn Код:
forward robbing( playerid ); public robbing( playerid ) { new succed = random( 100 ); if( succeed >= 30 ) { new str[ 128 ]; new moneyer = random( 10000 ); GivePlayerCash( playerid, moneyer ); format( str, 128, "You succesfully robbed the bank and got $%d!", moneyer ); SCM( playerid, COLOR_GREEN, str ); SetTimerEx( "canrobb", 1200000, false, "i", playerid ); } else { SCM( playerid, COLOR_GREEN, "You failed at robbing the bank!" ); SetTimerEx( "canrobb", 1200000, false, "i", playerid ); } return 1; }
|
Even if that will work, what is the reason that my RandomEx wont work here?
I don't like to do something without knowing why.
Re: Random aint random -
DaRkM - 19.02.2012
I've just never seen RandomEx, really. Plus I just finished doing something with random.
Though I'm pretty newbish and only know what I've used/seen.
Re: Random aint random -
milanosie - 19.02.2012
ok, changed code but it didnt work
pawn Код:
forward robbing( playerid );
public robbing( playerid )
{
new succeed = random( 100 );
if( succeed >= 30 )
{
new str[ 128 ];
new moneyer = random( 10000 );
GivePlayerCash( playerid, moneyer );
format( str, 128, "You succesfully robbed the bank and got $%d!", moneyer );
SCM( playerid, COLOR_GREEN, str );
SetTimerEx( "canrobb", 1200000, false, "i", playerid );
}
else
{
SCM( playerid, COLOR_GREEN, "You failed at robbing the bank!" );
SetTimerEx( "canrobb", 1200000, false, "i", playerid );
}
return 1;
}
still says failed all the time
Re: Random aint random -
aRoach - 19.02.2012
You'll better do something like this:
pawn Код:
switch( random( 3 ) )
{
case ( 0 || 1 ): return true; // More than 50%
case 2: return false; // Less than 50%
}
Re: Random aint random -
milanosie - 19.02.2012
Why would that be better? It should just work what I made, I don't like going the easy way just because something doesn't work.
I want to know what I am doing wrong.
Re: Random aint random -
aRoach - 19.02.2012
Dude... The random is too big so you can have something like this: FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, SUCCES.
Do you understand ?
Re: Random aint random -
milanosie - 19.02.2012
Quote:
Originally Posted by aRoach
Dude... The random is too big so you can have something like this: FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, SUCCES.
Do you understand ?
|
No I don't