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!
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
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
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!
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.
Glad you figured it out Here's the post that made me understand what the local M = {} and return M lines means, back I when I was still only a modder : https://www.beamng.com/threads/solved-scenario-lua-not-loading-first-time.27071/#post-388633
How did you code the spotlights to turn on and spin when entering the trigger area? I'm having no problems with emitters but I can't seem to make the spotlights turn on.
Sorry for the late reply @MonstrousManiac , In short, I did it the same way as the confetti cannons, however with the lights I used their, "isEnabled" functionality. So here's an example for ya Code: local M = {} local function onBeamNGTrigger(data) if data.event == 'enter' and data.triggerName == 'monsterExample' then local greenSpin = scenetree.findObject('greenSpinLight') greenSpin.isEnabled = true end if data.event == 'exit' and data.triggerName == 'monsterExample' then local greenSpin = scenetree.findObject('greenSpinLight') greenSpin.isEnabled = false end end M.onBeamNGTrigger = onBeamNGTrigger return M So I have a trigger named, "monsterExample" and then a light with the animation on it called, "greenSpinLight" and the code basically turns it on or off =)
Thank you so much! And no worries. I don't know much about lua and trying to figure it out on my own was impossible. Finally I can experiment with some lights now.
NP at all, I found it was pretty easy to start figuring out things after that point. Open up lua files from the game directory and explore for function names, explore the editor for things you can change: brightness, colour, on/off, etc.. will usually all work out in the code! Have fun =)