Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion lua/zones.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,36 @@ function zones.GetID(zone)
return table.KeyFromValue(zones.List,zone)
end

--Returns Zone ID and distance from given Pos (Takes: Class, Pos Returns: Zone ID, Distance)
function zones.FindClosest( class, pos )
if pos == nil then pos = Vector(0,0,0) end

local zone = zones.FindByClass( class )

local target = -1 --Var for current closest Zone ID
local dist = -1 --Var for distance to closest Zone

for id,data in pairs(zone) do --For each zone
for _,bound in pairs(data.bounds) do --For each bound.

local tempDist = pos:DistToSqr( bound )
if tempDist < dist or target == -1 then

target = id
dist = tempDist

end

end
end

if not (target == -1) then
return target, math.sqrt(dist)
end

return
end




Expand Down Expand Up @@ -608,4 +638,4 @@ function zones.PointInPoly(point,poly) //True if point is within a polygon.
end

return inside
end
end