Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve brake and reverse light trigger logic #7

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions lights/ivl_brakereverse_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,26 @@ end
function IVL.updateBrakeReverse(vehicle)

local driver = getVehicleOccupant(vehicle)
if not driver then return false end

local reverseNew = false
local brakeNew = false
local brakeOld = IVL.getData(vehicle, "brake")
local reverseOld = IVL.getData(vehicle, "reverse")

local gear = getVehicleCurrentGear(vehicle)
local accelerateControl = getPedControlState(driver, "accelerate")
local brakeControl = getPedControlState(driver, "brake_reverse")
if not (accelerateControl and brakeControl) then
local engineState = getVehicleEngineState(vehicle)

reverseNew =
gear == 0 and (brakeControl or reverseOld)
reverseNew = engineState and gear == 0

brakeNew =
(gear == 0 and accelerateControl) or
(gear > 0 and brakeControl) or
(brakeOld and not(accelerateControl or brakeControl))
if driver then
local accelerateControl = getPedControlState(driver, "accelerate")
local brakeControl = getPedControlState(driver, "brake_reverse")

brakeNew = engineState and
(gear > 0 and brakeControl)
or (gear == 0 and accelerateControl)
end

if brakeOld ~= brakeNew then
setVehicleCustomLightsPower(vehicle, BRAKE_LIGHTS, brakeNew and 1 or 0)
setVehicleLightState(vehicle, 2, 1)
Expand Down