Find random Player

Started by Retard, Feb 13, 2018, 10:16 AM

Previous topic - Next topic

Retard

The following function can help you find a random player.You can use this for minigames
function onPlayerCommand( player, cmd, text )
{
else if ( cmd == "rand" )
{
local RandPlayerID = FindRandPlayer();
print ( "Random PlayerID " + RandPlayerID );
}
}


function FindRandPlayer()
{
local
    MAX_PLAYERS = 50,
    count = 0,
    buffer = "",
    param;

    for(local i = 0; i < MAX_PLAYERS; i++)
    {
      if ( FindPlayer( i ) )
{
buffer = buffer + " " + i;
count++;
}
    }

param = split(buffer, " ");
return param[ rand() % count ];
}