SA-MP Forums Archive
RAND PLAYER - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: RAND PLAYER (/showthread.php?tid=182299)



RAND PLAYER - WillyP - 09.10.2010

okay, i got ure attention.

can someone give me the code where the server gets a random person and then prints

random person = theplayer


Re: RAND PLAYER - Dime - 09.10.2010

Can i ask...Why you need that?


Re: RAND PLAYER - WillyP - 09.10.2010

Quote:
Originally Posted by oттo
Посмотреть сообщение
Can i ask...Why you need that?
when i finish the code, you will see


Re: RAND PLAYER - WillyP - 10.10.2010

any ideas?




Re: RAND PLAYER - Rac3r - 10.10.2010

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.


Re: RAND PLAYER - Hiddos - 10.10.2010

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


Re: RAND PLAYER - iggy1 - 10.10.2010

If you use foreach that has a nice random player function that works nice.
pawn Код:
Iter_Random(MyIterator);
new randomplayer = Iter_Random(Player);



Re: RAND PLAYER - WillyP - 10.10.2010

Quote:
Originally Posted by iggy1
Посмотреть сообщение
If you use foreach that has a nice random player function that works nice.
pawn Код:
Iter_Random(MyIterator);
new randomplayer = Iter_Random(Player);
Thanks, but i dont use foreach