forked from DevBlocky/nearest-postal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcl_commands.lua
69 lines (61 loc) · 1.89 KB
/
cl_commands.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
-- optimizations
local ipairs = ipairs
local upper = string.upper
local format = string.format
-- end optimizations
---
--- [[ Nearest Postal Commands ]] ---
---
TriggerEvent('chat:addSuggestion', '/postal', 'Set the GPS to a specific postal',
{ { name = 'Postal Code', help = 'The postal code you would like to go to' } })
RegisterCommand('postal', function(_, args)
if #args < 1 then
if pBlip then
RemoveBlip(pBlip.hndl)
pBlip = nil
TriggerEvent('chat:addMessage', {
color = { 255, 0, 0 },
args = {
'Postals',
config.blip.deleteText
}
})
end
return
end
local userPostal = upper(args[1])
local foundPostal
for _, p in ipairs(postals) do
if upper(p.code) == userPostal then
foundPostal = p
break
end
end
if foundPostal then
if pBlip then RemoveBlip(pBlip.hndl) end
local blip = AddBlipForCoord(foundPostal[1][1], foundPostal[1][2], 0.0)
pBlip = { hndl = blip, p = foundPostal }
SetBlipRoute(blip, true)
SetBlipSprite(blip, config.blip.sprite)
SetBlipColour(blip, config.blip.color)
SetBlipRouteColour(blip, config.blip.color)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName(format(config.blip.blipText, pBlip.p.code))
EndTextCommandSetBlipName(blip)
TriggerEvent('chat:addMessage', {
color = { 255, 0, 0 },
args = {
'Postals',
format(config.blip.drawRouteText, foundPostal.code)
}
})
else
TriggerEvent('chat:addMessage', {
color = { 255, 0, 0 },
args = {
'Postals',
config.blip.notExistText
}
})
end
end)