Solved Dynamic Lighting on map

Discussion in 'Mod Support' started by EuroTrucker, Aug 21, 2019.

  1. EuroTrucker

    EuroTrucker
    Expand Collapse

    Joined:
    Mar 31, 2014
    Messages:
    159
    Is there a method of setting up dynamic Lighting (lights with only activate at night) on a map?
    I've seen that some maps contain them (Nadeox1's VR_city for example)

    I think it would be a cool addition to the map I'm working on.

    Thanks in advance
    Euro T.
     
    • Agree Agree x 1
  2. EuroTrucker

    EuroTrucker
    Expand Collapse

    Joined:
    Mar 31, 2014
    Messages:
    159
    Solved.
    Used the data from @Nadeox1's VR_city map to create the effect I wanted
    The file I used was mainLevel.lua
    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 = true
        if tod.time > 0.1 and tod.time < 0.5 then
            value = false
        end
    
        if lastValue == value then return end
        lastValue = value
    
        if scenetree.DynamicLights then
          setAllLightsEnabled(scenetree.DynamicLights, value )
        end
        if scenetree.MissionLights then
          setAllLightsEnabled(scenetree.MissionLights, value )
        end
    end
    
    M.onUpdate = onUpdate
    
    return M
     
  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