Skip to content

Commit d497444

Browse files
authored
Merge pull request #2 from LindholmDK/main
Integration of different positions.
2 parents b6741df + 546ccc5 commit d497444

File tree

4 files changed

+59
-7
lines changed

4 files changed

+59
-7
lines changed

client.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ local currentVehPlate = ""
44
local recheckCurrentVeh = 10000
55
local currentVehOwned = false
66
local lastUpdatedMileage = nil
7+
local Position = Config.Position
78

89
local function distanceCheck()
910
local ped = PlayerPedId()
1011

1112
if not IsPedInAnyVehicle(PlayerPedId(), false) then
12-
SendNUIMessage({ type = "hide" })
13+
sendToNui({ type = "hide" })
1314
return
1415
end
1516

1617
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
1718
local vehClass = GetVehicleClass(vehicle)
1819

1920
if GetPedInVehicleSeat(vehicle, -1) ~= ped or vehClass == 13 or vehClass == 14 or vehClass == 15 or vehClass == 16 or vehClass == 17 or vehClass == 21 then
20-
SendNUIMessage({ type = "hide" })
21+
sendToNui({ type = "hide" })
2122
return
2223
end
2324

@@ -48,7 +49,7 @@ local function distanceCheck()
4849
return
4950
end
5051

51-
SendNUIMessage({ type = "show", value = currentVehMileage, unit = Config.Unit })
52+
sendToNui({ type = "show", value = currentVehMileage, unit = Config.Unit, position = Position })
5253

5354
local dist = 0
5455
if IsVehicleOnAllWheels(vehicle) and not IsEntityInWater(vehicle) then
@@ -59,7 +60,7 @@ local function distanceCheck()
5960
currentVehMileage = currentVehMileage + distKm
6061
lastLocation = GetEntityCoords(vehicle)
6162
local roundedMileage = tonumber(string.format("%.1f", currentVehMileage))
62-
SendNUIMessage({ type = "show", value = roundedMileage, unit = Config.Unit })
63+
sendToNui({ type = "show", value = roundedMileage, unit = Config.Unit, position = Position })
6364

6465
if roundedMileage ~= lastUpdatedMileage then
6566
Entity(vehicle).state:set("vehicleMileage", roundedMileage)
@@ -75,4 +76,10 @@ CreateThread(function()
7576
end
7677
end)
7778

79+
function sendToNui(data)
80+
if Config.ShowMileage then
81+
SendNUIMessage(data)
82+
end
83+
end
84+
7885
exports("GetUnit", function() return Config.Unit end)

config.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Config = {}
22
Config.Framework = "auto" -- or "QBCore", "Qbox", "ESX"
3-
Config.Unit = "miles" -- or "kilometers"
3+
Config.ShowMileage = true
4+
Config.Unit = "miles" -- "miles" or "kilometers"
5+
Config.Position = "bottom-right" -- "bottom-right" or "bottom-left" or "top-right" or "top-left" or "bottom-center" or "top-center"

web/main.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ body {
1313
.odometer {
1414
display: none;
1515
gap: 7.5px;
16+
margin: 2rem;
1617
align-items: center;
1718
position: absolute;
1819
background: #212529;
1920
border: 1px solid #42484e;
2021
padding: 5px 8px;
2122
border-radius: 7px;
2223
color: white;
23-
right: 25px;
24-
bottom: 25px;
2524
transition: 0.5s ease-in-out;
2625
user-select: none;
2726
}

web/main.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,49 @@
33
const value = document.querySelector(".odometer-value");
44
const unit = document.querySelector(".odometer-unit");
55

6+
function elementPosition(position) {
7+
element = odometer;
8+
element.style.top = '';
9+
element.style.bottom = '';
10+
element.style.left = '';
11+
element.style.right = '';
12+
element.style.transform = '';
13+
14+
switch (position) {
15+
16+
case 'bottom-right':
17+
element.style.bottom = '0';
18+
element.style.right = '0';
19+
break;
20+
case 'bottom-left':
21+
element.style.bottom = '0';
22+
element.style.left = '0';
23+
break;
24+
case 'top-right':
25+
element.style.top = '0';
26+
element.style.right = '0';
27+
break;
28+
case 'top-left':
29+
element.style.top = '0';
30+
element.style.left = '0';
31+
break;
32+
case 'bottom-center':
33+
element.style.bottom = '0';
34+
element.style.left = '50%';
35+
element.style.transform = 'translateX(-50%)';
36+
break;
37+
case 'top-center':
38+
element.style.top = '0';
39+
element.style.left = '50%';
40+
element.style.transform = 'translateX(-50%)';
41+
break;
42+
default:
43+
element.style.bottom = '0';
44+
element.style.right = '0';
45+
break;
46+
}
47+
}
48+
649
window.addEventListener("message", (evt) => {
750
const { data } = evt;
851

@@ -16,6 +59,7 @@
1659
.toString()
1760
.padStart(6, "0");
1861
unit.innerHTML = data.unit === "miles" ? "MI" : "KM";
62+
elementPosition(data.position);
1963
} else if (data.type === "hide") {
2064
odometer.style.display = "none";
2165
}

0 commit comments

Comments
 (0)