-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
87 lines (67 loc) · 1.77 KB
/
Copy pathclient.lua
File metadata and controls
87 lines (67 loc) · 1.77 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
local SPEED_MULTIPLIER = 3.6
local SPEED_LABEL = 'KM/H'
local UPDATE_INTERVAL = 50
local IDLE_INTERVAL = 500
local hudVisible = false
local lastSpeed = -1
local lastRpm = -1
local missionTextActive = false
local function updateHud(speed, rpm)
if speed == lastSpeed and rpm == lastRpm then
return
end
lastSpeed = speed
lastRpm = rpm
hudVisible = true
SendNUIMessage({
action = 'update',
speed = speed,
rpm = rpm,
unit = SPEED_LABEL
})
end
local function hideHud()
if not hudVisible then
return
end
hudVisible = false
lastSpeed = -1
lastRpm = -1
SendNUIMessage({ action = 'hide' })
end
local function setMissionTextActive(active)
if missionTextActive == active then
return
end
missionTextActive = active
SendNUIMessage({
action = 'missionText',
active = active
})
end
AddEventHandler('speedometer:MissionTextActive', function()
setMissionTextActive(true)
end)
AddEventHandler('speedometer:MissionTextInactive', function()
setMissionTextActive(false)
end)
Citizen.CreateThread(function()
while true do
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn(ped, false)
while vehicle ~= 0 do
if IsPauseMenuActive() then
hideHud()
else
local speed = math.floor(GetEntitySpeed(vehicle) * SPEED_MULTIPLIER + 0.5)
local rpm = math.floor(GetVehicleCurrentRpm(vehicle) * 100 + 0.5) / 100
updateHud(speed, rpm)
end
Citizen.Wait(UPDATE_INTERVAL)
ped = PlayerPedId()
vehicle = GetVehiclePedIsIn(ped, false)
end
hideHud()
Citizen.Wait(IDLE_INTERVAL)
end
end)