How to exclude traffic AI vehicles from activating a LUA trigger?

Discussion in 'Programming' started by ltntai, Nov 2, 2023.

  1. ltntai

    ltntai
    Expand Collapse

    Joined:
    Mar 18, 2017
    Messages:
    671
    Or in other words how should I modify these scripts so that only player vehicle can activate them?
    The triggers are supposed to turn daylight on and off for extra dark tunnel experience, and they do, but traffic cars keep flickering the light.
    screenshot_2023-11-02_22-38-46.png screenshot_2023-11-02_22-39-46.png
    I tried many ways of adding data.subjectName or subjectID info in it without success.

    Code:
    local function sunsky(data)
     local obj = scenetree.findObject("sunsky")
     if obj then
        if data.event == 'enter' then
            obj:setHidden(true)
        end
     end
    end
    return sunsky
     
  2. r3eckon

    r3eckon
    Expand Collapse

    Joined:
    Jun 15, 2013
    Messages:
    595
    It should work if you add "and data.subjectID == be:getPlayerVehicleID(0)" to your condition, if not try dump(data) to see the table contents maybe that will give you a clue what's going on. The subjectID works fine, I used it in a more complex trigger handling script that keeps track of trigger enter/exit state for specific vehicles in a table, also because I needed to ignore traffic vehicles. The 'data' table is passed through onBeamNGTrigger hook, I don't know if the custom lua function set in the trigger parameters could be causing issues.
     
    • Like Like x 1
  3. ltntai

    ltntai
    Expand Collapse

    Joined:
    Mar 18, 2017
    Messages:
    671
    It works like a charm. Thank you so much!
    Code:
    local function sunsky(data)
     local obj = scenetree.findObject("sunsky")
     if obj then
        if data.event == 'enter' and data.subjectID == be:getPlayerVehicleID(0) then
            obj:setHidden(true)
        end
     end
    end
    return sunsky
     
    • 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