@@ -13,6 +13,7 @@ local storages = getStorages()
1313local storageMarkers = {}
1414local playerPos = vector3 (0 ,0 ,0 )
1515local isAtJobCache = {}
16+ local nearDistanceTexts = {}
1617local nearDistanceMarkers = {}
1718local nearDistanceMarkerDistance = Config .NearObjectDistance
1819local isAtMarker = false
@@ -58,6 +59,21 @@ Citizen.CreateThread(function()
5859 end
5960end )
6061
62+ Citizen .CreateThread (function ()
63+ while true do
64+ Citizen .Wait (Config .CheckPlayerPosition )
65+ local ped = PlayerPedId ()
66+ playerPos = GetEntityCoords (ped )
67+ nearDistanceTexts = {}
68+ for k , v in pairs (distanceTexts ) do
69+ local dist = # (playerPos - vector3 (v .coords .x , v .coords .y , v .coords .z ))
70+ if dist <= Config .NearObjectDistance then
71+ nearDistanceTexts [k ] = v
72+ end
73+ end
74+ end
75+ end )
76+
6177RegisterNetEvent (' rcore:changePlayer' )
6278AddEventHandler (' rcore:changePlayer' ,function (xPlayer )
6379 isAtJobCache = {}
@@ -169,17 +185,20 @@ end
169185
170186-- Check if press key
171187Citizen .CreateThread (function ()
188+ local keys = getKeys ()
172189 while true do
173190 Citizen .Wait (0 )
174- for _ , key in pairs (getKeys ()) do
175- if IsControlJustReleased (0 ,key ) then
176- onKey (key )
177- TriggerEvent (' rcore:onKey' ,key )
191+
192+ for i = 1 ,# keys do
193+ if IsControlJustReleased (0 , keys [i ]) then
194+ onKey (keys [i ])
195+ TriggerEvent (' rcore:onKey' , keys [i ])
178196 end
179197 end
180198 end
181199end )
182200
201+ -- Render marker
183202Citizen .CreateThread (function ()
184203 while true do
185204 Citizen .Wait (1 )
@@ -217,10 +236,11 @@ Citizen.CreateThread(function()
217236 end
218237end )
219238
239+ -- Check distance marker on enter, on leave
220240Citizen .CreateThread (function ()
221241 while true do
222242 Citizen .Wait (150 )
223- for id , v in pairs (distanceMarkers ) do
243+ for id , v in pairs (nearDistanceMarkers ) do
224244 if isAtJobFunc (id ,v ) then
225245 if not playerPos then
226246 playerPos = GetEntityCoords (PlayerPedId ())
@@ -250,19 +270,33 @@ Citizen.CreateThread(function()
250270 end
251271end )
252272
253- -- Distance text
273+ -- Update distance text
254274AddEventHandler (' rcore:updateDistanceTexts' , function ()
255275 distanceTexts = getDistanceTexts ()
256276end )
257277
278+ -- Render distance text
258279Citizen .CreateThread (function ()
259280 while true do
260- Citizen .Wait (0 )
261- for id , v in pairs (distanceTexts ) do
281+ Citizen .Wait (1 )
282+ for id , v in pairs (nearDistanceMarkers ) do
283+ if isAtJobFunc (id ,v ) then
284+ local dist = # (playerPos - vector3 (v .coords .x , v .coords .y , v .coords .z ))
285+ if dist < v .distance then
286+ draw3DText (v .coords , v .text , v .options )
287+ end
288+ end
289+ end
290+ end
291+ end )
292+
293+ -- Call distance text on enter, on leave
294+ Citizen .CreateThread (function ()
295+ while true do
296+ Citizen .Wait (150 )
297+ for id , v in pairs (nearDistanceTexts ) do
262298 local dist = # (playerPos - vector3 (v .coords .x , v .coords .y , v .coords .z ))
263299 if dist < v .distance then
264- draw3DText (v .coords , v .text , v .options )
265-
266300 if dist <= (v .options .actionDistance + (v .options .actionDistance / 4 )) then
267301 isAtText = id
268302 callActionOnce (string.format (' text-%s-onEnter' ,id ))
@@ -282,20 +316,6 @@ Citizen.CreateThread(function()
282316 end
283317end )
284318
285- -- Text
286- AddEventHandler (' rcore:updateTexts' , function ()
287- texts = getTexts ()
288- end )
289-
290- Citizen .CreateThread (function ()
291- while true do
292- Citizen .Wait (0 )
293- for _ , v in pairs (texts ) do
294- draw3DText (v .coords , v .text , v .options )
295- end
296- end
297- end )
298-
299319AddEventHandler (' rcore:updateStorages' ,function ()
300320 storages = getStorages ()
301321
0 commit comments