Problem with choosing random Id.
#1

Hi, i have a problem, this function should go through all players online and get a random ID that is not Admin or Member id 9, and now me and my friend are testing this but its always giving me error that there is currently no active targets, and my friend is not admin or member with id 9

pawn Код:
foreach(Player, i)
{
    new count, target[MAX_PLAYERS], id;

    if(PI[i][Member] != 9 && PI[i][Admin] < 1)
    {
        count++;
    }

    if(count == 0) return SCM(playerid, ERRORCOLOR, "There is currently no active targets.");

    id = target[random(count)];

    new level = PI[id][Level];

    PI[id][Contract] = level*225;

    new str[128];
    format(str, sizeof(str), "HQ: New target - name %s - price $%d.", GetName(id), PI[id][Contract]);
    SCM(playerid, YELLOW, str);
    break;
}
Reply
#2

Don't return inside a loop unless you explicitly want to break out of it.
Reply
#3

Oh, didn't know that, thank you ! I will test this later
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)