Skip to content

Instantly share code, notes, and snippets.

@adamnejm
Last active March 11, 2022 10:10
Show Gist options
  • Save adamnejm/c45f344c6f742462f8394abb56025010 to your computer and use it in GitHub Desktop.
Save adamnejm/c45f344c6f742462f8394abb56025010 to your computer and use it in GitHub Desktop.
Starfall - Find Closest Chair in Area Example
--@name Find Closest Chair in Area Example
--@author Name
--@server
local owner, client, chip, world = owner(), player(), chip(), entity(0)
local origin = chip:getPos() -- Origin of the search
local distance = 200^2 -- Maximum distance of the chair (still 200, but square it so it's faster to compare later on)
-- Find all chairs and disregard those that are not owned by us or are farther than the specified distance
local found_ents = find.byClass("prop_vehicle_prisoner_pod", function(ent)
if ent:getOwner() ~= owner then return end
if ent:getPos():getDistanceSqr(origin) > distance then return end
return true
end)
-- Grab the closest entity to the origin (if any)
local chair = find.closest(found_ents, origin)
if chair then
chair:setColor(Color(255,0,0))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment