Hello, I’m developing a mod that plays a warning sound when the vehicle experiences a radiator leak. I'm looking for a reliable way to detect radiator or coolant system damage in order to trigger an alert. Any suggestions or insights would be greatly appreciated. This is the code I used: Code: local M = {} local soundNode = 0 local leakAlertPlayed = false local function onInit() -- Get a reference point in the vehicle to attach the sound to (like the first node) if v.data and v.data.refNodes and v.data.refNodes[0] then soundNode = v.data.refNodes[0].ref else log("E", "RadiatorLeakAlert", "No valid ref node found!") end -- Create a 3D sound source obj:createSFXSource2("/art/sound/Alarm.wav", "Audio2D", "radiatorLeakAlert", soundNode, 0) end local function onUpdate(dt) if not playerInfo.anyPlayerSeated then return end if not leakAlertPlayed and damageTracker.getDamage("engine", "radiatorLeak") then log("I", "RadiatorLeakAlert", "Radiator leak value: " .. tostring(damageTracker.getDamage("engine", "radiatorLeak"))) obj:playSFXOnce("radiatorLeakAlert", soundNode, 1, 1) leakAlertPlayed = true log("I", "RadiatorLeakAlert", "Radiator leak detected! Sound alert triggered.") end end M.onInit = onInit M.onUpdate = onUpdate return M I also made sure to put my code in: /lua/vehicle/extensions/auto/ The code won't even run. Thank you.
damageTracker is a global provided for the vehicle environment only and does not need to be required. You're using a game engine Lua script which does not have access to vehicle side globals. Since you do not need a separate GE extension in this case, you can just move it into the vehicle. Those are stored here: /lua/vehicle/extensions/ - available for all vehicles (put in /lua/vehicle/extensions/auto/ for automatic loading in all vehicles) /vehicles/.../lua/ - available only for the vehicle the lua folder is inside of (always loads automatically). In this case you'd want a script that loads for all vehicles, but only runs on the currently active one. playerInfo.anyPlayerSeated is a global you can use to check for that. You will also need to change the API for sounds to the VLua one. Code: local soundNode = 0 This needs to only run once. Code: soundNode = v.data.refNodes[0].ref obj:createSFXSource2("/art/sound/Alarm.wav", "Audio2D", "radiatorLeakAlert", soundNode, 0) This then plays the sound. Code: obj:playSFXOnce("radiatorLeakAlert", soundNode, 1, 1) No. radiatorLeak is a valid flag and also the flag every other part of the UI uses for this purpose.