Solved Lua triggers in scenarios

Discussion in 'Mod Support' started by Darthbob555, Dec 19, 2016.

  1. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    290
    I want to have a choice of routes in my scenario so that when the player drives through path A, the waypoints now correspond to path A. Likewise, if the player goes through path B, the waypoints should correspond to path B.
    I noticed in the map editor under "Level" there is such a thing as "BeamNG Lua Trigger". However, I do not know when this is triggered and how to get it to call a function in the lua file. I assume it is triggered when a car drives through it similarly to how a waypoint works.

    Any help would be much appreciated.
     
  2. RyvyLo

    RyvyLo
    Expand Collapse

    Joined:
    May 15, 2014
    Messages:
    438
    Lua triggers calls a function named onBeamNGTrigger when a vehicle enters and when a vehicle leaves the trigger. ( or at least they do it then the luaFunction parameter is set to onBeamNGTrigger, like the lua triggers in the campaign scenarios )

    You can then call custom actions using a code similar to the one used for waypoint trigger detection
    Code:
    local function onBeamNGTrigger(data)
    
        if data.parameter == 'parameterName' then
            doSomething()
    
        end
    end
    
    return {
       onBeamNGTrigger = onBeamNGTrigger,
    }
    
    The lua trigger's most useful parameters are :
    - event (parameterName ="enter" or "exit"),
    - triggerName (the name of the trigger),
    - subjectName ( "scenario_player0" for example)
     
  3. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    290
    Thank you very much; this works perfectly! :D
     
  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