-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
64 lines (56 loc) · 1.97 KB
/
Copy pathclient.lua
File metadata and controls
64 lines (56 loc) · 1.97 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
local speedometerVisible = true
local inVehicle = false
local config = {
useImperial = true,
passengerCanSee = false,
hideKey = 'H'
}
function round(num, numDecimalPlaces)
return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
end
function getVehicleSpeed()
local player = PlayerPedId()
local vehicle = GetVehiclePedIsIn(player, false)
local speed = GetEntitySpeed(vehicle)
if config.useImperial then
return round(speed * 2.236936, 0) -- Convert to MPH
else
return round(speed * 3.6, 0) -- Convert to KPH
end
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(50)
local player = PlayerPedId()
if IsPedInAnyVehicle(player, false) then
if not inVehicle then
inVehicle = true
if speedometerVisible then
SendNUIMessage({type = "showSpeedometer", blur = "in"})
end
end
if (GetPedInVehicleSeat(GetVehiclePedIsIn(player, false), -1) == player) or config.passengerCanSee then
local speed = getVehicleSpeed()
SendNUIMessage({
type = "updateSpeed",
speed = speed,
unit = config.useImperial and "MPH" or "KPH"
})
end
else
if inVehicle then
inVehicle = false
SendNUIMessage({type = "showSpeedometer", blur = "out"})
end
end
end
end)
RegisterCommand('toggleSpeedometer', function()
speedometerVisible = not speedometerVisible
if speedometerVisible and inVehicle then
SendNUIMessage({type = "showSpeedometer", blur = "in"})
else
SendNUIMessage({type = "showSpeedometer", blur = "out"})
end
end)
RegisterKeyMapping('toggleSpeedometer', 'Toggle Speedometer', 'keyboard', config.hideKey)