Random isn't working properly :S
#1

The random isn't working properly, there are 3 chances to success and 7 to fail
the thing is that sometimes its just succeeds for a few times in a row and then fails a few times in a row
That's the code:
pawn Код:
new Chance = random(10);
            if(PlayerInfo[playerid][pGunSkill] <= 50 && Chance == 3 || Chance == 6)
            {
                AssmblingSucessLuck[playerid] = 1;
                AssmblingResult(playerid);
            }
            else if(PlayerInfo[playerid][pGunSkill] <= 50 && Chance == 1 || Chance == 2 || Chance == 4 || Chance == 5 || Chance == 7 || Chance == 8 || Chance == 9 || Chance == 10)
            {
                AssmblingFail[playerid] = 1;
                AssmblingResult(playerid);
            }
And sometimes nothing happeneds
Reply
#2

It's >random<.

If that's your case, it's randomly picking that success a few times in a row just because it's random.
Reply
#3

I don't get it O.O
Reply
#4

pawn Код:
new Chance = random(10);

if(PlayerInfo[playerid][pGunSkill] <= 50)
{
    switch(Chance)
    {
        case 3,6:
        {
            AssmblingSucessLuck[playerid] = 1;
            AssmblingResult(playerid);
        }
        case 1,2,4,5,7,8,9,10:
        {
            AssmblingFail[playerid] = 1;
            AssmblingResult(playerid);
        }
    }
}
Reply
#5

For ten it would return zero to nine, it's always from zero to your passed value minus one.
Reply
#6

I made it random(11) and used case 0-10, still the same.
Reply
#7

Quote:
Originally Posted by Maxips2
Посмотреть сообщение
I made it random(11) and used case 0-10, still the same.
I was replying just on the random thing, didn't read the code to be honest.

Freshkillas code is fine btw, fix the random part and maybe add a "default :" case, id try that anyway, add a default case with a debug print to see if it's the issue. It could be related to the custom functions or array values aswell so stick those in the prints.
Reply
#8

Nope, the default case does not activate at all
Reply
#9

Run this code (yes I blatently stole it from Freshkilla):

pawn Код:
new Chance = random(10);
printf("chance = %d", Chance);
if(PlayerInfo[playerid][pGunSkill] <= 50)
{
    print("gunskill was below or equal to 50");
    print("before switch");
    switch(Chance)
    {
        case 3,6:
        {
            print("first case");
            AssmblingSucessLuck[playerid] = 1;
            AssmblingResult(playerid);
        }
        case 0,1,2,4,5,7,8,9:
        {
            print("second case");
            AssmblingFail[playerid] = 1;
            AssmblingResult(playerid);
        }
        default: print"(the default case, this shouldn't be seen!!!");
    }
    print("after switch");
}
else print("gunskill wasn't less or equal to 50");
Run that and see what prints out.
Reply
#10

I tried that a few times:

pawn Код:
[14:06:23] gunskill was below or equal to 50
[14:06:23] before switch
[14:06:23] second case
[14:06:23] after switch
[14:06:46] gunskill was below or equal to 50
[14:06:46] before switch
[14:06:46] first case
[14:06:46] after switch
[14:07:03] gunskill was below or equal to 50
[14:07:03] before switch
[14:07:03] second case
[14:07:03] after switch
[14:07:21] gunskill was below or equal to 50
[14:07:21] before switch
[14:07:21] second case
[14:07:21] after switch
[14:07:39] gunskill was below or equal to 50
[14:07:39] before switch
[14:07:39] first case
[14:07:39] after switch
But it didn't work as it should work, according to the printing, it works fine, but in-game it doesn't work properly
so whats fucked up here?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)