Repository navigation
Expand file tree
/
Copy pathclient.lua
More file actions
122 lines (107 loc) · 5.29 KB
/
Copy pathclient.lua
File metadata and controls
122 lines (107 loc) · 5.29 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
lib.locale()
local Radar = lib.load('config')
local showRadar = (not GetResourceKvpInt('showRadar') and Radar.defaultShowingRadar or false) or (GetResourceKvpInt('showRadar') == 1 and true or false)
local speedMultiplier = Radar.speedType == "MPH" and 2.23694 or 3.6
local showingRadar = false
local radarLocked = false
---@param message string
---@param type string
notify = function(message, type)
lib.notify({ description = message, type = type })
end
RegisterNuiCallback('hideFrame', function(data, cb)
SetNuiFocus(false, false)
cb(true)
end)
RegisterNuiCallback('saveRadarPosition', function(data, cb)
SetResourceKvp('radarPosition', json.encode({ x = data.x or 1580, y = data.y or 860 }))
cb(true)
end)
RegisterCommand(Radar.changeRadarPositionCommand, function()
if showingRadar then
SetNuiFocus(true, true)
end
end, false)
RegisterCommand(Radar.lockRadarCommand, function()
if showingRadar then
radarLocked = (not radarLocked)
SendNUIMessage({ action = 'updateRadarLocked', data = radarLocked })
PlaySoundFrontend( -1, "Beep_Red", "DLC_HEIST_HACKING_SNAKE_SOUNDS", true)
notify(radarLocked and locale('locked') or locale('unlocked'), 'info')
end
end, false)
RegisterKeyMapping(Radar.lockRadarCommand, locale('lockRadarKeybind'), 'KEYBOARD', Radar.lockRadarKeybind)
RegisterCommand(Radar.showRadarCommand, function()
if IsPedInAnyVehicle(cache.ped, false) and (GetVehicleClass(GetVehiclePedIsIn(cache.ped, false)) == 18) then
showRadar = (not showRadar)
SetResourceKvpInt('showRadar', showRadar and 1 or 0)
notify(showRadar and locale('enabled') or locale('disabled'), 'info')
end
end, false)
RegisterKeyMapping(Radar.showRadarCommand, locale('toggleRadarKeybind'), 'KEYBOARD', Radar.showRadarKeybind)
local function vehicleLoop()
Citizen.CreateThread(function()
while cache.vehicle do
if (not showingRadar) and showRadar then
local position = json.decode(GetResourceKvpString('radarPosition')) or { x = 1580, y = 860 }
SendNUIMessage({ action = 'setVisibleRadar', data = true })
SendNUIMessage({ action = 'setLocale', data = json.decode(LoadResourceFile(cache.resource, ('locales/%s.json'):format(Radar.locale or 'en'))) })
SendNUIMessage({ action = 'setRadarPosition', data = { x = position.x, y = position.y } })
showingRadar = true
elseif showingRadar and (not showRadar) then
SendNUIMessage({ action = 'setVisibleRadar', data = false })
showingRadar = false
end
if showingRadar then
if IsPauseMenuActive() then
SendNUIMessage({ action = 'setVisibleRadar', data = false })
showingRadar = false
else
local position = json.decode(GetResourceKvpString('radarPosition')) or { x = 1580, y = 860 }
SendNUIMessage({ action = 'setVisibleRadar', data = true })
SendNUIMessage({ action = 'setLocale', data = json.decode(LoadResourceFile(cache.resource, ('locales/%s.json'):format(Radar.locale or 'en'))) })
SendNUIMessage({ action = 'setRadarPosition', data = { x = position.x, y = position.y } })
showingRadar = true
end
end
if showingRadar and (not radarLocked) then
local veh = GetVehiclePedIsIn(cache.ped, false)
local coordA = GetOffsetFromEntityInWorldCoords(veh, 0.0, 1.0, 1.0)
local coordB = GetOffsetFromEntityInWorldCoords(veh, 0.0, 105.0, 0.0)
local frontcar = StartShapeTestCapsule(coordA, coordB, 6.0, 10, veh, 7)
local a, b, c, d, e = GetShapeTestResult(frontcar)
if IsEntityAVehicle(e) then
SendNUIMessage({ action = 'updateFrontCar', data = { speed = math.ceil(GetEntitySpeed(e) * speedMultiplier), plate = GetVehicleNumberPlateText(e) } })
end
local bcoordB = GetOffsetFromEntityInWorldCoords(veh, 0.0, -105.0, 0.0)
local rearcar = StartShapeTestCapsule(coordA, bcoordB, 3.0, 10, veh, 7)
local f, g, h, i, j = GetShapeTestResult(rearcar)
if IsEntityAVehicle(j) then
SendNUIMessage({ action = 'updateRearCar', data = { speed = math.ceil(GetEntitySpeed(j) * speedMultiplier), plate = GetVehicleNumberPlateText(j) } })
end
end
Wait(Radar.radarUpdateInterval)
end
if showingRadar then
SendNUIMessage({ action = 'setVisibleRadar', data = false })
showingRadar = false
end
end)
end
lib.onCache('vehicle', function(veh)
if veh then
if GetVehicleClass(veh) == 18 then
vehicleLoop()
end
end
end)
Citizen.CreateThread(function() -- Support for restarting the script while being in a vehicle
if LocalPlayer.state.isLoggedIn then
if cache.vehicle then
Wait(1000) -- Wait for NUI to be ready
if GetVehicleClass(cache.vehicle) == 18 then
vehicleLoop()
end
end
end
end)