Random aint random
#1

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

Have you tried with just random(100) instead of RandomEx(01,100)?
Reply
#3

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

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

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

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

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

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

Dude... The random is too big so you can have something like this: FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, SUCCES.

Do you understand ?
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)