First commit

Functionally we have headlights, lightbar and ignition and starter
control
This commit is contained in:
2025-10-06 01:42:41 +01:00
commit 1ea0f3467d
6 changed files with 257 additions and 0 deletions
+17
View File
@@ -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.
@@ -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"
}
}
@@ -0,0 +1,5 @@
local M = {}
return M
@@ -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
@@ -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
+4
View File
@@ -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)