07.05.2012, 17:57
(
Последний раз редактировалось Kitten; 24.11.2013 в 06:26.
)
Solved
stock RandomPlayer(players[],size=MAX_PLAYERS)
{
new random=random(strlen(players))
new result=players[random]-1; //We subtract one here to equilize for EOS being 0, explained later
strdel(players,random,random+1);
return result;
}
//Create your array
new playerarray[MAX_PLAYERS+1]; //+1 because we're treating it as a string, and strings have an 'EOS'
//Create an index and add the players to the array
new idx;
for(new playerid;playerid<MAX_PLAYERS;playerid++)
{
if(IsPlayerConnected(playerid)&&!IsPlayerNPC(playerid)) //Only want actual players who are online
{
playerarray[idx]=playerid+1; //Plus 1 because EOS is 0, and player 0 is an ID
idx++;
}
}
//Now your array is full of online players
//Now use the function
printf("Player Selected: %d",RandomPlayer(playerarray));
printf("Player Selected: %d",RandomPlayer(playerarray));
printf("Player Selected: %d",RandomPlayer(playerarray));
Player Selected: 0 Player Selected: 6 Player Selected: 13