05.09.2013, 11:24
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);
}