Skip to content
This repository was archived by the owner on Oct 1, 2023. It is now read-only.

Commit 4db8996

Browse files
author
Isigar
committed
mega optimalization
1 parent 46a84d0 commit 4db8996

File tree

5 files changed

+188
-121
lines changed

5 files changed

+188
-121
lines changed

client/main.lua

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ local storages = getStorages()
1313
local storageMarkers = {}
1414
local playerPos = vector3(0,0,0)
1515
local isAtJobCache = {}
16+
local nearDistanceTexts = {}
1617
local nearDistanceMarkers = {}
1718
local nearDistanceMarkerDistance = Config.NearObjectDistance
1819
local isAtMarker = false
@@ -58,6 +59,21 @@ Citizen.CreateThread(function()
5859
end
5960
end)
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+
6177
RegisterNetEvent('rcore:changePlayer')
6278
AddEventHandler('rcore:changePlayer',function(xPlayer)
6379
isAtJobCache = {}
@@ -169,17 +185,20 @@ end
169185

170186
--Check if press key
171187
Citizen.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
181199
end)
182200

201+
--Render marker
183202
Citizen.CreateThread(function()
184203
while true do
185204
Citizen.Wait(1)
@@ -217,10 +236,11 @@ Citizen.CreateThread(function()
217236
end
218237
end)
219238

239+
--Check distance marker on enter, on leave
220240
Citizen.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
251271
end)
252272

253-
-- Distance text
273+
--Update distance text
254274
AddEventHandler('rcore:updateDistanceTexts', function()
255275
distanceTexts = getDistanceTexts()
256276
end)
257277

278+
--Render distance text
258279
Citizen.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
283317
end)
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-
299319
AddEventHandler('rcore:updateStorages',function()
300320
storages = getStorages()
301321

client/model/model.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
function requestModel(modelName,cb)
2-
if type(modelName) ~= 'string' then
3-
cb(false)
4-
return
2+
if type(modelName) ~= 'number' then
3+
modelName = tonumber(modelName)
54
end
65

6+
local breaker = 0
7+
78
RequestModel(modelName)
89

910
while not HasModelLoaded(modelName) do
1011
Citizen.Wait(1)
12+
breaker = breaker + 1
13+
if breaker >= 100 then
14+
break
15+
end
1116
end
1217

13-
cb(true)
18+
if breaker >= 100 then
19+
cb(false)
20+
else
21+
cb(true)
22+
end
1423
end
1524

1625
exports('requestModel',requestModel)

client/natives/marker.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ function createDistanceMarker(type, coords, distance, cb, options)
155155
options = Config.DefaultMarkerOptions
156156
end
157157

158-
dprint('Creating marker with options')
159-
dprint(dumpTable(options))
160-
161158
local findId = findDistanceMarkersWithSameCoords(coords)
162159
if findId then
163160
if Config.Debug then

0 commit comments

Comments
 (0)