Released [TUTORIAL] Unique engine sounds for vehicles

Discussion in 'Programming' started by Fireboyd78, Jul 18, 2014.

  1. Fireboyd78

    Fireboyd78
    Expand Collapse

    Joined:
    Aug 5, 2013
    Messages:
    85
    Tired of having to switch between different engine sound mods just to use the sound you really want? Fret not! With this simple tutorial, you can add any engine sound you want to any vehicle!

    Before attempting any of this, be sure to download the patch that is attached to this post. There's also an example for the Moonhawk provided as well, demonstrating that this really does work!

    Without further ado, here's how it works (we'll be using the Moonhawk as an example):

    1) Download the 'moonhawk_engine.ogg' file and place it in your 'vehicles/moonhawk' folder. Alternatively, you can download the attached example.

    2) Create a new file called "sounds.cs" in the folder of where your vehicle is located:

    vehicles/moonhawk/sounds.cs:
    Code:
    singleton SFXProfile(MoonhawkEngine)
    {
       fileName = "vehicles/moonhawk/moonhawk_engine.ogg";
       description = "AudioDefaultLoop3D";
    };
    Everything should be self-explanatory. In this case, our new engine sound is called MoonhawkEngine. We then link to an .ogg file containing our engine sound (paths must be fully qualified, i.e. 'vehicles/<carname>/<soundFileName>.ogg').
    Don't change the 'description' property!

    You can define as many of these as you want, for example:

    Code:
    singleton SFXProfile(MoonhawkEngine)
    {
       fileName = "vehicles/moonhawk/moonhawk_engine.ogg";
       description = "AudioDefaultLoop3D";
    };
    
    singleton SFXProfile(MoonhawkEngineBeefy)
    {
        fileName = "vehicles/moonhawk/moonhawk_engine_beefy.ogg";
        description = "AudioDefaultLoop3D";
    }
    3) Next, in your JBeam, preferably one that defines the engine(s) for the vehicle, set it up like so:

    vehicles/moonhawk/moonhawk_engine.jbeam (~line 40):
    Code:
    "engine":{
            "engineSound":"MoonhawkEngine",
            "idleRPM":700,
            "shiftDownRPM":1800,
            "shiftUpRPM":4200,
            "maxRPM":4500,
            "inertia":0.17,
            "friction":28
            "brakingCoefRPS":0.15
            "burnEfficiency":0.30
            "throttleSensitivity":1.5
            "torqueReactionNodes:":["e1l","e2l","e4r"]
        },
    We add a new field callled 'engineSound', which is the name of the SFXProfile you defined in 'sounds.cs'.
    NOTE: The 'engineSound' property is optional and does not take a filename, but rather the name of an SFXProfile that is currently defined. The default is 'EngineTestSound'.

    You can also define a default "global" engine sound by going to the primary JBeam and doing so:

    vehicles/moonhawk/moonhawk.jbeam (~line 85):
    Code:
    "engine":{
            "engineSound":"MoonhawkEngine"
            "onBeamBreakDisableDriveshaft":["driveshaft"]
            "waterDamage": {"[engineGroup]:":["moonhawk_engine_intake"]}
        },
    This allows for the specified sound to be the default unless overridden by new engine types!

    Now when the Moonhawk has the '378 CUI V8 Engine', it'll use our custom sound! For practice, try adding a new sound for the 'Supercharged 378 CUI V8 Engine' ;)

    Enjoy!

    UPDATE: I've included a "generic" sound pack that gives unique sounds for the D15, Bolide, and Moonhawk. A great example of custom sound packs! (Credits to Nemesis' sound pack for the D15 and Bolide sounds)
     

    Attached Files:

    #1 Fireboyd78, Jul 18, 2014
    Last edited: Jul 19, 2014
    • Like Like x 1
  2. Leet34

    Leet34
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    236
    This is great ! Wuv you <3
     
  3. Rokzy rules

    Rokzy rules
    Expand Collapse

    Joined:
    Dec 31, 2013
    Messages:
    379
    this deserves a......


    Bump.gif
     
    • Agree Agree x 1
  4. logoster

    logoster
    Expand Collapse

    Joined:
    Sep 5, 2012
    Messages:
    2,082
    this is awesome :)
     
  5. DrowsySam

    DrowsySam
    Expand Collapse

    Joined:
    Jul 30, 2013
    Messages:
    964
    Make this without editing the global lua files if possible :) BeamNG supports custom lua per vehicle now, eg. hatch/lua/sounds.lua.

    You should see if that's possible, because I'm not sure(Lua noob). Ah well, worth a try :)
     
  6. Fireboyd78

    Fireboyd78
    Expand Collapse

    Joined:
    Aug 5, 2013
    Messages:
    85
    This method is much easier and requires less work. Having a lua file just for custom engine sounds would cause compatibility issues.
     
  7. iheartmods

    iheartmods
    Expand Collapse

    Joined:
    Aug 8, 2012
    Messages:
    1,482
    It's simple. It's easy. 101379-Jim-Carrey-I-like-it-alot.gif
     
  8. Fireboyd78

    Fireboyd78
    Expand Collapse

    Joined:
    Aug 5, 2013
    Messages:
    85
    OP updated, generic sound pack now included! I might see if there's a way to assign engine sounds via Lua instead of modifying the JBeam files.
     
  9. DrowsySam

    DrowsySam
    Expand Collapse

    Joined:
    Jul 30, 2013
    Messages:
    964
    I'll love you forever if you pull it off <3
     
  10. Fireboyd78

    Fireboyd78
    Expand Collapse

    Joined:
    Aug 5, 2013
    Messages:
    85
    You'd have to look in the 'sounds.lua' file to understand why it's pretty much impossible to pull off. And not only that, but it would break the ability to add an 'engineSound' property to a JBeam.

    Ideally, this sort of system should be implemented into BeamNG anyways :p

    Besides, it's not like I'm changing any major functionality...

    Old code:
    Code:
    if engineSound == nil then
        engineSound = createSFXSource("EngineTestSound")
    end
    New code:
    Code:
    if engineSound == nil then
        engineSound = createSFXSource(v.data.engine.engineSound or "EngineTestSound")
    end
    It really was that easy.

    EDIT: This is why you don't program at 3 in the morning...:p

    Code:
    // Unique vehicle sounds mod
    // by Fireboyd78
    // Last updated: 7/18/2018
     
    #10 Fireboyd78, Jul 19, 2014
    Last edited: Jul 19, 2014
  11. Mr.Hankey

    Mr.Hankey
    Expand Collapse

    Joined:
    Aug 9, 2012
    Messages:
    29
    Hey Fireboyd78 I hope you don't mind if i kind of steal your topic here but I actually managed to pull off the "impossible".

    Yesterday in Skype DrowsySam was whining so much about this mod modifying the stock lua files that I gave it a shot and worked out a way to do it.

    What you basically have to do is this:

    1. Go to your vehicles folder (e.g vehicles/hatch)
    2. Create a new folder called "lua" in there. This is the new per-vehicle lua feature so every script in that folder gets loaded with the vehicle.
    3. Put the attached custom_sounds.lua in that folder. This contains your modified copy of the sounds.lua code and replaces it on initilization.
    4. Edit your vehicle's name.cs to create the SFXProfile for you. Example for the Covet
      Code:
      %vehicleName = "Ibishu Covet";
      
      singleton SFXProfile(HatchEngine)
      {
         fileName = "vehicles/hatch/moonhawk_engine.ogg";
         description = "AudioDefaultLoop3D";
      };
      (very hacky I know)
    5. Place an audio file in the proper directory that you have defined above.
    6. Edit the .jbeam as explained in the first post to point to your custom SFXProfile.

    That should be all and you are now able to release your vehicles including custom sounds without any modification of stock script files.

    I've also attached a complete example for the Covet. Just extract it inside vehicles/hatch/
     

    Attached Files:

  12. Fireboyd78

    Fireboyd78
    Expand Collapse

    Joined:
    Aug 5, 2013
    Messages:
    85
    I don't see why there's any need to freak out over having to modify a global lua file. If people decide to include it in their mods, the people who install it can install the sound mod at their own discretion.

    With the per-vehicle mod, if people decide to include it, it would require every single vehicle using the mod to update their "custom_sounds.lua" file whenever the BeamNG team decides to update 'sounds.lua'. And not only that, but using the 'name.cs' file to setup custom sounds is hacky. I am not a big fan of that myself.

    On top of that, you lose the capability to place sounds in 'vehicles/common' and have them shared across multiple vehicles. Not a very good tradeoff...

    If we can't release mods editing global files, then why let us edit the files? Just because we have per-vehicle lua now doesn't mean we shouldn't edit the other files in the game.

    /rant
     
    #12 Fireboyd78, Jul 19, 2014
    Last edited: Jul 19, 2014
  13. vladmir poopin

    vladmir poopin
    Expand Collapse
    Banned

    Joined:
    Mar 17, 2013
    Messages:
    844
    ok i cant get this to work none of the cars have sound now?
    all i got is the wind/tires sound
    what did i do rong?
    or can someone upload the vehicles that have the sound on.
     
  14. Fireboyd78

    Fireboyd78
    Expand Collapse

    Joined:
    Aug 5, 2013
    Messages:
    85
    Which files did you download? Reinstall the patch and download the "soundpack-generic.zip" attachment. Replace files if prompted.
     
  15. vladmir poopin

    vladmir poopin
    Expand Collapse
    Banned

    Joined:
    Mar 17, 2013
    Messages:
    844
    i did all three none of them are working and i get a error when i load up a map but i cant see it but my pc goes BING BING.
     
  16. Fireboyd78

    Fireboyd78
    Expand Collapse

    Joined:
    Aug 5, 2013
    Messages:
    85
    Since I don't know what all it is that you have done to your game, my only other suggestion is to force update the game. Make sure the game runs after this, then try reinstalling the mod. Don't install the Moonhawk example if you just want to have the sound pack I made.
     
  17. vladmir poopin

    vladmir poopin
    Expand Collapse
    Banned

    Joined:
    Mar 17, 2013
    Messages:
    844
    where do i put the actual sounds do i put them in vehicles-common?
     
  18. Miura

    Miura
    Expand Collapse

    Joined:
    Aug 5, 2012
    Messages:
    311
    I've done custom sounds by copying the default sounds.lua to the vehicle's lua folder and adding new entries to art\datablocks\audioProfiles.cs. Looks like I can move the new sound profiles to name.cs now, no need to edit any default files that get reset in updates.

    Custom lua for sounds is quite complex, but you're not limited to just one sample for the engine and you can make the sounds work the way you want, if you can code it.

    Some official support for custom sounds would be good, even as a placeholder until the sounds are redone properly. I don't even feel like driving cars with default sounds anymore after doing new sounds for a few of my cars.
     
  19. Fireboyd78

    Fireboyd78
    Expand Collapse

    Joined:
    Aug 5, 2013
    Messages:
    85
    The zip file is set up so that you drag the "vehicles" folder over the one in your BeamNG installation.
     
  20. vladmir poopin

    vladmir poopin
    Expand Collapse
    Banned

    Joined:
    Mar 17, 2013
    Messages:
    844
    oh COCK <james may quote
    i have been putting them into the common folder:p

    - - - Updated - - -

    that still didnt work.
     
  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