26.11.2011, 17:41
How would I go about getting a random player using ID's?
stock GetRandomPlayer()
{
new
playerid = random(MAX_PLAYERS);
if (!IsPlayerConnected(playerid)) GetRandomPlayer(); // call the function again - recursion
else return playerid;
}
#define MAX_PLAY 32 // Slots on your server
stock RandPlayer() // Will return a random player ID
{
new player[MAX_PLAY]; // The ID assigned to each slot
new plyrs; // Possible random players
for(new i=0; i<MAX_PLAY; i++)
{
if(IsPlayerConnected(i))
{
player[plyrs] = i;
plyrs++;
}
}
if(!plyrs) return -1; // If there aren't any players return -1
new rand;
rand = random(plyrs);
return player[rand];
}
new pRand = random(MAX_PLAYERS);
SendClientMessage(pRand,0xFFFFFF,"Congratulation, you have been RANDOMLY elected to be the server president!");
while(!IsPlayerConnected(randplayer)) randplayer = random(MAX_PLAYERS);
#if defined MAX_PLAYERS
#undef MAX_PLAYERS
#define MAX_PLAYERS 30
#endif