RAND PLAYER
#1

okay, i got ure attention.

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

random person = theplayer
Reply
#2

Can i ask...Why you need that?
Reply
#3

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

any ideas?

Reply
#5

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.
Reply
#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
#7

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)