Random not working properly
#4

pawn Код:
enum e_LigoninesLovos
{
    bool: LL_taken,
    Float: LL_pos[4]
};

new LigoninesLovos[][e_LigoninesLovos] =
{
    {false, {-197.1666,-1759.9664,676.4661,272.1911}},
    {false, {-200.7865,-1763.9344,676.4661,271.3739}},
    {false, {-196.8234,-1771.7848,676.4661,357.3743}},
    {false, {-197.1552,-1767.9449,676.4661,4.5810}},
    {false, {-197.2890,-1763.8800,676.4661,357.3743}}
};

// wherever you want to set the player's position:
new bool: full = true;
for (new i; i != sizeof (LigoninesLovos); ++i)
{
    if (!LigoninesLovos[i][LL_taken])
    {
        full = false;
        break;
    }
}

if (full)
{
    // all beds are taken..
}
else
{
    new Random, count;
    for (;;)
    {
        Random = random(sizeof (LigoninesLovos));
        if (LigoninesLovos[Random][LL_taken]) continue;
        SetPlayerPos(playerid, LigoninesLovos[Random][LL_pos][0], LigoninesLovos[Random][LL_pos][1], LigoninesLovos[Random][LL_pos][2]);
        SetPlayerFacingAngle(playerid, LigoninesLovos[Random][LL_pos][3]);
        LigoninesLovos[Random][LL_taken] = true;
        if (++count == sizeof (LigoninesLovos)) break;
    }
}
Don't forget to reset it (to false) when the bed is empty. If the bed is taken, it finds an empty one. In case all of them are taken, do whatever you want (in "if (full)" statement).
Reply


Messages In This Thread
Random not working properly - by Dziugsas - 23.06.2014, 21:22
Re: Random not working properly - by GeekSiMo - 23.06.2014, 21:27
Re: Random not working properly - by Dziugsas - 23.06.2014, 21:28
Re: Random not working properly - by Konstantinos - 23.06.2014, 21:50
Re: Random not working properly - by Dziugsas - 23.06.2014, 22:07
Re: Random not working properly - by Dziugsas - 23.06.2014, 22:10

Forum Jump:


Users browsing this thread: 1 Guest(s)