Choose a random player ?
#1

Solved
Reply
#2

Thought of starting to use foreach?

pawn Код:
new randomplayer = Itter_Random(Player);
Reply
#3

Try this:

pawn Код:
public RandomPlayer()
{
    for(new i=0; i != MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            new rand = random(2);
            if(rand == 1)
            {
                SendClientMessage(i, 0xFAFFFF0, "You have been randomly chosen!");
                break;
            }
            else continue;
        }
    }
    return 1;
}
Reply
#4

Solved
Reply
#5

I wouldn't use that, that'll end in the first 5-10 players every time.

This could work, I'm half asleep and wrote this in this quick reply box so anything can happen:
pawn Код:
new playaz[MAX_PLAYERS], count;

for(new i; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        playaz[count] = i;
        count++;
    }
}

new rand = playaz[random(count)];
Reply
#6

thanks ill try it
Reply
#7

Solved
Reply
#8

pawn Код:
stock GetRandomPlayer()
{
    new playaz[MAX_PLAYERS], count;

    for(new i; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            playaz[count] = i;
            count++;
        }
    }

    return playaz[random(count)];
}
Reply
#9

Solved
Reply
#10

Of course not.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)