SA-MP Forums Archive
Problem with choosing random Id. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem with choosing random Id. (/showthread.php?tid=605645)



Problem with choosing random Id. - ShoortyFl - 22.04.2016

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;
}



Re: Problem with choosing random Id. - Vince - 22.04.2016

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


Re: Problem with choosing random Id. - ShoortyFl - 22.04.2016

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