I'm working on a simple LUA script for smart coasting aka when you just wanna save some fuel on the highway the car will shutdown its engine and shift out of gear to maximize coasting. I have 90% of the script done but I just cannot figure out how to tell the gearbox to go to neutral and since I'm using a torque converter auto its even more difficult. I tried everything I could find on the old wiki and the new documentation and no luck. Can somebody please help me with this?
wow joined in 2017 and only 2 messages but anyway did you try using a system like idlo stop and start mod because that could potentially work.
Im looking at the mod right now and sadly I cannot find any traces of a code that would tell the gearbox to shift to a gear, I can mostly see just lines of code reading the current gear.
maybe you should ask the dev of it(if hes still active) and ask for persm and ask him how th system works
You can use this code to shift gears: Code: controller.mainController.shiftToGearIndex() shiftToGearIndex() takes one number as an argument, which is the gear. On manuals this is the literal indexes, so 0 = neutral, -1 = reverse, 1=first etc. Automatics don't do that, instead assigning an auto-gear to the index system: Code: hShifterModeLookup = {[-1] = "R", [0] = "N", "P", "D", "S", "2", "1", "M1"}, Meaning that to shift to neutral shiftToGearIndex needs to be called with 0, and to shift back into drive shiftToGearIndex needs to be called with 2. Keep in mind that this might not work properly with the Arcade gearbox mode.
Will this code work for my lua script? I just want to shift into neutral if wheelspeed is under 5 and theres no throttle, but not if its in reverse Spoiler: Code Code: local M = {} local wheelspeed = 0 local nbs = 0 local gearbox = powertrain.getDevice("gearbox") if electrics.values.throttle > 0.1 then nbs = 0 elseif gearbox.gearRatios[gearbox.gearIndex] == 0 then nbs = 0 return false end if electrics.values.wheelspeed <= 5.0 then nbs = 1 end if electrics.values.wheelspeed >= 5.0 then nbs = 0 end local function updateGFX(dt) if nbs == 1 then controller.mainController.shiftToGearIndex(0) end
Hi, code this short should work: Code: local M = {} local function updateGFX() -- speed is in m/s (m/s * 3.6 = km/h) if electrics.values.wheelspeed < 5/3.6 and electrics.values.throttle == 0 and electrics.values.gearIndex > 0 then controller.mainController.shiftToGearIndex(0) end end local function init() end M.init = init M.updateGFX = updateGFX return M This is a vehicle controller, so you'll need to load it via jbeam: https://documentation.beamng.com/modding/vehicle/sections/controller/ Alternatively, you can use this code to always run as an extension. Just plop it in a "lua" subfolder of the vehicle you're trying to mod. Code: local M = {} local function updateGFX() -- speed is in m/s (m/s * 3.6 = km/h) if electrics.values.wheelspeed < 5/3.6 and electrics.values.throttle == 0 and electrics.values.gearIndex > 0 then controller.mainController.shiftToGearIndex(0) end end local function onExtensionLoaded() end M.onExtensionLoaded = onExtensionLoaded M.updateGFX = updateGFX return M
So this file structure in the .zip is the right one? Code: mrradyt_wentwardtransmissionpack.zip/lua/vehicle/controller/nbsVoith.lua
Hello, unfortunately, the code doesn't work for me. I've loaded the controller in the jbeam and got the lua file in the right folder, but it doesn't do anything. No errors in the console either. Do you know why?