• Finding closest player inside sphere
    1 replies, posted
I need to find the closest player to a vector position that is within 400 units of that position. I looked and found ents.FindByClass() and ents.FindInSphere() but I dont know how to sort the lists.
[lua]local pos = Vector( 0, 0, 0 ) local closestdistance, closestplayer, dist for _, ply in ipairs( player.GetAll() ) do dist = ply:GetPos():Distance( pos ) if ( !closestdistance or dist < closestdistance ) then closestdistance = dist closestplayer = ply end end[/lua]
Sorry, you need to Log In to post a reply to this thread.