Get a random player in range of position using loops
#8

pawn Код:
stock GetRandomPlayerInRange(Float:x, Float:y, Float:z, Float:range)
{
    // Define a new iterator with a size of MAX_PLAYERS (all players in the server could potentially be in range of the point)
    new Iterator:PlayersNearPoint<MAX_PLAYERS>;

    // Loop through all players in the server
    foreach(new p : Player)
    {
        // If the current player is in range of the point
        if(IsPlayerInRangeOfPoint(p, range, x, y, z)
        {
            // Then add their id (p) to the iterator (PlayersNearPoint)
            Iter_Add(PlayersNearPoint, p);
        }
    }

    // If Iter_Count(PlayersNearPoint) is 0, then return INVALID_PLAYER_ID. If it isn't 0, then return a random value from the iterator
    return (Iter_Count(PlayersNearPoint) == 0) ? INVALID_PLAYER_ID : Iter_Random(PlayersNearPoint);
}
You'll need to download YSI for it to work. I've documented the code so you can understand it easier.
Reply


Messages In This Thread
Get a random player in range of position using loops - by iJumbo - 04.09.2013, 20:34
Re: Good way to - by Vince - 04.09.2013, 22:32
Re: Good way to - by iJumbo - 04.09.2013, 23:00
Re: Good way to - by Kar - 05.09.2013, 02:00
Re: Good way to - by CyNiC - 05.09.2013, 03:48
Re: Get a random player in range of position using loops - by Pottus - 05.09.2013, 04:48
Re: Get a random player in range of position using loops - by iJumbo - 05.09.2013, 10:01
Re: Get a random player in range of position using loops - by CaveDweller - 05.09.2013, 11:24
Re: Get a random player in range of position using loops - by iJumbo - 05.09.2013, 11:30
Re: Get a random player in range of position using loops - by CaveDweller - 05.09.2013, 11:31

Forum Jump:


Users browsing this thread: 4 Guest(s)