Solved How can I make a custom button on the UI, like the jato and n2o.

Discussion in 'Mod Support' started by señor Walter Blanco, Aug 8, 2023.

  1. señor Walter Blanco

    señor Walter Blanco
    Expand Collapse

    Joined:
    May 31, 2023
    Messages:
    15
    So I made a thruster mod for a different r32 mod (ignore the missing texture)

    And I want to be able to turn off the thrusters when you do not want them. I tried copying the Jato button into my thruster Lua code, but since there is basically no documentation, I can't tell what doesn't work.

    Jet controller Lua. From jet pigeon mod ( a bit modified)

    Code:
    local M = {}
    
    M.type = "auxiliary"
    M.defaultOrder = 500
    
    local rpm = 0
    
    local outputmin = 0
    local outputmax = 1
    local thrust = 0
    electrics.values.Jet = 0
    
    local lastFuelRatio = 0
    
    local function init(jbeamData)
    min = jbeamData.min or 4000
    max = jbeamData.max or 6000
    end
    
    local function updateSimpleControlButtons()
      extensions.ui_simplePowertrainControl.setButton("jato_" .. M.name, "JATO", "powertrain_jato", "0072bc", lastFuelRatio, "electrics.values.jatoInput = 1 - (electrics.values.jatoInput or 0)")
    end
    
    local function rpmthrust(rpm, min, max, outputmin, outputmax)
      local output = (rpm - min) / (max - min) * (outputmax - outputmin) + outputmin
      return output
    end
    
    local function updateGFX(dt)
      local RocketInput = min(electrics.values.jatoInput or 0, 1)
      print(rpm)
    
      rpm = electrics.values.rpm
    
     
      if rpm >= min then
        thrust = rpmthrust(rpm, min, max, outputmin, outputmax)
      else
        thrust = 0
      end
    
     
      electrics.values.Jet = thrust * electrics.values.throttle_input
    
    end
    
    M.updateGFX = updateGFX
    M.init = init
    return M
    
    Rocket Trunk Part Code:

    Code:
    {
    "coupe_trunk_rocket": {
        "information":{
            "authors":"BeamNG",
            "name":"Trunk Rocket",
            "value":350,
        },
        "slotType" : "coupe_trunk",
        "flexbodies": [
             ["mesh", "[group]:", "nonFlexMaterials"],
             ["coupe_trunk_rocket", ["coupe_trunk"]],
             {"deformGroup":"chmsl_break", "deformMaterialBase":"coupe_lights", "deformMaterialDamaged":"coupe_lights_dmg"},
             ["coupe_chmsl", ["coupe_trunk"]],
             {"deformGroup":""},
        ],
        "powertrain": [
            ["type", "name", "inputName", "inputIndex"],
            ["combustionEngine", "mainEngine", "dummy", 0],
        ],
        "slots": [
            ["type", "default", "description"],
           // ["coupe_spoiler","", "Spoiler"],
           // ["coupe_trunkpanel","coupe_trunkpanel", "Taillight Panel"],
           // ["coupe_lettering_trunk","coupe_lettering_base", "Lettering"],
        ],   
        "variables": [
            ["name", "type", "unit", "category", "default", "min", "max", "title", "description"],
            ["$jet_rpm_L", "range", "RPM", "Thruster", 4000, 0, 20000, "Minimum RPM", "Minimum RPM where thruster starts", {"stepDis":500}],
            ["$jet_rpm_W", "range", "RPM", "Thruster", 6000, 0, 20000, "Maximum RPM", "Maximum RPM where thruster starts", {"stepDis":500}],
        ],
        
        "props": [
            ["func"      , "mesh"              , "idRef:", "idX:", "idY:"            , "baseRotation"        , "rotation"                 , "translation"        , "min", "max", "offset", "multiplier"],
            {
                "lightInnerAngle":10,
                "lightOuterAngle":120,
                "lightRange":8,
                "lightColor":{"r":255, "g":0, "b":0, "a":255},
                "lightAttenuation":{"x":0, "y":1, "z":1},
                "lightCastShadows":false,
                "flareName":"vehicleBrakeLightFlare",
                "cookieName":""
            },
            //chmsl
            ["brake" ,         "SPOTLIGHT"        , "t4r", "t4", "t3r", {"x":0, "y":0, "z":0} , {"x":0, "y":0, "z":30}    , {"x":0, "y":0, "z":0}, 0, 0, 0, 1, {"baseTranslation":{"x":1.25, "y":0.9, "z":0.00},"flareScale":0.03,"lightBrightness":0.05,"deformGroup":"chmsl_break"}],
            ["rpmspin","Turbine_Fan","t1","1t","t1", {"x":0,"y":180,"z":90},{"x":0,"y":1,"z":0},{"x":0,"y":0,"z":0}, -360,360, 0 ,1],
        ],     
        "controller":[
            ["fileName"],
            ["Jet",{}],
        ],
        "Jet":{
        "min": "$jet_rpm_L",
        "max": "$jet_rpm_R",
        },
        "thrusters": [
            ["id1:", "id2:", "factor", "thrustLimit", "control"],
            ["t1","t3",60000,6000,"Jet"]
            ["t1","t3",6000,6000,"Jet"]
        ]
        "nodes": [
             ["id", "posX", "posY", "posZ"],
             //--TRUNK--
             {"nodeMaterial":"|NM_METAL"},
             {"frictionCoef":0.5},
             {"group":"coupe_trunk"},
             {"collision":true},
             {"selfCollision":true},
             {"nodeWeight":0.65},
             ["t1rr", -0.64, 1.67, 0.97],
             ["t1", 0, 1.76, 0.99],
             ["t1ll", 0.64, 1.67, 0.97],
    
             ["t2rr", -0.64, 1.85, 0.93],
             ["t2r", -0.27, 1.88, 0.95],
             ["t2l", 0.27, 1.88, 0.95],
             ["t2ll", 0.64, 1.85, 0.93],
    
             ["t3rr", -0.60, 2.09, 0.90],
             ["t3r", -0.36, 2.10, 0.92],
             ["t3", 0.0, 2.11, 0.93],
             ["t3l", 0.36, 2.10, 0.92],
             ["t3ll", 0.60, 2.09, 0.90],
    
             ["t4rr", -0.53, 2.14, 0.68],
             ["t4r", -0.28, 2.16, 0.68],
             ["t4", 0, 2.17, 0.68],
             ["t4l", 0.28, 2.16, 0.68],
             ["t4ll", 0.53, 2.14, 0.68],
    
             //rigidifier
             {"collision":false},
             {"selfCollision":false},
             {"nodeWeight":0.8},
             ["t5",0.0, 1.92, 0.76],
             {"group":""},
        ],
        "beams": [
              ["id1:", "id2:"],
              //--TRUNK--
              {"beamPrecompression":1, "beamType":"|NORMAL", "beamLongBound":1.0, "beamShortBound":1.0},
              {"beamSpring":701000,"beamDamp":50},
              {"beamDeform":32550,"beamStrength":"FLT_MAX"},
              {"deformationTriggerRatio":0.03},
              //trunk main shape
              {"deformLimitExpansion":1.1},
              ["t1rr","t1"],
              ["t1ll","t1"],
              ["t2rr","t2r"],
              ["t2r","t2l"],
              ["t2ll","t2l"],
              ["t3rr","t3r"],
              ["t3l","t3ll"],
    
              {"deformGroup":"chmsl_break"},
              ["t3r","t3"],
              ["t3","t3l"],
              {"deformGroup":"trunklight_R_break"},
              ["t4rr","t4r"],
              {"deformGroup":"trunklight_L_break"},
              ["t4ll","t4l"],
              {"deformGroup":""},
    
              ["t4r","t4"],
              ["t4l","t4"],
    
              ["t1rr","t2rr"],
              ["t1ll","t2ll"],
    
              ["t1","t2r"],
              ["t1","t2l"],
    
              ["t2rr","t3rr"],
              ["t2ll","t3ll"],
    
              {"deformGroup":"chmsl_break"},
              ["t2r","t3r"],
              ["t2l","t3l"],
              {"deformGroup":"trunklight_R_break"},
              ["t3rr","t4rr"],
              ["t3r","t4r"],
              {"deformGroup":"trunklight_L_break"},
              ["t3l","t4l"],
              ["t3ll","t4ll"],
              {"deformGroup":"chmsl_break"},
              ["t3","t4"],
              ["t2r","t3"],
              ["t2l","t3"],
              {"deformGroup":""},
    
              //surficial crossing
              {"deformLimitExpansion":""},
              {"beamDeform":13500,"beamStrength":"FLT_MAX"},
              ["t1rr","t2r"],
              ["t1ll","t2l"],
              ["t1","t2rr"],
              ["t1","t2ll"],
              ["t2r","t3rr"],
              ["t2l","t3ll"],
    
              {"deformGroup":"chmsl_break"},
              ["t2rr","t3r"],
              ["t2ll","t3l"],
              ["t3","t4l"],
              ["t3","t4r"],
              ["t4","t3l"],
              ["t4","t3r"],
              {"deformGroup":"trunklight_R_break"},
              ["t3r","t4rr"],
              ["t3rr","t4r"],
              {"deformGroup":"trunklight_L_break"},
              ["t3l","t4ll"],
              ["t3ll","t4l"],
              {"deformGroup":""},
    
              //rigids
              {"beamSpring":351000,"beamDamp":50},
              {"beamDeform":4800,"beamStrength":"FLT_MAX"},
              ["t1rr","t1ll"],
              ["t2rr","t2l"],
              ["t2r","t2ll"],
    
              {"deformGroup":"chmsl_break"},
              ["t3rr","t3"],
              ["t3r","t3l"],
              ["t3","t3ll"],
              {"deformGroup":""},
    
              ["t1rr","t3rr"],
              ["t1ll","t3ll"],
    
              {"deformGroup":"chmsl_break"},
              ["t1","t3r"],
              ["t1","t3"],
              ["t1","t3l"],
              {"deformGroup":"trunklight_R_break"},
              ["t2rr","t4rr"],
              ["t2r","t4r"],
              {"deformGroup":"trunklight_L_break"},
              ["t2l","t4l"],
              ["t2ll","t4ll"],
              {"deformGroup":""},
    
              ["t2r","t4"],
              ["t2l","t4"],
    
              {"deformGroup":"chmsl_break"},
              ["t1rr","t3"],
              ["t1ll","t3"],
              ["t1rr","t3r"],
              ["t1ll","t3l"],
              {"deformGroup":""},
    
              //rigidifier
              {"beamDeform":4050,"beamStrength":"FLT_MAX"},
              {"beamSpring":601000,"beamDamp":50},
              ["t1rr","t5"],
              ["t1","t5"],
              ["t1ll","t5"],
    
              ["t2rr","t5"],
              ["t2r","t5"],
              ["t2l","t5"],
              ["t2ll","t5"],
    
              ["t3rr","t5"],
              ["t3ll","t5"],
    
              {"deformGroup":"chmsl_break"},
              ["t3r","t5"],
              ["t3","t5"],
              ["t3l","t5"],
              {"deformGroup":"trunklight_R_break"},
              ["t4rr","t5"],
              ["t4r","t5"],
              {"deformGroup":"trunklight_L_break"},
              ["t4l","t5"],
              ["t4ll","t5"],
              {"deformGroup":""},
    
              ["t4","t5"],
    
              //trunk hinge
              {"beamPrecompression":1, "beamType":"|NORMAL", "beamLongBound":1.0, "beamShortBound":1.0},
              {"beamSpring":801000,"beamDamp":100},
              {"beamDeform":15000,"beamStrength":35000},
              {"breakGroup":"trunkhinge_R"},
              {"deformGroup":"trunklight_R_break"},
              //r
              ["t1rr","tb1r"],
              ["t1","tb1l"],
              ["t2ll","tb1l"],
              ["t2r","tb1r"],
    
              {"deformGroup":"trunklight_L_break"},
              {"breakGroup":"trunkhinge_L"},
              //l
              ["t1ll","tb1l"],
              ["t1","tb1r"],
              ["t2rr","tb1r"],
              ["t2l","tb1l"],
              {"breakGroup":""},
              {"deformGroup":""},
    
              //trunk latch
              {"beamSpring":501000,"beamDamp":70},
              {"beamDeform":3600,"beamStrength":7500},
              {"breakGroup":"trunklatch"},
              ["t4rr","r7"],
              ["t4r","r7"],
              ["t4rr","r7rr"],
              ["t4r","r7rr"],
              ["t4l","r7"],
              ["t4ll","r7"],
              ["t4l","r7ll"],
              ["t4ll","r7ll"],
              ["t4","r7rr"],
              ["t4","r7ll"],
              ["t4","r7"],
              {"breakGroup":""},
    
              //pop open
              {"breakGroupType":1},
              {"beamSpring":450,"beamDamp":50},
              {"beamDeform":4350,"beamStrength":10000},
              {"beamPrecompression":3},
              {"breakGroup":"trunklatch"},
              ["t3r","r7rr"],
              ["t3l","r7ll"],
              {"breakGroup":""},
              {"beamPrecompression":1},
              {"breakGroupType":0},
    
              //damping
              {"beamDeform":27600,"beamStrength":225000},
              {"beamSpring":0,"beamDamp":30},
              {"breakGroup":"trunkhinge_R"},
              ["t3rr","r4rr"],
              {"breakGroup":"trunkhinge_L"},
              ["t3ll","r4ll"],
              {"breakGroup":""},
    
              //trunk support beams
              {"beamType":"|SUPPORT", "beamLongBound":6},
              {"beamSpring":523050,"beamDamp":50},
              {"beamDeform":22500,"beamStrength":1250000},
              ["t1rr","r5rr"],
              ["t1ll","r5ll"],
              ["t1","r5"],
    
              //["t2rr","r6rr"],
              ["t2r","r6"],
              ["t2l","r6"],
              //["t2ll","r6ll"],
    
              ["t3rr","r7rr"],
              ["t3r","r7rr"],
              ["t3","r7"],
              ["t3l","r7ll"],
              ["t3ll","r7ll"],
    
              //width
              ["t1rr","q4r"],
              ["t1ll","q4l"],
              ["t2r","q5r"],
              ["t2l","q5l"],
              ["t3r","q6r"],
              ["t3l","q6l"],
              ["t4r","q13r"],
              ["t4l","q13l"],
    
              //weak
              {"beamDeform":9000,"beamStrength":1250000},
              ["t4rr","r6rr"],
              ["t4ll","r6ll"],
              ["t4","r6"],
              ["t4r","r6"],
              ["t4l","r6"],
              {"beamPrecompression":1, "beamType":"|NORMAL", "beamLongBound":1.0, "beamShortBound":1.0},
              {"deformLimitExpansion":1.1},
        ],
        "triangles": [
                ["id1:","id2:","id3:"],
                //trunk
                {"groundModel":"metal"},
                {"group":"coupe_trunk"},
                {"dragCoef":10},
                ["t1rr","t2r","t2rr"],
                ["t1rr","t1","t2r"],
                ["t1","t2l","t2r"],
                ["t1","t1ll","t2l"],
                ["t2l","t1ll","t2ll"],
    
                ["t2rr","t2r","t3rr"],
                ["t2r","t3r","t3rr"],
                ["t2l","t3l","t3"],
                ["t2r","t2l","t3"],
                ["t2r","t3","t3r"],
                ["t2l","t3ll","t3l"],
                ["t2l","t2ll","t3ll"],
    
                {"dragCoef":2},
                ["t3rr","t3r","t4rr"],
                ["t3r","t4r","t4rr"],
                ["t3l","t4l","t4"],
                ["t3r","t3l","t4"],
                ["t3r","t4","t4r"],
                ["t3l","t4ll","t4l"],
                ["t3l","t3ll","t4ll"],
                {"group":""},
        ],
    },
    "coupe_trunkpanel": {
        "information":{
            "authors":"BeamNG",
            "name":"Taillight Panel",
            "value":90,
        },
        "slotType" : "coupe_trunkpanel",
        "flexbodies": [
             ["mesh", "[group]:", "nonFlexMaterials"],
             ["coupe_rearpanel", ["coupe_trunk"]],
             ["coupe_trunklightframe_L", ["coupe_trunk"]],
             ["coupe_trunklightframe_R", ["coupe_trunk"]],
             {"deformGroup":"trunklight_R_break", "deformMaterialBase":"coupe_lights", "deformMaterialDamaged":"coupe_lights_dmg"},
             ["coupe_trunklight_R", ["coupe_trunk"],[]{"deformSound":"event:>Destruction>Vehicle>Glass>glassbreaksound4", "deformVolume":0.4}],
             ["coupe_reverselight_R", ["coupe_trunk"]],
             {"deformGroup":"trunklight_L_break", "deformMaterialBase":"coupe_lights", "deformMaterialDamaged":"coupe_lights_dmg"},
             ["coupe_trunklight_L", ["coupe_trunk"],[]{"deformSound":"event:>Destruction>Vehicle>Glass>glassbreaksound3", "deformVolume":0.4}],
             ["coupe_reverselight_L", ["coupe_trunk"]],
             {"deformGroup":""},
        ],
        "props": [
            ["func"      , "mesh"              , "idRef:", "idX:", "idY:"            , "baseRotation"        , "rotation"                 , "translation"        , "min", "max", "offset", "multiplier"],
            {
                "lightInnerAngle":0,
                "lightOuterAngle":120,
                "lightRange":8,
                "lightColor":{"r":255, "g":50, "b":0, "a":255},
                "lightAttenuation":{"x":0, "y":0, "z":0},
                "lightCastShadows":false,
                "flareName":"vehicleBrakeLightFlare",
                "cookieName":""
            },
            //taillights
            ["brake" ,         "SPOTLIGHT"        , "t4rr", "t4r", "t3rr", {"x":0, "y":90, "z":30} , {"x":0, "y":0, "z":0}    , {"x":0, "y":0, "z":0}, 0, 0, 0, 1, {"baseTranslation":{"x":0.45, "y":0.3, "z":0.00},"flareScale":0.05,"lightBrightness":0.05,"deformGroup":"trunklight_R_break"}],
            ["brake" ,         "SPOTLIGHT"        , "t4ll", "t4l", "t3ll", {"x":180, "y":-90, "z":30} , {"x":0, "y":0, "z":0}    , {"x":0, "y":0, "z":0}, 0, 0, 0, 1, {"baseTranslation":{"x":0.45, "y":0.3, "z":-0.00},"flareScale":0.05,"lightBrightness":0.05,"deformGroup":"trunklight_L_break"}],
            ["lowhighbeam" ,         "SPOTLIGHT"        , "t4rr", "t4r", "t3rr", {"x":0, "y":90, "z":30} , {"x":0, "y":0, "z":0}    , {"x":0, "y":0, "z":0}, 0, 0, 0, 1, {"baseTranslation":{"x":0.45, "y":0.3, "z":0.00},"flareScale":0.02,"lightBrightness":0.03,"lightRange":8,"deformGroup":"trunklight_R_break"}],
            ["lowhighbeam" ,         "SPOTLIGHT"        , "t4ll", "t4l", "t3ll", {"x":180, "y":-90, "z":30} , {"x":0, "y":0, "z":0}    , {"x":0, "y":0, "z":0}, 0, 0, 0, 1, {"baseTranslation":{"x":0.45 "y":0.3, "z":-0.00},"flareScale":0.02,"lightBrightness":0.03,"lightRange":8,"deformGroup":"trunklight_L_break"}],
            {
                "lightInnerAngle":0,
                "lightOuterAngle":120,
                "lightRange":20,
                "lightColor":{"r":255, "g":255, "b":160, "a":255},
                "lightAttenuation":{"x":0, "y":1, "z":1},
                "lightCastShadows":false,
                "flareName":"vehicleReverseLightFlare",
                "cookieName":"",
                "texSize":512,
                "shadowSoftness":0.5
    
            },
            //reverse lights
            ["reverse" ,         "SPOTLIGHT"        , "t4r", "t4", "t3r", {"x":0, "y":90, "z":30} , {"x":0, "y":0, "z":0}    , {"x":0, "y":0, "z":0}, 0, 0, 0, 1, {"baseTranslation":{"x":0.1, "y":0.09, "z":0.00},"flareScale":0.05,"lightBrightness":0.05,"deformGroup":"trunklight_R_break"}],
            ["reverse" ,         "SPOTLIGHT"        , "t4l", "t4", "t3l", {"x":180, "y":-90, "z":30} , {"x":0, "y":0, "z":0}    , {"x":0, "y":0, "z":0}, 0, 0, 0, 1, {"baseTranslation":{"x":0.1, "y":0.09, "z":-0.00},"flareScale":0.05,"lightBrightness":0.05,"deformGroup":"trunklight_L_break"}],
        ],
    },
    }
     
  2. señor Walter Blanco

    señor Walter Blanco
    Expand Collapse

    Joined:
    May 31, 2023
    Messages:
    15
  3. señor Walter Blanco

    señor Walter Blanco
    Expand Collapse

    Joined:
    May 31, 2023
    Messages:
    15
  4. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,365
    Looks like you didn't put the
    updateSimpleControlButtons() function in the public interface (the thing at the end of the lua file)
     
  5. señor Walter Blanco

    señor Walter Blanco
    Expand Collapse

    Joined:
    May 31, 2023
    Messages:
    15
    could you elaborate?
    Code:
    local M = {}
    
    M.type = "auxiliary"
    M.defaultOrder = 500
    
    local rpm = 0
    
    local outputmin = 0
    local outputmax = 1
    local thrust = 0
    electrics.values.Jet = 0
    
    local lastFuelRatio = 0
    
    local function init(jbeamData)
    min = jbeamData.min or 4000
    max = jbeamData.max or 6000
    end
    
    local function updateSimpleControlButtons()
      extensions.ui_simplePowertrainControl.setButton("jato_" .. M.name, "JATO", "powertrain_jato", "0072bc", lastFuelRatio, "electrics.values.jatoInput = 1 - (electrics.values.jatoInput or 0)")
    end
    
    local function rpmthrust(rpm, min, max, outputmin, outputmax)
      local output = (rpm - min) / (max - min) * (outputmax - outputmin) + outputmin
      return output
    end
    
    local function updateGFX(dt)
      local RocketInput = min(electrics.values.jatoInput or 0, 1)
      print(rpm)
    
      rpm = electrics.values.rpm
    
     
      if rpm >= min then
        thrust = rpmthrust(rpm, min, max, outputmin, outputmax)
      else
        thrust = 0
      end
    
     
      electrics.values.Jet = thrust * electrics.values.throttle_input
    
    end
    
    M.updateGFX = updateGFX
    M.init = init
    
    M.updateSimpleControlButtons = updateSimpleControlButtons
    
    return M
    this does nothing
     
  6. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,365
    The function also needs to be called at the end of updateGFX. And your lastFuelRatio can't be permanently 0, you can change it to 1 instead, and ideally to the amount of jet fuel left.
     
  7. señor Walter Blanco

    señor Walter Blanco
    Expand Collapse

    Joined:
    May 31, 2023
    Messages:
    15
    Code:
    local M = {}
    
    M.type = "auxiliary"
    M.defaultOrder = 500
    
    local rpm = 0
    
    local outputmin = 0
    local outputmax = 1
    local thrust = 0
    electrics.values.Jet = 0
    
    local lastFuelRatio = 1
    
    local function init(jbeamData)
    min = jbeamData.min or 4000
    max = jbeamData.max or 6000
    end
    
    local function updateSimpleControlButtons()
      extensions.ui_simplePowertrainControl.setButton("jato_" .. M.name, "JATO", "powertrain_jato", "0072bc", lastFuelRatio, "electrics.values.jatoInput = 1 - (electrics.values.jatoInput or 0)")
    end
    
    local function rpmthrust(rpm, min, max, outputmin, outputmax)
      local output = (rpm - min) / (max - min) * (outputmax - outputmin) + outputmin
      return output
    end
    
    local function updateGFX(dt)
      local RocketInput = min(electrics.values.jatoInput or 0, 1)
      print(rpm)
    
      rpm = electrics.values.rpm
    
     
      if rpm >= min then
        thrust = rpmthrust(rpm, min, max, outputmin, outputmax)
      else
        thrust = 0
      end
    
     
      electrics.values.Jet = thrust * electrics.values.throttle_input
      updateSimpleControlButtons()
    
    end
    
    M.updateGFX = updateGFX
    M.init = init
    
    M.updateSimpleControlButtons = updateSimpleControlButtons
    
    return M
    so this should work?

    could you provide documentation for the extensions.ui_simplePowertrainControl.setButton, there is none availabe
     
  8. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,365
    The documentation for this is work in progress as there are many codependent systems that need to be documented. This should work from the look of it
     
  9. señor Walter Blanco

    señor Walter Blanco
    Expand Collapse

    Joined:
    May 31, 2023
    Messages:
    15
    It just doesn't for some reason, did I put all the variables in SetButton correctly? or I didn't define something else that I needed
     
  10. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,365
    What exactly is not working? Is the goal for now just to get the button to show up, or to have it fully working? Because it should be showing up, but there is nothing that will make it functional yet.
     
  11. señor Walter Blanco

    señor Walter Blanco
    Expand Collapse

    Joined:
    May 31, 2023
    Messages:
    15
    for some reason, its not even showing up yet
     
  12. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,365
    Can you confirm if the whole code is working yet? Is the jet engine functional at all?
     
  13. señor Walter Blanco

    señor Walter Blanco
    Expand Collapse

    Joined:
    May 31, 2023
    Messages:
    15
    it is
     
  14. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,365
    Can you check the console? It's really weird that part of the code is working and the other part not, usually an error would disable the whole file.
     
  15. señor Walter Blanco

    señor Walter Blanco
    Expand Collapse

    Joined:
    May 31, 2023
    Messages:
    15
    I dont see any error related to that LUA script speciffically
     
  16. señor Walter Blanco

    señor Walter Blanco
    Expand Collapse

    Joined:
    May 31, 2023
    Messages:
    15
    I think I have a theory on why it doesn't work, I'm gonna check and get back
    --- Post updated ---
    okay, because I forgot to rename the controller, it was always using the one that came with the jetgion mod, not the modified mod. Now it shows the button, the question is how do I make it work now

    I also decided to use the button to display current amount of thrust.
     
  17. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,365
    Good that it was easy to fix. Now you need to add a new variable called "jet_disabled" for example, and in the long line with setButton in the last quotation marks change
    electrics.values.jatoInput to your jet_disabled value. Then in the line where you set electrics.values.jet you can multiply it by this value. That will set the jet to 0 when the button is disabled and the calculated value when it's enabled. I hope you understand.
     
  18. señor Walter Blanco

    señor Walter Blanco
    Expand Collapse

    Joined:
    May 31, 2023
    Messages:
    15
    okay, because I forgot to rename the controller, it was always using the one that came with the jetgion mod, not the modified mod. Now it
    Is this correct?
    Code:
    local M = {}
    
    M.type = "auxiliary"
    M.defaultOrder = 500
    
    local rpm = 0
    
    local outputmin = 0
    local outputmax = 1
    local thrust = 0
    local indicator = 1
    local JetsEnable = 1
    electrics.values.Jet = 0
    
    local lastFuelRatio = 1
    
    local function init(jbeamData)
    min = jbeamData.min or 4000
    max = jbeamData.max or 6000
    end
    
    local function updateSimpleControlButtons()
      extensions.ui_simplePowertrainControl.setButton("jato_" .. M.name, "Jets", "powertrain_jato", "0072bc", indicator, "JetsEnable = 1 - (JetsEnable or 0)")
    end
    
    local function rpmthrust(rpm, min, max, outputmin, outputmax)
      local output = (rpm - min) / (max - min) * (outputmax - outputmin) + outputmin
      if output > outputmax then return outputmax
      else return output
      end
    end
    
    local function updateGFX(dt)
    
      rpm = electrics.values.rpm
    
      if rpm >= min then
        thrust = rpmthrust(rpm, min, max, outputmin, outputmax)
        indicator = thrust
      else
        thrust = 0
        indicator = 0.01
      end
    
     
      electrics.values.Jet = thrust * electrics.values.throttle_input * JetsEnable
      updateSimpleControlButtons()
    
    end
    
    M.updateGFX = updateGFX
    M.init = init
    
    M.updateSimpleControlButtons = updateSimpleControlButtons
    
    return M
     
    #18 señor Walter Blanco, Aug 18, 2023
    Last edited: Aug 18, 2023
  19. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,365
    Set the jetsEnable to 1 in init too and should work, let me know if it does.
     
  20. señor Walter Blanco

    señor Walter Blanco
    Expand Collapse

    Joined:
    May 31, 2023
    Messages:
    15
    Jets work, and I can see the button, but I cant turn it off
     
  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