From 2ce934c41a2b0ac396b914c37e3d40fabccff504 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 13 Mar 2022 03:22:09 +0000 Subject: [PATCH] feat(imports/points): distance checks and interaction api WIP. Set callback functions when exiting and standing in range of a set point. Primary callback is called on-frame and can be used to check for key presses, distance, draw markers, etc. --- imports/points/client.lua | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 imports/points/client.lua diff --git a/imports/points/client.lua b/imports/points/client.lua new file mode 100644 index 0000000..becce52 --- /dev/null +++ b/imports/points/client.lua @@ -0,0 +1,54 @@ +local points = {} +local nearby = {} + +function points.new(coords, distance, data) + local id = #points + 1 + + local self = { + id = id, + coords = coords, + distance = distance + } + + for k, v in pairs(data) do + self[k] = v + end + + points[id] = self + + return self +end + +CreateThread(function() + while true do + local coords = GetEntityCoords(cache.ped) + Wait(300) + table.wipe(nearby) + + for i = 1, #points do + local point = points[i] + local distance = #(coords - point.coords) + + if distance <= point.distance then + nearby[#nearby + 1] = point + point.currentDistance = distance + elseif point.currentDistance then + if point.onExit then point:onExit() end + point.entered = nil + point.currentDistance = nil + end + end + end +end) + +CreateThread(function() + while true do + Wait(0) + for i = 1, #nearby do + local point = nearby[i] + if point.callback then point:callback() end + end + end +end) + +return points \ No newline at end of file