Aller au contenu

Photo

Lights turning on and off at night?


  • Veuillez vous connecter pour répondre
6 réponses à ce sujet

#1
Kossith123

Kossith123
  • Members
  • 96 messages

I'm trying to use this script, but im not 100% sure if I got it right..

 

I have a row of custom lampposts with the tag LampPost, and I placed (I can't find any invisible placeable, so I assume they meant a placeable which you will make invisible, via appearance but I just added a lever underneith a rock with the heartbeat script on.

 

And of course the lights don't work xD

 

I know I ask for a lot of help, but I'm pretty stumped on this situation. I'm not 100% sure what I should do.

 

I'll test putting the heartbeat script on the lamp posts themselves as well.

 

I was also curious if they meant the light it's self, or did they just mean the light, as in the lamp post

 

 

////////////////////////////////////////////////////////////////////////////////
// Automatically turn lights on during the night or off during the day
////////////////////////////////////////////////////////////////////////////////
// Modified By: Stephen M. LaBar, Jr.
// Modified On: 08/07/2002
////////////////////////////////////////////////////////////////////////////////
// Currently this goes into the OnHeartbeat event handler for an invisible
// object located in a module area. For ease of use I named my invisible
// object LightOnOff.
////////////////////////////////////////////////////////////////////////////////
// Make a custom placeable light with the tag LampPost and place it in whatever
// area you want in your module.
////////////////////////////////////////////////////////////////////////////////
void main()
{
object oLamp;
int nNth=0;
oLamp = GetObjectByTag("LampPost", nNth);
int validDay = GetIsDawn() || GetIsDay();
int validNight = GetIsDusk() || GetIsNight();

// This part of the script only runs one time.
if (GetLocalInt (OBJECT_SELF,"RUNONCE") != 1)
{
while (GetIsObjectValid(oLamp))
{
SetLocalInt(OBJECT_SELF,"RUNONCE",1);
PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
SetPlaceableIllumination(oLamp, FALSE);
SetLocalInt(OBJECT_SELF,"NW_L_AMION",0);
RecomputeStaticLighting(GetArea(oLamp));
nNth++;
oLamp = GetObjectByTag("LampPost", nNth);
};
}
// This part of the script only runs once at validNight.
if (validNight && GetLocalInt(OBJECT_SELF, "NW_L_AMION") == 0 )
{
while (GetIsObjectValid(oLamp))
{
PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
SetPlaceableIllumination(oLamp, TRUE);
SetLocalInt(OBJECT_SELF,"NW_L_AMION",1);
RecomputeStaticLighting(GetArea(oLamp));
nNth++;
oLamp = GetObjectByTag("LampPost", nNth);
};
}
// This part of the script only runs once at validDay.
if (validDay && GetLocalInt(OBJECT_SELF, "NW_L_AMION") == 1)
{
while (GetIsObjectValid(oLamp))
{
PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
SetPlaceableIllumination(oLamp, FALSE);
SetLocalInt(OBJECT_SELF,"NW_L_AMION",0);
RecomputeStaticLighting(GetArea(oLamp));
nNth++;
oLamp = GetObjectByTag("LampPost", nNth);
};
}
}



#2
Tchos

Tchos
  • Members
  • 5 063 messages

I haven't used that system, but one invisible object you can use is the standard ipoint placeable.  You should have only one copy of this script in your module, because it searches for all "LampPost" tagged objects in the module and affects them all.

 

I'm not familiar with the function SetPlaceableIllumination.



#3
rjshae

rjshae
  • Members
  • 4 497 messages

I believe the lights can lose information, so you have to grab it right away on area entry. The method I use is to pre-position the lights, store the light objects in an array on the area, then just flip them on or off. There's an example in Vol. IV of the Toolset Guide linked in my sig (called "Toggle Streetlights").



#4
PJ156

PJ156
  • Members
  • 2 985 messages

If you wish to do this then you should of course.

 

However you might want to look at the scripted lighting system on the vault. It has all this functionality already built in giving you time to mess up your head with a different scripting challenge.

 

PJ



#5
Tchos

Tchos
  • Members
  • 5 063 messages

The way I do it is to cycle through all light objects in the area and set them to active or inactive if the time is right.  It could be done with a single ipoint with a custom heartbeat set to a very low heartbeat rate just so that it's not checking every 6 seconds.



#6
Dann-J

Dann-J
  • Members
  • 3 161 messages

I either search for the nearest light object to a particular placeable (for lights that can be turned on or off manually), or I spawn light objects via script and store them as local objects on placeables (including ipoints). Either method avoids the problem of light objects losing their tags when you reload from a saved game.

 

I suspect the placeable illumination script functions are leftovers from NWN. They may not work in NWN2.



#7
Dann-J

Dann-J
  • Members
  • 3 161 messages

Here's a script I'm using at the moment. It runs as a heartbeat script on a single ipoint, and searches for all placeables (also ipoints) in the same area that have a tag of 'nightlight'. Each 'nightlight' ipoint has a string variable that determines what visual effect to spawn (torch flames, brazier fires, etc). The script gets the nearest light to each 'nightlight' ipoint and turns it on or off, so you have to make sure you position light objects manually for each one.

void main()
{
object oArea = GetArea(OBJECT_SELF);
if (oArea != GetArea(GetFirstPC()))
return;

int iDay = GetLocalInt(OBJECT_SELF, "Day");

if (iDay == GetIsDay())
	return;

object oLight;
object oEffect;
int i = 1;
string sEffect;

if (iDay == 1 && !GetIsDay())
	{
	oLight = GetNearestObject(OBJECT_TYPE_PLACEABLE, OBJECT_SELF);
	while(GetIsObjectValid(oLight))
		{
		i++;
		if (GetTag(oLight) == "nightlight")
			{
			sEffect = GetLocalString(oLight, "Effect");
			oEffect = CreateObject(OBJECT_TYPE_PLACED_EFFECT, sEffect, GetLocation(oLight), 0, "LightEffect");
			SetLocalObject(oLight, "EffectObject", oEffect);
			SetLightActive(GetNearestObject(OBJECT_TYPE_LIGHT, oLight),1);
			}//end if nightlight		
		oLight = GetNearestObject(OBJECT_TYPE_PLACEABLE, OBJECT_SELF, i);		
		}//end while	
	SetLocalInt(OBJECT_SELF, "Day", 0);		
	}//end if night
else
	{
	oLight = GetNearestObject(OBJECT_TYPE_PLACEABLE, OBJECT_SELF);
	while(GetIsObjectValid(oLight))
		{
		i++;
		if (GetTag(oLight) == "nightlight")	
			{
			oEffect = GetLocalObject(oLight, "EffectObject");
			SetLightActive(GetNearestObject(OBJECT_TYPE_LIGHT, oLight),0);
			DestroyObject(oEffect);
			DeleteLocalObject(oLight, "EffectObject");
			}//end if nightlight
		oLight = GetNearestObject(OBJECT_TYPE_PLACEABLE, OBJECT_SELF, i);		
		}//end while	
	SetLocalInt(OBJECT_SELF, "Day", 1);
	//Rooster crows
	if (GetTimeHour() < 8)
	AssignCommand(GetFirstPC(), PlaySound("al_an_rooster1", TRUE));		
	}//end if day	
		
}