Last active
March 11, 2022 10:10
-
-
Save adamnejm/c45f344c6f742462f8394abb56025010 to your computer and use it in GitHub Desktop.
Starfall - Find Closest Chair in Area Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--@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