Lights by night

Hello !
How could I make a light glow only at night ?
For a town, that would be realistic and beautiful… and weird if there’s no light at all by night.
Thanks, and good luck for your confinement, if your country is in it.

You have to do them from the ToolSet.
You can select the color, the intensity, the light distance, etc.


3 Likes

I don’t get it. In the pictures it seems that the light is on all the time, night as well as day. Do you have to do some scripting, perhaps setting “On?” to “FALSE”? Or am I stupid? :woozy_face:

Yes, it is always “On”, unlike sounds for which it is possible to manually adjust their hours of activity. To deactivate a local light source, you have to go through a script.
What must be done is to adjust the intensities of each type of light you create, so that it does not appear too much during the day. Normally, they don’t cause any inconvenience and rarely have I used scripts to turn them off in a city for example. It’s also possible to create light source that will light up and go out if the player clicks on them, which I use in my modules, for example in the undergrounds to explore.

EDIT:

Disable “cast shadow” if you have a lot of light source in the same area. You will reduce the lag enormously.
For example, if you have a tavern that has several light sources in the same place, place these lights which have the “cast shadow” at off and then place in the center of the area a lower intensity light source, but which covers the entire area with the “cast shadow” at On. [See picture → Big Red bubble are “global light source area”].


4 Likes

Yep. I’ve disabled “cast shadow” in the areas I’ve used before quite often. For some reason in NWN2 there tend to be too much shadows when adding light sources by default. So often you have to go to each individual light and reduce the shadows they cast, or at least test different settings to make it look somehow natural.

2 Likes

What’s this area with blue houses and walls?

It’s an area for a friend I’m working on and I hope should finish soon.

2 Likes

Use both of the following basic scripts to turn on lights at night and off during the day.

/*
	Place this on the Area OnClientEnter handler. 
	Change the "lt_white" string to the tag of your light sources.
*/

const string AREA_LIGHT = "light_";

void LightSwitch(int bSwitch)
{
	int n;
	 
	for (n = 0; n >= 0; n++)  
	{
		object oLight = GetLocalObject(OBJECT_SELF, AREA_LIGHT + IntToString(n));
	
		if (!GetIsObjectValid(oLight)) return;
		
		SetLightActive(oLight, bSwitch);
	}
}

void main()
{
	object oArea = OBJECT_SELF;
	
	if (!GetLocalInt(oArea, "DoOnce"))
	{
		SetLocalInt(oArea, "DoOnce", TRUE);
	
		int n;
	 
		for (n = 0; n >= 0; n++)  
		{
			object oLight = GetNearestObjectByTag("lt_white", GetFirstPC(), n);
			
			if (!GetIsObjectValid(oLight)) break;
	
			SetLocalObject(oArea, AREA_LIGHT + IntToString(n), oLight);
		}		
	}

	if (!GetIsDay()) LightSwitch(TRUE);
		
	else LightSwitch(FALSE);
}

and

/*
	Place this on the Area OnHeartbeat handler.
*/

void LightSwitch(int bSwitch)
{
	int n;
	 
	for (n = 0; n >= 0; n++)  
	{
		object oLight = GetLocalObject(OBJECT_SELF, "light_" + IntToString(n));
	
		if (!GetIsObjectValid(oLight)) return;
		
		SetLightActive(oLight, bSwitch);
	}
}

void main()
{
	if (GetIsDusk()) LightSwitch(TRUE);
		
	else if (GetIsDawn()) LightSwitch(FALSE);
}

EDIT: updated scripts to use set/get local objects for lights because light objects lose their tag on reload and module transitions.

6 Likes

For lights, the first time a player enters, I use a script to store the light objects. Thereafter I manage the lights using the objects. (IIRC, the lights can lose their tag information with a save or an exit/re-enter.)

3 Likes

another possibility →

object oArea = OBJECT_SELF;
object o = GetFirstObjectInArea(oArea);
while (GetIsObjectValid(o))
{
   if (GetObjectType(o) == OBJECT_TYPE_LIGHT) // && GetLocalInt(o, "hasDayNightSwitch")
        SetLightActive(o, bActive);

    o = GetNextObjectInArea(oArea);
}
4 Likes

Yes, there are problems with lights …

I use both the methods described by rjshae and KevL.

There are also problems with some light items being carried by PCs too. It’s been such a long time since I looked at this, but basically, items that also produce light will stop working in a similar manner. This is why I replace “light items” when a player leaves and enters areas (iirc - maybe module). Very old blog on the light issue here.

Cheers, Lance.

2 Likes

I tested this and sure enough, lights lose their tags on a reload and module transitions. They are ok on area transitions within the same module, though.
I updated the scripts above to use set/get local objects. They seem to work fine in testing.

3 Likes