1. Stuck, Having problems with creating your mod? Let us help you: Mod Support

LUA Trigger Area

Discussion in 'Content Creation' started by krallopian, Jan 11, 2019.

  1. krallopian

    krallopian
    Expand Collapse

    Joined:
    Dec 5, 2013
    Messages:
    129
    I saw a thread recently about LUA triggers, something like, "enter this area and trigger gravity to XX" and was just thinking,

    Is this a method you could use to say enter an area and trigger lights or particles? I.E. "On enter, trigger light_01, Light_02, Light_03, ON, & particle 1, 2, ON, else all off" typa thing?

    Thanks!
     
  2. RyvyLo

    RyvyLo
    Expand Collapse
    Staff Member

    Joined:
    May 15, 2014
    Messages:
    427
    This should be possible indeed, it is done in the lua of the Autobello showcase scenario for example

    The trigger code should look like this :
    Code:
    local particuleEffect = scenetree.findObject('particuleEffectObject')
    
    particuleEffect.active = true
    
     
    • Informative Informative x 1
  3. krallopian

    krallopian
    Expand Collapse

    Joined:
    Dec 5, 2013
    Messages:
    129
    Awesome! I'll look for the showcase scenario and check it out, thank you very much RyvyLo - I assume I'll be posting back with more questions as a result though ahah
    --- Post updated ---
    Wow, this is basically EXACTLY what I need:

    l
    Code:
    local function onBeamNGTrigger(data)
    
      if data.event == 'enter' and data.triggerName == 'confetti_trigger' then
    
      local confettiCanon0 = scenetree.findObject('confetti_canon0')
      local confettiCanon1 = scenetree.findObject('confetti_canon1')
    
      confettiCanon0.active = true
      confettiCanon1.active = true
    
      end
    end
    Incredible! I've just learned so much in so little time =D Well no, I've just had my eyes opened much wider.
    --- Post updated ---
    Well I've found where I'm getting stuck.

    1.) Basically, where do I put my .lua file and how is it called?
    2.) Do they only work if you start a scenario instead of freeroam?
    3.) Do I trigger the particle emitter or the particle emitter or particle emitter node?
    4.) The LUA Trigger is called "confetti_trigger" and calls a blank luaFunction, which I understand defaults to, "onBeamNGTrigger" is this a function specific name, or can I call it something unique, "myOwnTriggerName" and if so... aaahhh there are too many unknowns right now I'll keep searching around but Google's only been so helpful on the matter imo.

    Long story short, I want to enter "finishLine" and have it activate two confetti particle jobbies, and eventually some disco lights etc.. the issue is, where do I put the LUA file, and do I always have to be in a scenario in order for it to work?

    Thanks a lot - if I find the answer I'll post it here of course.



    ***

    I've made a "confetti_trigger.lua" and placed it in the root dir (levels\mylevelname) and then also made a scenarios dir called, "levels\mylevelname\scenarios" and places the lua there.

    No go =D

    Something so simple, and I'm just missing the basics ANNND it's Friday so not looking good for a staff answer :(
     
    #3 krallopian, Jan 12, 2019
    Last edited: Jan 12, 2019
  4. krallopian

    krallopian
    Expand Collapse

    Joined:
    Dec 5, 2013
    Messages:
    129
    I changed the script, learned to save it as "mainLevel.lua" and put it in my level's root directory (\levels\mylevel\mainLevel.lua) and it didn't work.

    Then I saw one of the scripts in West Coast USA had a line in it, added it, and presto IT WORKS!!! I MADE A THING!!

    Code:
    local M = {}
    
    
    local function onBeamNGTrigger(data)
    
      if data.event == 'enter' and data.triggerName == 'confetti_trigger' then
    
      local confettiCanon0 = scenetree.findObject('confetti_canon0')
      local confettiCanon1 = scenetree.findObject('confetti_canon1')
    
      confettiCanon0.active = true
      confettiCanon1.active = true
    
      end
    end
    
    M.onBeamNGTrigger = onBeamNGTrigger
    return M
    
    
    
    So it was the line, "M.onBeamNGTrigger = onBeamNGTrigger" and I don't what that does. I also don't understand the local M = {} and return M lines.

    Regardless, it does what I need, now to make an ELSE and see if that'll work to turn'm back off. Look at me, look at me! =D
    --- Post updated ---
    No luck with else and elseif using the following code:

    Code:
    local M = {}
    
    
    local function onBeamNGTrigger(data)
    
      if data.event == 'enter' and data.triggerName == 'confetti_trigger' then
    
      local confettiCanon0 = scenetree.findObject('confetti_canon0')
      local confettiCanon1 = scenetree.findObject('confetti_canon1')
     
     confettiCanon0.active = true
      confettiCanon1.active = true
      elseif data.event == 'exit' and data.triggerName == 'confetti_trigger' then
      confettiCanon0.active = false
      confettiCanon1.active = false
     
      end
    end
    
    M.onBeamNGTrigger = onBeamNGTrigger
    return M
    --- Post updated ---
    Put some thought in to it and realized that maybe I should make a second function. Did that, they turned on, then off! Then.. never on again.

    SO I wrote the second function before the END as I realized it's calling the ONE function called "onBeamNGTrigger" which I guess could be anything I want..

    Anyway IF YOU WANT confetti that works by driving into a zone and then turns off when you leave the zone, here y'ar!

    Code:
    local M = {}
    
    
    local function onBeamNGTrigger(data)
    
      if data.event == 'enter' and data.triggerName == 'confetti_trigger' then
    
      local confettiCanon0 = scenetree.findObject('confetti_canon0')
      local confettiCanon1 = scenetree.findObject('confetti_canon1')
     
     confettiCanon0.active = true
      confettiCanon1.active = true
    
      end
      if data.event == 'exit' and data.triggerName == 'confetti_trigger' then
    
      local confettiCanon0 = scenetree.findObject('confetti_canon0')
      local confettiCanon1 = scenetree.findObject('confetti_canon1')
     
     confettiCanon0.active = false
      confettiCanon1.active = false
     
      end 
    end
    
    M.onBeamNGTrigger = onBeamNGTrigger
    return M
    --- Post updated ---
    Here's a sneaky sneak preview!

     
  5. Danny Werewolf

    Danny Werewolf
    Expand Collapse

    Joined:
    Mar 31, 2017
    Messages:
    1,395
    Don't know what everything else means, but OH MY GOOD GOLLY GOODNESS GOLLY GAWD, I CAN'T WAIT FOR THIS TO BE USED MORE.
     
    • Agree Agree x 1
  6. RyvyLo

    RyvyLo
    Expand Collapse
    Staff Member

    Joined:
    May 15, 2014
    Messages:
    427
    • 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