In reference to this thread here : https://www.beamng.com/threads/point-lights-only-light-up-at-night.23942/ I used this in my maps years ago, but it no longer seems to work. Is there a new method for doing this these days? I would imagine its LUA based now, but I'm not a coder. I would love to get my street lights working again. Any help would be amazing
Like for the map Utah: in the main file of your map, create a mainLevel.lua Inside put something like this Code: local M = {} local function setAllLightsEnabled(group, value) for i = 0, group.obj:getCount(), 1 do local id = group.obj:idAt(i) local obj = scenetree.findObjectById(id) if obj and obj.obj:isSubClassOf('LightBase') then obj.obj:setLightEnabled( value ) end end end local lastValue = nil local function onUpdate() local tod = scenetree.tod if not tod then return end local value = false if tod.time > 0.21 and tod.time < 0.77 then value = true end if lastValue == value then return end lastValue = value end M.onUpdate = onUpdate return M
That's some awesome info, I will have a fiddle about. I was unaware Utah had lights that came on at night. I can at least see how its done now hopefully. I will probably be back in a few hours with a bunch of questions though. haha. Thank you so much!
Ok here comes the questions lol. So I tried putting your code into the mainLevel.lua and no lights came on at night. So I looked at the lua in Utah and it was a little different. It looks like its pointing to the folder in the scene tree where the lights are. My lights are in a folder called dynamiclights and in the Utah map they are in one called auto_repair_lights. So I changed auto_repair_lights to dynamiclights in the levelMain.lua and it still didn't work. Here is the code from Utah Code: local M = {} local function setAllLightsEnabled(group, value) for i = 0, group.obj:getCount(), 1 do local id = group.obj:idAt(i) local obj = scenetree.findObjectById(id) if obj and obj.obj:isSubClassOf('LightBase') then obj.obj:setLightEnabled( value ) end end end local lastValue = nil local function onUpdate() local tod = scenetree.tod if not tod then return end local value = false if tod.time > 0.21 and tod.time < 0.77 then value = true end if lastValue == value then return end lastValue = value if scenetree.auto_repair_lights then setAllLightsEnabled(scenetree.auto_repair_lights, value ) setAllLightsEnabled(scenetree.tourist_center_lights, value ) end end M.onUpdate = onUpdate return and here is what I tried changing it to Code: local M = {} local function setAllLightsEnabled(group, value) for i = 0, group.obj:getCount(), 1 do local id = group.obj:idAt(i) local obj = scenetree.findObjectById(id) if obj and obj.obj:isSubClassOf('LightBase') then obj.obj:setLightEnabled( value ) end end end local lastValue = nil local function onUpdate() local tod = scenetree.tod if not tod then return end local value = false if tod.time > 0.21 and tod.time < 0.77 then value = true end if lastValue == value then return end lastValue = value if scenetree.dynamiclights then setAllLightsEnabled(scenetree.dynamiclights, value ) end end M.onUpdate = onUpdate return I am obviously missing something here, any ideas? --- Post updated --- Ignore me I noticed I was missing the M at the very end. I'm such a noob. Thanks for pointing me in the right direction, I'm so pleased to have it working again