Binding help

Discussion in 'Programming' started by yannis01186, May 29, 2020.

  1. yannis01186

    yannis01186
    Expand Collapse

    Joined:
    Feb 27, 2017
    Messages:
    134
    Hi, I'm trying to create a lift system for my mod. What I want to do is set a value to a variable inside a .jbeam file by clicking on a key. I understant the input_actions.json and how to use .lua with hydro beams but I haven't figured out how, if it's possible to assign a variable like for example $rideheight_F with binding.
    Thank you
     
    • Like Like x 1
  2. Zonda

    Zonda
    Expand Collapse
    Banned

    Joined:
    Jan 17, 2020
    Messages:
    136
    upload_2020-5-29_12-16-45.png
    Pretty sure in a folderpath of inputmaps/keyboards.json, you can define the hydro actions
    upload_2020-5-29_12-18-14.png
    and having a input_actions.json file in the mainfolder of the mod.
     
  3. yannis01186

    yannis01186
    Expand Collapse

    Joined:
    Feb 27, 2017
    Messages:
    134
    Thanks for your answer but it's not what I want to do, I don't want to define a hydro action but set a variable so I can change the precompressionRange value dynamically
     
    • Like Like x 1
  4. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,492
    Hey @yannis01186 , check this out : https://www.beamng.com/threads/a-variable-for-the-jbeam-files-but-defined-by-a-lua-file.70386/

    I don't know which in-game action you're after but why would you want to make pre-crompression dynamical ? As far as I know the pre-compression value only takes action on spawning, it defines how much a beam is allowed to stretch or shrink while spawning. Next to that there is beamdamp and beamspring to adjust stretch or compression rates. Strength and damp can also be defined on hydros so what you want to do is actually use a hydro imo, since it's just a beam as long as you don't use your controller to shrink or extend it.
    Then, in lua, you can use a variable to make it move on certain arguments. The reaction time (inrate outrate) is limited though. Again, I don't know what it is you actually want to do, do you just want a lift to go up and down but stop on the way in between ? That would just be like the car lift and dumpster and etc ? Here below is the code from the T-Series' custom_input lua file. Pay attention to the dt arguments, dt (difference in time) in this case is applied for potentiometer-like action like car lift or dumpster.

    Code:
    -- 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 function onReset()
      electrics.values['tilt'] = 0
      electrics.values['tilt_input'] = 0
      electrics.values['extend'] = 0
      electrics.values['extend_input'] = 0
    end
    
    local function updateGFX(dt) -- ms
      electrics.values['tilt'] = math.min(1, math.max(-0.0, (electrics.values['tilt'] + electrics.values['tilt_input'] * dt * 0.25)))
      electrics.values['extend'] = math.min(1, math.max(-0.0, (electrics.values['extend'] + electrics.values['extend_input'] * dt * 0.25)))
    end
    
    local function tiltBed(value)
      electrics.values.tilt_input = value
    end
    
    local function extendBed(value)
      electrics.values.extend_input = value
    end
    
    -- public interface
    M.onInit    = onReset
    M.onReset   = onReset
    M.updateGFX = updateGFX
    M.tiltBed = tiltBed
    M.extendBed = extendBed
    
    return M
    
    By the way you can just put this file in your own mod and apply the 'tilt' and 'extend' values in your hydro settings as input source. That should get you started on a lift system.
     
    • Like Like x 1
  5. yannis01186

    yannis01186
    Expand Collapse

    Joined:
    Feb 27, 2017
    Messages:
    134
    Thanks a lot, I will try that. I don't know why but I thought that using an hydros would make the suspensions unstable or not like a normal beam. And now I know that we can't a variable in lua for a jbeam files. Thanks
    --- Post updated ---
    @NOCARGO
    It work perfectly thanks :)
    I made my own lua script but it's maybe a bit to fast now: (edit I just have to change inRate and outRate to 0.2)
    Code:
    -- 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 = {}
    M.type = "auxilliary"
    M.relevantDevice = nil
    
    local liftClosed = 0
    local liftNormal = 0.1
    
    local  pressed = false
    
    local function init()
    
    end
    
    local function setUpLift()
       if pressed == true then
           pressed = false
       else
           pressed = true
       end
    end
    
    
    local function updateGFX(dt)
        local lift = electrics.values.lift
       if pressed == true then
           lift = liftNormal
       else
           lift = liftClosed
       end
        electrics.values.lift = lift
    end
    
    M.updateGFX = updateGFX
    M.setUpLift = setUpLift
    
    return M
    
    And in the jbeam file:
    Code:
        ], 
        "hydros": [
                ["id1:","id2:"],
              {"beamDeform":20000,"beamStrength":200000},
              {"beamSpring":161000,"beamDamp":0},
              ["fh4r","fs1r", {"precompressionRange":0.045,
                  "soundFile":"event:>Vehicle>Suspension>car_modn_med_01>spring_compress_01","colorFactor":0.4,"attackFactor":10,"volumeFactor":0.5,"maxStress":1700,"decayMode":1,"decayFactor":8,"pitchFactor":0.35,
                 "inputSource":"lift","inLimit":0,"outLimit":2.1,"inRate":1,"outRate":1,"inputFactor":1.0}],
              ["fh4l","fs1l", {"precompressionRange":0.045,
                  "soundFile":"event:>Vehicle>Suspension>car_modn_med_01>spring_compress_01","colorFactor":0.4,"attackFactor":10,"volumeFactor":0.5,"maxStress":1700,"decayMode":1,"decayFactor":8,"pitchFactor":0.35,         
                 "inputSource":"lift","inLimit":0,"outLimit":2.1,"inRate":1,"outRate":1,"inputFactor":1.0}],         
        ],
    
     
    #5 yannis01186, May 30, 2020
    Last edited: May 30, 2020
  6. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,492
    Hey nice script :)

    Too fast ? Well, hydros don't go as fast as I want them to go but they sure can go slow. Just change your inRate and or outRate, try
    half the value for starters and see what happens. Example : "inputSource":"lift","inLimit":0,"outLimit":2.1,"inRate":0.5,"outRate":0.5,"inputFactor":1.0}],
     
  7. yannis01186

    yannis01186
    Expand Collapse

    Joined:
    Feb 27, 2017
    Messages:
    134
    Thanks, I just saw that on the wike as well and 0.2 is the right value
    --- Post updated ---
     
    #7 yannis01186, May 30, 2020
    Last edited: May 30, 2020
  8. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,492
    Sure, thank you for inviting me :) But you're diverting from your own thread here so better to pm and or create a thread for it ?
    Don't get me wrong, I wouldn't create a thread if I didn't want to though. :)
     
  9. SlickNick924

    SlickNick924
    Expand Collapse

    Joined:
    Aug 19, 2018
    Messages:
    323
  10. yannis01186

    yannis01186
    Expand Collapse

    Joined:
    Feb 27, 2017
    Messages:
    134
    Thanks, I really put a lot of work on my next mod and I hope everyone will enjoy it !
     
    • Like Like x 4
  11. SlickNick924

    SlickNick924
    Expand Collapse

    Joined:
    Aug 19, 2018
    Messages:
    323
    I noticed that you're asking about a lift system... your next mod wouldn't happen to be the 911, right? If so, that's epic
     
  12. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,492
    Friendly reminder that this is a programming thread. I'm not angry but I'm just saying :D
     
  13. Chase_090080

    Chase_090080
    Expand Collapse

    Joined:
    Mar 2, 2019
    Messages:
    2
    good luck on the lift
     
  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