Skip to content
105 changes: 64 additions & 41 deletions [core]/es_extended/client/imports/point.lua
Original file line number Diff line number Diff line change
@@ -1,53 +1,76 @@
local Point = ESX.Class()

local nearby, loop = {}
local points, nearbyPoints, mainThread, nearbyThread = {}, {}, false, false

local function UnloadPoint(handle, point)
nearbyPoints[handle] = nil
if point.leave then
point:leave()
end
if #nearbyPoints == 0 then
nearbyThread = false
end
end

function Point:constructor(properties)
self.coords = properties.coords
self.hidden = properties.hidden
self.enter = properties.enter
self.leave = properties.leave
self.inside = properties.inside
self.handle = ESX.CreatePointInternal(properties.coords, properties.distance, properties.hidden, function()
nearby[self.handle] = self
if self.enter then
self:enter()
end
if not loop then
loop = true
CreateThread(function()
while loop do
local coords = GetEntityCoords(ESX.PlayerData.ped)
for handle, point in pairs(nearby) do
if point.inside then
point:inside(#(coords - point.coords))
end
end
Wait()
end
end)
end
end, function()
nearby[self.handle] = nil
if self.leave then
self:leave()
end
if #nearby == 0 then
loop = false
end
end)
self.coords = properties.coords
self.distance = properties.distance
self.hidden = properties.hidden
self.enter = properties.enter
self.leave = properties.leave
self.inside = properties.inside
self.handle = ESX.Table.SizeOf(points) + 1
points[self.handle] = self
if not mainThread then
mainThread = true
CreateThread(function()
while mainThread do Wait(500)
local coords = GetEntityCoords(ESX.PlayerData.ped)
for handle, point in pairs(points) do
if not point.hidden and #(coords - point.coords) <= point.distance then
if not nearbyPoints[handle] then
nearbyPoints[handle] = point
if point.enter then
point:enter()
end
if not nearbyThread then
nearbyThread = true
CreateThread(function()
while nearbyThread do Wait(0)
coords = GetEntityCoords(ESX.PlayerData.ped)
for _, nearbyPoint in pairs(nearbyPoints) do
if nearbyPoint.inside then
nearbyPoint:inside(#(coords - nearbyPoint.coords))
end
end
end
end)
end
end
elseif nearbyPoints[handle] then
UnloadPoint(handle, point)
end
end
end
end)
end
end

function Point:delete()
ESX.RemovePointInternal(self.handle)
points[self.handle] = nil
if #points == 0 then
mainThread = false
end
if nearbyPoints[self.handle] then
UnloadPoint(self.handle, self)
end
end

function Point:toggle(hidden)
if hidden == nil then
hidden = not self.hidden
end
self.hidden = hidden
ESX.HidePointInternal(self.handle, hidden)
if hidden == nil then
hidden = not self.hidden
end
self.hidden = hidden
end

return Point
return Point
1 change: 0 additions & 1 deletion [core]/es_extended/client/modules/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ RegisterNetEvent("esx:playerLoaded", function(xPlayer, _, skin)
end

Actions:Init()
StartPointsLoop()
StartServerSyncLoops()
NetworkSetLocalPlayerSyncLookAt(true)
end)
Expand Down
54 changes: 0 additions & 54 deletions [core]/es_extended/client/modules/points.lua

This file was deleted.

1 change: 0 additions & 1 deletion [core]/es_extended/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ client_scripts {
'client/modules/wrapper.lua',
'client/modules/callback.lua',
'client/modules/adjustments.lua',
'client/modules/points.lua',

'client/modules/events.lua',

Expand Down
Loading