Skip to content

Commit 14fca5b

Browse files
committed
Fixed Driving Activity's speed being different from the game's HUD
1 parent 3020518 commit 14fca5b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/cet/Handlers.lua

+11-7
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,23 @@ function Handlers.Driving(mod, activity)
124124
local vehicleName = GameUtils.GetVehicleName(vehicle)
125125
if vehicleName and vehicle:IsPlayerDriver() then
126126
local speedUnit = mod.speedAsMPH and "mph" or "km/h"
127-
-- 2.23693629192 is 3.6 * 0.6213711922 where the latter number is the conversion factor between km/h and mph
128-
local vehicleSpeed = math.floor(vehicle:GetCurrentSpeed() * (mod.speedAsMPH and 2.23693629192 or 3.6) + .5)
127+
local vehicleSpeed, goingForward = GameUtils.GetVehicleSpeed(vehicle)
128+
-- 1.609344 is the conversion factor from mph to km/h
129+
if not mod.speedAsMPH then vehicleSpeed = vehicleSpeed * 1.609344; end
130+
-- local vehicleSpeed = math.floor(vehicle:GetCurrentSpeed() * (mod.speedAsMPH and 2.23693629192 or 3.6) + .5)
129131
local activityVars = Handlers.SetCommonInfo(mod, activity, {
130132
vehicle = vehicleName,
131-
speed = math.abs(vehicleSpeed),
133+
speed = math.floor(vehicleSpeed + .5),
132134
speedUnit = speedUnit
133135
})
134136

135137
activity.Details = mod.Localization:GetFormatted("Driving.Details", activityVars)
136-
if vehicleSpeed > 0 then
137-
activity.State = mod.Localization:GetFormatted("Driving.State.Forward", activityVars)
138-
elseif vehicleSpeed < 0 then
139-
activity.State = mod.Localization:GetFormatted("Driving.State.Backwards", activityVars)
138+
if vehicleSpeed >= 1 then
139+
if goingForward then
140+
activity.State = mod.Localization:GetFormatted("Driving.State.Forward", activityVars)
141+
else
142+
activity.State = mod.Localization:GetFormatted("Driving.State.Backwards", activityVars)
143+
end
140144
else
141145
activity.State = mod.Localization:GetFormatted("Driving.State.Parked", activityVars)
142146
end

0 commit comments

Comments
 (0)