Is it possible to have a sound effect play when you begin your your final lap in a quickrace? Perhaps with a lua trigger? I'd like to find a way to play the sound effect when the lap number changes from 2 to 3/3 for example, think it would be a nice touch. Any help is much appreciated.
Of course it's possible with the magic of programing ! So, the tricky part here has been to find the variable containing the number of laps the player chosed to do. But I managed to find how to do it while looking at BeamNG.drive\lua\ge\extensions\scenario\quickRace.lua This code should work, I tested it on the gridmap slalom quickrace : Code: local logTag = 'quickraceSoundAtFinalLap' local finalWaypointName = 'wp_s19' -- The name of the last waypoint, often the same as in the "finishLineCheckpoint" part of the json local lapsLeft = 0 -- Variable that will contain the number of laps the player still has to do local function onRaceStart() local scenario = scenario_scenarios.getScenario() -- get the scenario info, especially the number of laps via the variable scenario.lapCount log('I', logTag,'Laps : ' .. scenario.lapCount) lapsLeft = scenario.lapCount log('I', logTag,'Laps left : ' .. lapsLeft) end local function onRaceWaypointReached(data) -- This function gets called every time a vehicle crosses a waypoint if data.waypointName == finalWaypointName then -- If we crossed the final checkpoint, meaning we finished one lap lapsLeft = lapsLeft -1 -- We tell that we have one less lap to do log('I', logTag,'Laps left to do : ' .. lapsLeft) if lapsLeft == 1 then -- If we have only one lap left Engine.Audio.playOnce('AudioGui','levels/GridMap/testSound.ogg') -- We play the sound effect log('I',logTag,'Sound effect played') end end end return { onRaceStart = onRaceStart, onRaceWaypointReached = onRaceWaypointReached, } To make it work for your quickraces, you need to save this text on a file called 'yourQuickraceName.lua' in levels\yourLevelName. Don't forget to change the finalWaypointName and the sound path on the file according to your case. You can also comment out the log lines, there are here just to see what the games does via the console. Only downside of this is that the custom sound effect will be played over the default checkpoint sound, so you'll hear both at the same time. Feel free to ask any question if there is something in the code you don't understand, or if there's something that doesn't work
Thank you! Though I just tried it, and even if I amplify the sound file in audacity, it's still played very softly. Any way to amplify the sound in the lua file?
Sadly I don't think it's possible to amplify it with lua. It's a long shot, is your audio file in the .ogg format ? Maybe it's that. Else, you'll have to amplify it a lot in audacity I guess