From d3718622cf20a354c747f8a60f203f87db2f9a4f Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Fri, 6 May 2022 14:28:45 +1000 Subject: [PATCH] feat(zones): sphere zone It's just a distance check and works exactly like lib.points, with some minor API changes for consistency. --- imports/zones/client.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/imports/zones/client.lua b/imports/zones/client.lua index a074c8d..a3ec2c8 100644 --- a/imports/zones/client.lua +++ b/imports/zones/client.lua @@ -298,11 +298,18 @@ local function debugBox(self) DrawLine(self.vertices[4], self.vertices[6], 255, 0, 0, 150) end +local function debugSphere(self) + DrawMarker(28, self.coords.x, self.coords.y, self.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, self.radius, self.radius, self.radius, 255, 0, 0, 50, false, false, false, true, false, false, false) +end + local glm_polygon_contains = glm.polygon.contains local function contains(self, coords) return glm_polygon_contains(self.polygon, coords, self.thickness) end + +local function insideSphere(self, coords) + return #(self.coords - coords) < self.radius end local function getBoxVertices(self) @@ -356,5 +363,19 @@ return { zones[data.id] = data return data - end + end, + + sphere = function(data) + data.id = #zones + 1 + data.radius = (data.radius or 2) + 0.0 + data.remove = removeZone + data.contains = insideSphere + + if data.debug then + data.debug = debugSphere + end + + zones[data.id] = data + return data + end, }