From 4abc10f436673f68470f0eb677dc8dd9378bd1df Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 16 May 2024 15:40:34 +0100 Subject: [PATCH 1/4] Improve brake and reverse light trigger logic ivl_brakereverse_client updated --- lights/ivl_brakereverse_client.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lights/ivl_brakereverse_client.lua b/lights/ivl_brakereverse_client.lua index 1a1e662..c00765f 100644 --- a/lights/ivl_brakereverse_client.lua +++ b/lights/ivl_brakereverse_client.lua @@ -22,7 +22,6 @@ end function IVL.updateBrakeReverse(vehicle) local driver = getVehicleOccupant(vehicle) - if not driver then return false end local reverseNew = false local brakeNew = false @@ -30,17 +29,18 @@ function IVL.updateBrakeReverse(vehicle) 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 - reverseNew = - gear == 0 and (brakeControl or reverseOld) + -- Turn on reverse light if in reverse gear + reverseNew = (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") + + -- Turn on braking lights if in a forwards gear and brake key is pressed + -- or if in reverse gear and accelerate key is pressed + brakeNew = (gear > 0 and brakeControl) + or (gear == 0 and accelerateControl) end if brakeOld ~= brakeNew then From dc8319ab7580b7092243d8a57c921eb513a3760f Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 16 May 2024 16:00:15 +0100 Subject: [PATCH 2/4] Only show brake&reverse lights if engine is on --- lights/ivl_brakereverse_client.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lights/ivl_brakereverse_client.lua b/lights/ivl_brakereverse_client.lua index c00765f..75e5229 100644 --- a/lights/ivl_brakereverse_client.lua +++ b/lights/ivl_brakereverse_client.lua @@ -29,9 +29,10 @@ function IVL.updateBrakeReverse(vehicle) local reverseOld = IVL.getData(vehicle, "reverse") local gear = getVehicleCurrentGear(vehicle) + local engineState = getVehicleEngineState(vehicle) -- Turn on reverse light if in reverse gear - reverseNew = (gear == 0) + reverseNew = engineState and (gear == 0) if driver then local accelerateControl = getPedControlState(driver, "accelerate") @@ -39,9 +40,12 @@ function IVL.updateBrakeReverse(vehicle) -- Turn on braking lights if in a forwards gear and brake key is pressed -- or if in reverse gear and accelerate key is pressed - brakeNew = (gear > 0 and brakeControl) - or (gear == 0 and accelerateControl) + brakeNew = engineState and + ((gear > 0 and brakeControl) + or (gear == 0 and accelerateControl)) end + + dxDrawText("gear: "..tostring(gear), 10, 15) if brakeOld ~= brakeNew then setVehicleCustomLightsPower(vehicle, BRAKE_LIGHTS, brakeNew and 1 or 0) From 137d4ad699b5f89e060e873dabcf919cabf66eb8 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 16 May 2024 16:01:17 +0100 Subject: [PATCH 3/4] Formatting --- lights/ivl_brakereverse_client.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lights/ivl_brakereverse_client.lua b/lights/ivl_brakereverse_client.lua index 75e5229..a1fd57f 100644 --- a/lights/ivl_brakereverse_client.lua +++ b/lights/ivl_brakereverse_client.lua @@ -31,18 +31,15 @@ function IVL.updateBrakeReverse(vehicle) local gear = getVehicleCurrentGear(vehicle) local engineState = getVehicleEngineState(vehicle) - -- Turn on reverse light if in reverse gear - reverseNew = engineState and (gear == 0) + reverseNew = engineState and gear == 0 if driver then local accelerateControl = getPedControlState(driver, "accelerate") local brakeControl = getPedControlState(driver, "brake_reverse") - -- Turn on braking lights if in a forwards gear and brake key is pressed - -- or if in reverse gear and accelerate key is pressed brakeNew = engineState and - ((gear > 0 and brakeControl) - or (gear == 0 and accelerateControl)) + (gear > 0 and brakeControl) + or (gear == 0 and accelerateControl) end dxDrawText("gear: "..tostring(gear), 10, 15) From 9ffcd132dfc801aed0bedb82bf8101da8e902f3c Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 16 May 2024 16:03:22 +0100 Subject: [PATCH 4/4] Remove leftover debug dxdraw --- lights/ivl_brakereverse_client.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lights/ivl_brakereverse_client.lua b/lights/ivl_brakereverse_client.lua index a1fd57f..09f141b 100644 --- a/lights/ivl_brakereverse_client.lua +++ b/lights/ivl_brakereverse_client.lua @@ -42,8 +42,6 @@ function IVL.updateBrakeReverse(vehicle) or (gear == 0 and accelerateControl) end - dxDrawText("gear: "..tostring(gear), 10, 15) - if brakeOld ~= brakeNew then setVehicleCustomLightsPower(vehicle, BRAKE_LIGHTS, brakeNew and 1 or 0) setVehicleLightState(vehicle, 2, 1)