commit 1ea0f3467d6ab70b66325ba2b6a9818c94317f2b Author: Eduardo Silva Date: Mon Oct 6 01:42:41 2025 +0100 First commit Functionally we have headlights, lightbar and ignition and starter control diff --git a/README.md b/README.md new file mode 100644 index 0000000..498669f --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# ESBtnBoxBindings +This mod creates new binds to handle: +- Lights +- Diff locks +- Range box +- Ignition +- Starter + + +Becasue in BeamNG.drive currently the user can only assign a single key to toggle across the +multiple positions for each one of those settings, which doesn't really work well with toggle +switches. + + +With this mod you can have a `On - Off - On` toggle switch with 2 distinct states that can stay in +each of its positions to turn something on and when returning to the Off position it will turn it +off. \ No newline at end of file diff --git a/lua/ge/extensions/core/input/actions/ESBtnBoxBindings.json b/lua/ge/extensions/core/input/actions/ESBtnBoxBindings.json new file mode 100644 index 0000000..afef377 --- /dev/null +++ b/lua/ge/extensions/core/input/actions/ESBtnBoxBindings.json @@ -0,0 +1,67 @@ +{ + "bb_turn_ignition_on": { + "cat": "vehicle", + "order": 54328, + "ctx": "vlua", + "onDown": "extensions.use('ESBtnBoxIgnition').toggleIgnitionOn()", + "title": "ESBtnBox Bindings: Toggle Ignition to ON Position", + "desc": "Turns the key to the ON position" + }, + "bb_turn_ignition_acc": { + "cat": "vehicle", + "order": 54329, + "ctx": "vlua", + "onDown": "extensions.use('ESBtnBoxIgnition').toggleIgnitionAcc()", + "title": "ESBtnBox Bindings: Toggle Ignition to Acc Position", + "desc": "Turns the key to the Acc position" + }, + "bb_turn_starter": { + "cat": "vehicle", + "order": 54330, + "ctx": "vlua", + "onDown": "extensions.use('ESBtnBoxIgnition').turnStarter()", + "onUp": "extensions.use('ESBtnBoxIgnition').releaseStarter()", + "title": "ESBtnBox Bindings: Turn starter", + "desc": "Turns the starter" + }, + "bb_turn_high_beams_on": { + "cat": "vehicle", + "order": 54331, + "ctx": "vlua", + "onDown": "extensions.use('ESBtnBoxHeadlights').toggleHighBeams()", + "title": "ESBtnBox Bindings: Toggle High Beams On", + "desc": "Turns high beams on and off with the flicker of the toggle switch" + }, + "bb_turn_low_beams_on": { + "cat": "vehicle", + "order": 54332, + "ctx": "vlua", + "onDown": "extensions.use('ESBtnBoxHeadlights').toggleLowBeams()", + "title": "ESBtnBox Bindings: Toggle Low Beams On", + "desc": "Turns the low beams on and off with the flicker of the toggle switch" + }, + "bb_turn_lightbar_light": { + "cat": "vehicle", + "order": 54333, + "ctx": "vlua", + "onDown": "extensions.use('ESBtnBoxHeadlights').toggleLigthbarLight()", + "title": "ESBtnBox Bindings: Toggle Lightbar Light On", + "desc": "Turns the lights on the lightbar" + }, + "bb_turn_lightbar_sound": { + "cat": "vehicle", + "order": 54334, + "ctx": "vlua", + "onDown": "extensions.use('ESBtnBoxHeadlights').toggleLigthbarSound()", + "title": "ESBtnBox Bindings: Toggle Lightbar Sound On", + "desc": "Turns the sound on the lightbar" + }, + "bb_turn_high_four": { + "cat": "vehicle", + "order": 54335, + "ctx": "vlua", + "onDown": "extensions.use('ESBtnBoxDrivetrain').toggleHighFour()", + "title": "ESBtnBox Bindings: Toggle Lightbar Sound On", + "desc": "Turns the sound on the lightbar" + } +} \ No newline at end of file diff --git a/lua/vehicle/extensions/ESBtnBoxDrivetrain.lua b/lua/vehicle/extensions/ESBtnBoxDrivetrain.lua new file mode 100644 index 0000000..4076910 --- /dev/null +++ b/lua/vehicle/extensions/ESBtnBoxDrivetrain.lua @@ -0,0 +1,5 @@ +local M = {} + + + +return M \ No newline at end of file diff --git a/lua/vehicle/extensions/ESBtnBoxHeadlights.lua b/lua/vehicle/extensions/ESBtnBoxHeadlights.lua new file mode 100644 index 0000000..ee02abe --- /dev/null +++ b/lua/vehicle/extensions/ESBtnBoxHeadlights.lua @@ -0,0 +1,81 @@ +local M = {} + +-- Additional logic needed for headlight toggle +-- BeamNG headlight status: +-- Off 0 +-- Low Beams 1 +-- High Beams 2 +local headlightsOff = 0 +local lowBeams = 1 +local highBeams = 2 + +-- I will be forcing each state due to my controls not being sequential +-- I have a toggle switch (On - Off - On) and it will control both low and high beams, so +-- the top On will turn high beams on and the bottom On will turn low beams on. The middle position +-- will just be off. +-- Which makes this variable redundant, but if I do change my controls the logic will be useful +local currentHeadlightMode = 0 + +---------------------------------------------------------------------------------------------------- +-- Utility +---------------------------------------------------------------------------------------------------- +local function setHeadlightsTo(pos) + electrics.setLightsState(pos) + currentHeadlightMode = pos +end + +---------------------------------------------------------------------------------------------------- +-- HeadLight handling +---------------------------------------------------------------------------------------------------- +local function toggleHighBeams() + print("toggling high beams") + if currentHeadlightMode == highBeams then + setHeadlightsTo(headlightsOff) + else + setHeadlightsTo(highBeams) + end +end + +local function toggleLowBeams() + print("toggling low beams") + if currentHeadlightMode == lowBeams then + setHeadlightsTo(headlightsOff) + else + setHeadlightsTo(lowBeams) + end +end + +---------------------------------------------------------------------------------------------------- +-- Lightbar handling +---------------------------------------------------------------------------------------------------- +local lightbarOff = 0 +local lightbarOn = 1 +local lightbarWithSound = 2 +local lightbarCurrentMode = 0 + +local function turnLightbarLight() + if lightbarCurrentMode == lightbarOn then + electrics.set_lightbar_signal(lightbarOff) + lightbarCurrentMode = lightbarOff + else + electrics.set_lightbar_signal(lightbarOn) + lightbarCurrentMode = lightbarOn + end +end + +local function turnLightbarSound() + if lightbarCurrentMode == lightbarWithSound then + electrics.set_lightbar_signal(lightbarOff) + lightbarCurrentMode = lightbarOff + else + electrics.set_lightbar_signal(lightbarWithSound) + lightbarCurrentMode = lightbarWithSound + end +end + +M.toggleHighBeams = toggleHighBeams +M.toggleLowBeams = toggleLowBeams +M.toggleLigthbarLight = turnLightbarLight +M.toggleLigthbarSound = turnLightbarSound + +return M \ No newline at end of file diff --git a/lua/vehicle/extensions/ESBtnBoxIgnition.lua b/lua/vehicle/extensions/ESBtnBoxIgnition.lua new file mode 100644 index 0000000..2111ba9 --- /dev/null +++ b/lua/vehicle/extensions/ESBtnBoxIgnition.lua @@ -0,0 +1,83 @@ +local M = {} + +---------------------------------------------------------------------------------------------------- +-- UTILITY +---------------------------------------------------------------------------------------------------- +local function setIgnitionLevel(level) + electrics.values.ignitionLevel = level + curIgnitionPos = level +end + +-- BeamNG ignition states +-- Ignition OFF 0 +-- Ignition Acc 1 +-- Ignition ON 2 +-- Ignition Running 3 +local ignitionOff = 0 +local ignitionAcc = 1 +local ignitionOn = 2 +local ignitionRunning = 3 +local curIgnitionPos = 0 + +local function toggleIgnitionAcc() + print("Toggle ignition to accessories") + if curIgnitionPos == ignitionAcc then + electrics.values.ignitionLevel = ignitionOff + curIgnitionPos = ignitionOff + controller.mainController.setEngineIgnition(false) + else + electrics.values.ignitionLevel = ignitionAcc + curIgnitionPos = ignitionAcc + controller.mainController.setEngineIgnition(false) + end + + local ignPos = electrics.values.ignitionLevel + print("cur ignition lvl: " .. ignPos or nil) +end + +local function toggleIgnitionOn() + print("Toggle ignition to on") + if curIgnitionPos == ignitionOn then + electrics.values.ignitionLevel = ignitionOff + curIgnitionPos = ignitionOff + controller.mainController.setEngineIgnition(false) + else + electrics.values.ignitionLevel = ignitionOn + curIgnitionPos = ignitionOn + controller.mainController.setEngineIgnition(true) + end + + local ignPos = electrics.values.ignitionLevel + print("cur ignition lvl: " .. ignPos or nil) +end + +---------------------------------------------------------------------------------------------------- +-- STARTER +---------------------------------------------------------------------------------------------------- + +local starterHeld = false +local engineRunning = false + +local function turnStarter() + if curIgnitionPos < 2 then + return + end + + controller.mainController.setStarter(true) +end + +local function releaseStarter() + print("releasing starter") + if curIgnitionPos < 2 then + return + end + + controller.mainController.setStarter(false) +end + +M.toggleIgnitionAcc = toggleIgnitionAcc +M.toggleIgnitionOn = toggleIgnitionOn +M.turnStarter = turnStarter +M.releaseStarter = releaseStarter + +return M \ No newline at end of file diff --git a/scripts/ESBtnBoxBindings/modScript.lua b/scripts/ESBtnBoxBindings/modScript.lua new file mode 100644 index 0000000..8f1a346 --- /dev/null +++ b/scripts/ESBtnBoxBindings/modScript.lua @@ -0,0 +1,4 @@ +load("ESBtnBoxHeadlights") -- Load the mod +load("ESBtnBoxIgnition") -- Load the mod +setExtensionUnloadMode("ESBtnBoxHeadlights", "manual") -- Set the unload mode to manual (This is very new, old function is deprecated) +setExtensionUnloadMode("ESBtnBoxIgnition", "manual") -- Set the unload mode to manual (This is very new, old function is deprecated) \ No newline at end of file