First Vehicle Lua Mod

So, since we added a Lua modding/hooking API into our latest testing version, we enable the mod creators to extend the Lua functionality that we ship by default.

As example, we want to have speed-sensitive dynamic steering on certain hydros so that the steering of certain wheels will reduce the faster you get.
Let me walk you through how to get it working. (once we release the update to the public for sure)

1. Change your hydros so that they are not driven by the steering anymore: I.e. change

["x43l","x44l", {"factor": 0.20,"steeringWheelLock":700,"lockDegrees":35}],

to

["x43l","x44l", {"factor": 0.20,"steeringWheelLock":700,"lockDegrees":35, "inputSource":"steering_speeddependant"}],

2. add a new folder to your vehicle folder, called ‘lua’. The game will load any .lua files in there.

3. write the lua extension (lua/rearSteering.lua):

 

-- This Source Code Form is subject to the terms of the bCDDL, v. 1.1.
-- If a copy of the bCDDL was not distributed with this
-- file, You can obtain one at http: //beamng.com/bCDDL-1.1.txt
local M = {}
local maxSpeed = 10 -- in meters per second
local function init()
    if v.data.dynamicSteering.maxSpeed ~= nil and type(v.data.dynamicSteering.maxSpeed) == 'number' then
        maxSpeed = v.data.dynamicSteering.maxSpeed
    end
end
local function updateGFX(dt)
    electrics.values['steering_speeddependant'] = electrics.values['steering_input'] * math.max(0, (maxSpeed - math.abs(electrics.values['wheelspeed'])) / maxSpeed)
end
-- public interface
M.updateGFX = updateGFX
M.init      = init
return M

The updateGFX, init and reset functions are called automatically by the game. 🙂

To make it easier for the vehicle creator, one can add the gimmick to read out options by adding them to the .jbeam instead of hardcoding them into the lua. The above mod uses this new section in the jbeam file:

"dynamicSteering":
{
    "maxSpeed":10,
}

 

 

Leave a Reply