1. Trouble with the game?
    Try the troubleshooter!

    Dismiss Notice
  2. Issues with the game?
    Check the Known Issues list before reporting!

    Dismiss Notice
  3. The BeamNG Team wishes everyone Happy Holidays!
    BeamNG team presence will be limited during the holiday season as we take the time off to rest and enjoy the holidays!
    There will be no mod support or mod approvals from 19th of December until 5th of January. Please expect delays during this period.
    We hope you enjoy the holidays too, see you in 2026!
  4. Before reporting issues or bugs, please check the up-to-date Bug Reporting Thread for the current version.
    0.37 Bug Reporting thread
    Solutions and more information may already be available.

(SOLVED) Street lights at night

Discussion in 'Troubleshooting: Bugs, Questions and Support' started by essej818, Jul 24, 2020.

  1. essej818

    essej818
    Expand Collapse

    Joined:
    Aug 9, 2016
    Messages:
    95
    Anyone know how to get lights to only be enabled at night? I found one script but it seems to be outdated.

    SOLVED:
    I found a lua script from vrcity by Nadeox that I modified.

    I will include the script here, and I will let you know what you need to do to get it to work.

    1. First, make sure you put all the lights you want to be automatic in a group, and name that group something. For this example I will be using the name lights for my group of lights.

    2. Put the attached file into your levels directory, and then open it with an editor (I like notepad++) If for some reason you cant download it, then copy the code below and save it as mainLevel.lua

    It will look like this:


    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.2 and tod.time < 0.8 then
    value = true
    end

    if lastValue == value then return end
    lastValue = value

    if scenetree.GROUPNAME then
    setAllLightsEnabled(scenetree.GROUPNAME, value )
    end
    if scenetree.MissionLights then
    setAllLightsEnabled(scenetree.MissionLights, value )
    end
    end

    M.onUpdate = onUpdate

    return M


    3. the only thing you need to change is replace GROUPNAME with the name of the group of lights you created in step 1. so I would change GROUPNAME to lights, since thats the name i chose.

    I hope this helps anyone that has been looking for this answer.
     

    Attached Files:

    #1 essej818, Jul 24, 2020
    Last edited: Jul 26, 2020
    • Like Like x 4
  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