SOLVED: Increase nitrous spray with vehicle speed

Discussion in 'Content Creation' started by Geraldis, Oct 8, 2023.

  1. Geraldis

    Geraldis
    Expand Collapse

    Joined:
    Oct 8, 2023
    Messages:
    3
    Hello all. First post here, newbie to LUA and JBEAM.

    I'm trying to make self-adjusting nitrous shots based on vehicle speed.
    Basically I want the nitrous to increase as vehicle speed increases.

    I have successfully made a helloworld.lua that gives me wheelspeed data and stores it to 'testvar'
    This LUA file was placed in the lua folder inside of the vehicle directory.
    Code:
    local M = {}
    local function updateGFX(dt)
        testvar = electrics.values.wheelspeed
        print(testvar)
    end
    M.updateGFX = updateGFX
    return M
    
    When playing Beamng I can open the console and see a constant stream of values for testvar so I know its got the right data.

    Here's my code on the nitrous side. n2o.jbeam
    Code:
    "n2o_shot_variable": {
        "information":{
            "authors":"BeamNG",
            "name":"Adjustable Shot Size",
            "value":200,
        },
        "slotType" : "n2o_shot",
        "variables": [
            ["name", "type", "unit", "category", "default", "min", "max", "title", "description"],
            ["$n2o_power", "range", "kW", "Nitrous Oxide", 75, 25, 1900, "Added Power", "Power increase the N2O injection grants", {"stepDis":5}],
        ],
        "n2o": {
              "addedPower": "$=$testvar*50",
        },
    },
    }
    
    It seems like 'testvar' is not being read properly in n2o.jbeam, as when I hit the nitrous it does nothing. Like it's set to 0.

    If I replace "$=$testvar*50" with an integer it'll activate the nitrous. So I know the JBEAM is working.

    Any idea what I'm missing here?
    Thanks
     
    #1 Geraldis, Oct 8, 2023
    Last edited: Oct 8, 2023
  2. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,353
    Sadly it's not possible to just pass variables freely like this. You would have to create a custom version of the N2O controller and do the setup there.
     
    • Like Like x 1
  3. Geraldis

    Geraldis
    Expand Collapse

    Joined:
    Oct 8, 2023
    Messages:
    3
    Kinda figured I was barking up the wrong tree.
    I think I'll be able to accomplish the same thing by editing Beamng's included nitrousOxideInjection.lua now that you mentioned that method.

    Thanks!
     
  4. Geraldis

    Geraldis
    Expand Collapse

    Joined:
    Oct 8, 2023
    Messages:
    3
    For anyone curious, this is possible by changing one line in nitrousOxideInjection.lua

    Change
    Code:
    assignedEngine.nitrousOxideTorque = assignedEngine.nitrousOxideTorque + noTorque
    
    To:
    Code:
    assignedEngine.nitrousOxideTorque = (assignedEngine.nitrousOxideTorque + noTorque) * (1 + ((electrics.values.airspeed ^ 1.36) / 16.5))
    
    Have your adjustable nitrous shot in game set to whatever your car can handle out of the hole. In my case this was right around a 50 shot.

    Replace the exponent 1.36 with a higher number for more nitrous on the big end. Replace 16.5 with a lower number to give more nitrous throughout the entire run.

    This makes nitrous SO much more fun. For example I took a 15 sec 4 door sedan into the mid 9s on an unprepped road. Nitrous starts at a 50 shot out of the hole but by the eighth mile it's spraying around a 1000hp shot.

    This comes close to emulating a nitrous controller that has the ability to ramp in more nitrous as vehicle speed increases.
     
    #4 Geraldis, Oct 9, 2023
    Last edited: Oct 11, 2023
  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