Best Practice for installing lua mods?

Discussion in 'Utilities and programming' started by PEZZALUCIFER, Jun 21, 2021.

  1. PEZZALUCIFER

    PEZZALUCIFER
    Expand Collapse

    Joined:
    Jan 19, 2020
    Messages:
    11
    Hey,

    I'm no lua expert, and I certainly know very little about BeamNG mods so maybe someone here can help me with this.

    I'd like to know what the best practice is for distributing mods to .lua so they don't break when things update, and the user doesn't lose functionality of other mods.. etc..

    Specifically motionSim.lua
    https://github.com/PHARTGAMES/SpaceMonkey/blob/main/BeamNG/lua/vehicle/motionSim.lua

    I have modified the file directly to output extra telemetry for my app SpaceMonkey so I can use the SimCommander chassis tactile functionality, It all works well.

    However, I want to make an installer so that a user can just run the installer and it copies or patches a file into the right place in BeamNG.

    Initial plan is to just stomp the motionSim.lua file with my version.. then if it gets modified by an update, stomp over it again.

    Or should I modify some other file that includes motionSim.lua, and make it include a differently named file motionSim2.lua? Can I even do that?

    Or something else?

    Thankyou!
     
  2. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    Hey :)

    This is a complicated topic....

    Some areas of our lua code contain measures to make the things you are asking for somewhat easy (eg powertrain devices, controllers, shift logic), however, this is very specific and has to be implemented in a certain way depending on the actual requirements.

    While it would be technically possible to do something similar for the motionSim stuff, there isn't enough interest to warrant the cost...

    In this specific case, it's probably fine to replace the file with a custom version, however, please note that we don't approve mods on the repo that have that specific behavior.
    If you want to be extra nice, include a log in your own version that says very clearly that this is a modded motionSim.lua file and not the original. This will help our support massively.

    Out of curiosity, what exactly did you add/change?
     
  3. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    6,782
    He has added very interesting suspension telemetry stuff, although I have not got it to log anything yet, just waits data from some reason.

    edit: Also in case it was not obvious from the code, this breaks game if using vehicles with other number of wheels than 4, because lua crashes then.
    So, no Pigeon racing or truck racing when this is installed and motion sim is enabled.
     
    #3 fufsgfen, Jun 25, 2021
    Last edited: Jun 26, 2021
  4. PEZZALUCIFER

    PEZZALUCIFER
    Expand Collapse

    Joined:
    Jan 19, 2020
    Messages:
    11
    OK cool thanks Diamondback.

    As fufsgfen said I added suspension parameters and engine parameters so I can use those values for tactile feedback.

    The telemetry format in SpaceMonkey can realistically support any number of wheels but Simcommander Simvibe only supports the 4 corners so that's what I'm currently targeting.

    The suspension position value is the local to vehicle z (vertical) coordinate of the wheel. It's a value that can be used to calculate the velocity and acceleration of the wheel vertically, I don't actually care about the position so much as long as it's local to vehicle.

    Simvibe takes the suspension acceleration value and does some math with the oscillation rate of the wheel and turns that into tactile feedback.. so driving on dirt or hitting potholes etc will trigger vibration on a corner when it oscillates over a certain frequency, or spikes in the case of a pot hole.

    Rock crawling and off road feel really good :)

    I think Simvibe may also support the speed of the wheel on each corner relative to the vehicle speed to calculate tactile feedback for skidding tyres and I will experiment with that soon...

    BeamNG and sometimes Dirt Rally 2 are what I play for fun in my simulator so BeamNG will get more support going forward. Are we getting VR at any time in the future? I think my RTX3090 can handle it ;)

    Thanks fufsgen I will make a fix to support UP TO four wheels :)

    I will also add a log to my motionSim.lua file.

    If anyone has suggestions for a better way of calculating that suspension position I would love to hear :)

    Thanks!
     
  5. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    6,782
    You might also need some code to deal with more than 4 wheels, so that game does not break if you drive for example T-series or D-series with dual rears for some odd reason.

    Yeah, that suspension position Z is something of weirdness, I was hoping to get it logged to datafile for simracing telemetry purposes, but it seems not to be very sane value, sometimes does weird things and even moves to wrong direction.

    Anyway, with your code and this thread https://beamng.com/threads/data-collection-and-logging-to-a-file.58863/ I was able to finally get something interesting logged from Beam, huge thanks from this :)

    My dream is to get this to work with Beam:
    https://github.com/Winzarten/SecondMonitor

    As Outsim is not working again in game, I can't get much interesting stuff done, but perhaps on some day I might get things to talk, with my lack of skills that day might be quite far in the future though, but with ability to log to csv I get somewhere at least.
     
  6. PEZZALUCIFER

    PEZZALUCIFER
    Expand Collapse

    Joined:
    Jan 19, 2020
    Messages:
    11
    "Yeah, that suspension position Z is something of weirdness,"
    Agreed, I was looking at it just before and it's not quite right, perhaps that quaternion i'm using to transform into vehicle space is not correct, anyway for now it works ok :)

    Looks like it wouldn't be too complicated to add SpaceMonkey support to SecondMonitor either.

    Looks like you would have to copy one of the existing game implementations and then feed the SpaceMonkey data to the right places in the DataConverter class for the new game type.

    It's all c# so you could reference the CMCustomUDP.dll from SpaceMonkey.

    Use the code here as an example of how to read the SpaceMonkey MMF (or udp if you want to use it on a second machine)
    https://github.com/PHARTGAMES/SpaceMonkey/blob/main/GTPSimfeedback/GTPTelemetryProvider.cs

    Then you will get whatever SpaceMonkey outputs from BeamNG and all the other titles. (defaultPacketFormat.xml)

    You can also then use the same code in SecondMonitor to read telemetry from Dirt Rally 2 and Dirt 4 if you wanted to.

    SpaceMonkey 1.0.5 is just released with those motionSim.lua changes too so you can use the release if you want.

    My name on discord is Pezza#6155 if you want to chat directly.

    Cheers.
     
    • Like Like x 1
  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