-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathcl_render.lua
84 lines (75 loc) · 2.54 KB
/
cl_render.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
-- optimizations
local vec = vec
local Wait = Citizen.Wait
local format = string.format
local RemoveBlip = RemoveBlip
local PlayerPedId = PlayerPedId
local IsHudHidden = IsHudHidden
local SetTextFont = SetTextFont
local SetTextScale = SetTextScale
local SetTextOutline = SetTextOutline
local GetEntityCoords = GetEntityCoords
local EndTextCommandDisplayText = EndTextCommandDisplayText
local BeginTextCommandDisplayText = BeginTextCommandDisplayText
local AddTextComponentSubstringPlayerName = AddTextComponentSubstringPlayerName
-- end optimizations
local nearestPostalText = ""
-- recalculate current postal
Citizen.CreateThread(function()
-- wait for postals to load
while postals == nil do Wait(1) end
local delay = math.max(config.updateDelay and tonumber(config.updateDelay) or 300, 50)
if not delay or tonumber(delay) <= 0 then
error("Invalid render delay provided, it must be a number > 0")
end
local postals = postals
local deleteDist = config.blip.distToDelete
local formatTemplate = config.text.format
local _total = #postals
while true do
local coords = GetEntityCoords(PlayerPedId())
local _nearestIndex, _nearestD
coords = vec(coords[1], coords[2])
for i = 1, _total do
local D = #(coords - postals[i][1])
if not _nearestD or D < _nearestD then
_nearestIndex = i
_nearestD = D
end
end
if pBlip and #(pBlip.p[1] - coords) < deleteDist then
TriggerEvent('chat:addMessage', {
color = { 255, 0, 0 },
args = {
'Postals',
"You've reached your postal destination!"
}
})
RemoveBlip(pBlip.hndl)
pBlip = nil
end
local _code = postals[_nearestIndex].code
nearest = { code = _code, dist = _nearestD }
nearestPostalText = format(formatTemplate, _code, _nearestD)
Wait(delay)
end
end)
-- text display thread
Citizen.CreateThread(function()
local posX = config.text.posX
local posY = config.text.posY
local _string = "STRING"
local _scale = 0.42
local _font = 4
while true do
if nearest and not IsHudHidden() then
SetTextScale(_scale, _scale)
SetTextFont(_font)
SetTextOutline()
BeginTextCommandDisplayText(_string)
AddTextComponentSubstringPlayerName(nearestPostalText)
EndTextCommandDisplayText(posX, posY)
end
Wait(0)
end
end)