RAND PLAYER
#6

Quote:
Originally Posted by Rac3r
Посмотреть сообщение
On this forum I'm sure there's a RandomID() function.

I'll try rip up a bit of code.
pawn Код:
GetRandomID()
{
    new TotalPlayers[MAX_PLAYERS];
    new TotalFound;
    for(new i; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            TotalPlayers[ TotalFound ] = i;
            TotalFound++;
        }
    }
    if(TotalFound == 1)
    {
        printf("id found : %d", TotalPlayers[0]);
    }
    else
    {
        if(TotalFound > 1)
        {
            new a = random(TotalFound);
            printf("id found : %d", TotalPlayers[ a ]);
        }
    }
}
Untested, took one minute to write. Hopefully it helps.
Or simple:

pawn Код:
new r = -1;
while(r == -1)
{
  r = random(MAX_PLAYERS);
  if(!IsPlayerConnected(r)) r = -1;
}
Untested either
Reply


Messages In This Thread
RAND PLAYER - by WillyP - 09.10.2010, 23:44
Re: RAND PLAYER - by Dime - 09.10.2010, 23:53
Re: RAND PLAYER - by WillyP - 09.10.2010, 23:57
Re: RAND PLAYER - by WillyP - 10.10.2010, 10:28
Re: RAND PLAYER - by Rac3r - 10.10.2010, 10:40
Re: RAND PLAYER - by Hiddos - 10.10.2010, 11:09
Re: RAND PLAYER - by iggy1 - 10.10.2010, 11:17
Re: RAND PLAYER - by WillyP - 10.10.2010, 11:24

Forum Jump:


Users browsing this thread: 4 Guest(s)