[LIGHTS] Day/Night Dynamic Lighting Workaround

After numerous attempts at trying to make tileset light and placeable lighting work - lights off in the daytime and on at night, I finally came up with a workaround that appears to work 100% of the time.

  1. Set all tileset source lights to black

  2. Place an invisible object placeable in each source light - set to the XYZ coordinates so it is centered over the light’s holder (I usually change the appearance to “small flame” so I can get the position dead on, then it change it back to “invisible object”

  3. Give the invisible object a unique tag such as “LIGHT_1”

  4. In the Area’s OnEnter script, add this snippet of code:

    //Set the lightsources to "on" at night
    object oLight = GetObjectByTag("LIGHT_1");
    if (!GetIsDay())
    {
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectVisualEffect(VFX_DUR_LIGHT_YELLOW_20), oLight);
        CreateObject(OBJECT_TYPE_PLACEABLE, "plc_flamesmall", GetLocation(oLight), FALSE, "F_LIGHT_1);
    }
    else
    {
        RemoveEffectOfType(oLight, EFFECT_TYPE_VISUALEFFECT);
        DestroyObject(GetNearestObjectByTag("FlameSmall"));
    }

This code handles one light source. You can make it handle multiple lights by adding a for loop in the “if” and “else” statements, searching for “LIGHT_”+INT and “F_LIGHT_”+INT respectively.

So, what’s the benefit?

  1. You can now have tileset source lights that actually function as they are supposed to, transitioning for day/night, as opposed to only working some of the time - if at all.

  2. There is no need to RecomputeStaticLighting, as it is done automatically when the “light” VFX is applied. This might also resolve the crashing issue that people are experiencing when they use RecomputeStaticLighting in an area with “fancy mapped” objects.

6 Likes

Nice, I already did this a long time ago for my HR base 10.75 including with all sorts of colors and did a write up on it. I also included some flare options. Thanks for reminding me I forgot to include the flare options in other releases after 10.75 so I will add it back in in my next release. I have not experienced any crashes with RecomputeStaticLighting and the new fancy maps or it not consistently working. Good luck with your project.

I like this idea. For my own PW I’ll probably fire it as a psuedo heart beat from the OnEnter event as folks often linger in areas long enough for the day night cycle to change. Just a few checks added like - Is the light already created and its night = do nothing … and Oooo, its daytime now = destroy the light. Heck, it could even be adapted for NPCs that wander out when fired to light lamp posts.

Wow! After going back and doing some more recent test, RecomputeStaticLighting function really sucks now. It give all sorts of weird shadows when working with multiple lighting sources that I do not remember it doing way back in the day. I hope the new render engine can fix this or a fix to the function.

I added an OnHeartbeat to handle day/night transitions that occur when the PC is in the village area. Rather than check GetIsNight() or GetIsDay(), I opted to use GetTimeHour() and set each check to an hour after Dawn/Dusk. Using GetIsNight() and GetIsDay() my son was getting a brief hiccup in his FPS on his ancient PC.

1 Like

Yeah, its a mess.