How do you detect radiator leak in Lua? (Help still needed)

Discussion in 'Content Creation' started by Jack The Fox, Apr 16, 2025.

  1. Jack The Fox

    Jack The Fox
    Expand Collapse

    Joined:
    Jan 22, 2025
    Messages:
    21
    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.
     
    #1 Jack The Fox, Apr 16, 2025
    Last edited: Apr 18, 2025
  2. DaddelZeit

    DaddelZeit
    Expand Collapse

    Joined:
    Jul 17, 2019
    Messages:
    3,472
    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.
     
    • Like Like x 1
  3. Jack The Fox

    Jack The Fox
    Expand Collapse

    Joined:
    Jan 22, 2025
    Messages:
    21
    Thanks a lot! I tried it and it didn't work though :(. I think I misunderstood let me try again.
     
    #3 Jack The Fox, Apr 17, 2025
    Last edited: May 8, 2025
  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