BeamNG LUA Library

Discussion in 'Content Creation' started by DaddelZeit, Jan 30, 2022.

  1. DaddelZeit

    DaddelZeit
    Expand Collapse

    Joined:
    Jul 17, 2019
    Messages:
    3,487
    Hello :D
    In my time of modding BeamNG I eventually came to a point where I could no longer experiment with existing JBEAM features, so I began learning how to code in LUA for Beam.
    After I got asked quite a lot of times for permission to use my work I figured I might as well release it for free under these conditions:
    1. Credit to me on the mod page must be given.
    2. These files are free to use, however this does not mean they are free to redistribute. Send out the link to this thread instead.
    3. You are allowed to edit the files, however 1. applies in all cases.

    Now onto the files, I included a little documentation to help you implement them:
    The lua files in here go into <vehicle name>/lua/controller.
    To call these files you must follow this format:
    Code:
    "controller": [
       ["filename"],
       ["<name of lua file>"],
    ],
    To specifiy attributes you must follow this format:
    Code:
    "<name of lua file>": {
       "<attributeX>": <value>,
    },
    For nodes the format is a table:
    Code:
    "<attributeY>": ["<node name>"]


    coastRegenLights.lua
    Functionality: Lets the brake lights light up when emotor is regenerating
    Usage: Use on vehicles with the new "brakeLights" function instead of "brake" for glowmaps/flares
    JBEAM attributes:
    motorName - specifies what motor the lua is looking for (commonly rearMotor, frontMotor)


    corneringLights.lua
    Functionality: makes cornering lights possible
    Usage: Separate the light mesh, materials and flares into right and left if not done already and
    use cornering_R and cornering_L as their glowmap (and light) functions
    JBEAM attributes:
    steerAngle - sets the angle at which the lights turn on


    evWarn.lua
    Functionality: Plays a sound pitched by wheel speed.
    Usage: Use with static one-note looped sound effects.
    JBEAM attributes:
    soundLoopFile - specifies what sound to play (file path)
    soundVolume - sets volume of sound (is smoothed afterward)
    soundNode - specifies from what node the sound is played (default is ref node)


    infinitePropSpin.lua
    Functionality: Creates an infinite spin function
    Usage: Lets a 360° prop spin infinitely, multiplier must be 1
    JBEAM attributes:
    spinSpeed - specifies the speed at which the prop spins


    packCurrentPowerIntoValue.lua
    Functionality: Converts torque% from electric motor into function usable for gauge needles
    Usage: Use as function for gauges done with props
    JBEAM attributes:
    offset - specifies an offset amount
    torqueMultiplier - multiplies the shown torque to allow for adjusting
    regenTorqueMultiplier - multiplies the regenerating torque to allow for adjusting


    retarder.lua
    Functionality: Allows for implementation of a retarder (albeit 5 step). Requires transmission/gearbox
    Usage: For use with given input_actions_retarder.json
    JBEAM attributes:
    powerStage1 - Power of the first stage
    powerStage2 - Power of the second stage
    powerStage3 - Power of the third stage
    powerStage4 - Power of the 4th stage
    powerStage5 - Power of the 5th stage
    The lua files in here go into <vehicle name>/lua/energyStorage.
    (You can also install these in <mod.zip>/lua/vehicle/energyStorage,
    to avoid conflicts however please use the vehicle specific method)

    To call these files you must follow this format:
    Code:
    "energyStorage": [
        ["type", "name"],
        ["<storage type>", "<storage name>"],
    ],
    To specifiy attributes you must follow this format:
    Code:
    "<name of lua file>": {
       "<attributeX>": <value>,
    },
    The required attributes are these:
    Code:
    "mainTank": {
        "energyType":"<energy type>",
        "fuelCapacity": <fuel capacity in numbers>,
        "startingFuelCapacity": "<fuel jbeam variable>",
        "fuel": {"[engineGroup]:":["fuel"]},
        "breakTriggerBeam": "<break beam, uses name>",
    },


    gasTank.lua
    Functionality: Adds support for CNG and LPG fuels along with correct density etc. values.
    Usage: gasTank as storage type, energy type can be either lpg or cng
    JBEAM attributes:
    default vanilla attributes
    The lua files in here go into <vehicle name>/lua.
    These files are automatically loaded.


    messageOnSpawn.lua
    Functionality: sends a GUI message when the vehicle is first spawned
    Usage: change the text inbetween the "" to change text displayed (inside the lua file)

    I hope you find this useful :)
     

    Attached Files:

    • Like Like x 3
  2. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,436
    Cool, but I thought that custom LUA wasn't needed to simulate CNG and LPG, I have done that with only Jbeam before, and other weird types of fuel too, and all seems to work fine
     
  3. DaddelZeit

    DaddelZeit
    Expand Collapse

    Joined:
    Jul 17, 2019
    Messages:
    3,487
    Yes, I originally made that lua to allow for correct density and burn power (?) settings as I wanted to make it as close to perfect as possible.
     
  4. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,436
    Liquid density and energy density is possible to change via Jbeam, not sure what the burn power is but could be just a similar thing as energy density
     
    • Agree Agree x 1
  5. DaddelZeit

    DaddelZeit
    Expand Collapse

    Joined:
    Jul 17, 2019
    Messages:
    3,487
    Wait what :eek:
    Okay I gotta take that file out then
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice