In an area I’ve been working on, I wanted it to start black (no lighting) then use a placeable chain to turn on some wall sconces. With the help of a script I found, I had all that working perfectly. However when the PC enters that area, sometimes the lights are all on when they shouldn’t be. Sometimes it happens OnEnter, sometimes it happens when a cutscene fadeout, fades back in. It should only happen with the use of the chain. Is this a known bug? I probably shouldn’t agonize over these little details but it seems to work pretty reliably when I start in the area itself and not enter from another area. Or maybe it is working more reliably when I don’t just F9 from the toolset but quit that and start as a new game. I may have to try that one again from start of module (different area).
It would help if we could see the script or at least know how it is firing. Is it firing off a tag based event or from the use of one of the placeables or other means.
For trying to debug it, you could start by finding out if the script is firing when you don’t want it to. You can find out when the script if firing by turning on the script logging option in nwnplayer.ini
Under
[Script Options]
Enable Logging=0
Change the 0 to a 1
this will log every script that runs into the log file.
The placeable lights are being activated or deactivated by tag in a loop. The mere presence of this script on a switch placeable in the area may be affecting tile lighting somehow, because when I remove it from on use so there is no area lighting available, the tile lighting doesn’t somehow illuminate. Here’s the script:
//::///////////////////////////////////////////////
//:: Name n_am_ou_lswitch
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
Turns all lights (tag “am_light”) in area on/off. If
these are light objects (like a chandelier); set this int
Properties/Advanced/Variables of the light object:
IS_STANDARD_LIGHT int 1
*/
//:://////////////////////////////////////////////
//:: Created By: nereng
//:: Created On: 14/11/2004
//:://////////////////////////////////////////////
void main()
{
// Get the creature who triggered this event.
object oPC = GetLastUsedBy();
object oSelf = OBJECT_SELF;
object oArea = GetArea(OBJECT_SELF);
object oObject = GetFirstObjectInArea(oArea);
effect eLight = EffectVisualEffect(VFX_DUR_LIGHT_ORANGE_5);
// If the local int is exactly 1.
if ( GetLocalInt(oPC, “LightsOnOk”) == 1 )
{
if (GetLocalInt(OBJECT_SELF,“CEP_L_AMION”) == 0) //It’s off; lights on!
{
AssignCommand(oSelf, ActionPlayAnimation(ANIMATION_PLACEABLE_ACTIVATE));
ActionPlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
SetLocalInt(OBJECT_SELF,“CEP_L_AMION”,1);
// Loop all objects in the area
while(GetIsObjectValid(oObject))
{
if (GetTag(oObject) == "ZEP_OSCONCE002")
{
if (GetLocalInt(oObject, "CEP_L_LIGHTCYCLE") == 1)
{
//* If this is a standard lightsource, like a chandelier
AssignCommand(oObject, ActionPlayAnimation(ANIMATION_PLACEABLE_ACTIVATE));
SetPlaceableIllumination(oObject, TRUE);
}
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eLight, oObject);
}
oObject = GetNextObjectInArea(oArea);
}
DelayCommand(0.6,RecomputeStaticLighting(GetArea(OBJECT_SELF)));
}
else //It's on; lights off!
{
AssignCommand(oSelf, ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
SetLocalInt(OBJECT_SELF,"CEP_L_AMION",0);
while(GetIsObjectValid(oObject)) //check all objects
{
if (GetTag(oObject) == "ZEP_OSCONCE002")
{
if (GetLocalInt(oObject, "CEP_L_LIGHTCYCLE") == 1)
{
//* If this is a standard lightsource, like a candelabra
AssignCommand(oObject, ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
SetPlaceableIllumination(oObject, FALSE);
}
effect eEffect = GetFirstEffect(oObject);
while (GetIsEffectValid(eEffect) == TRUE)
{
if (GetEffectType(eEffect) == EFFECT_TYPE_VISUALEFFECT)
RemoveEffect(oObject, eEffect);
eEffect = GetNextEffect(oObject);
}
}
oObject = GetNextObjectInArea(oArea);
}
DelayCommand(0.6,RecomputeStaticLighting(GetArea(OBJECT_SELF)));
}
}
}
It sounds very odd that the light switch script is getting triggered during screen fades. I can’t seem to reproduce the issue, but if the problem is fixed if the script is not directly linked to the placeables (and you don’t need them to be manually toggleable by the player) you could just take the on/off script away from the placeables and run the turn on/off loop from elsewhere.
I’d try looking at the script that’s doing the screen fade, and possibly the area OnEnter and OnExit, too, see if there are placeable events being signalled anywhere.
void SwitchAllLights(int nOn=TRUE, object oArea=OBJECT_INVALID)
{
string sTag;
object oTarget = GetFirstObjectInArea(oArea);
while (oTarget != OBJECT_INVALID)
{
sTag = GetStringUpperCase(GetTag(oTarget));
if (GetLocalInt(oTarget, "IS_STANDARD_LIGHT") ||
sTag == "AM_LIGHT" ||
sTag == "CANDELABRA")
{
// Switch on.
if (nOn)
{
SetLocalInt(oTarget, "NW_L_AMION", TRUE);
SetLocalInt(oTarget, "CEP_L_AMION", TRUE);
AssignCommand(oTarget, ClearAllActions());
AssignCommand(oTarget, PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE));
SetPlaceableIllumination(oTarget, TRUE);
ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectVisualEffect(VFX_DUR_LIGHT_ORANGE_5), oTarget);
}
// Switch off.
else
{
SetLocalInt(oTarget, "NW_L_AMION", FALSE);
SetLocalInt(oTarget, "CEP_L_AMION", FALSE);
AssignCommand(oTarget, ClearAllActions());
AssignCommand(oTarget, PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
SetPlaceableIllumination(oTarget, FALSE);
// Remove VFX.
effect eEffect = GetFirstEffect(oTarget);
while (GetIsEffectValid(eEffect) == TRUE)
{
if (GetEffectType(eEffect) == EFFECT_TYPE_VISUALEFFECT)
RemoveEffect(oTarget, eEffect);
eEffect = GetNextEffect(oTarget);
}
}
}
oTarget = GetNextObjectInArea(oArea);
}
DelayCommand(0.6, RecomputeStaticLighting(oArea));
}
Smushed together for testing purposes, doesn’t contain all the functionality of the posted original. Tested with basegame candelabra.
SwitchAllLights(TRUE, GetArea(oPC));
Also, sidenote: Try pasting code like this, to keep the formatting:
[code]
Insert code here.
[/code]
No scripts used on that area. The placeables are 6 sconces triggered by a switch (or should be). When the undesired lighting happens, it doesn’t appear to be the coming from the script, because the color is slightly different than the light source color used in the script. The script being attached to the placeable, seems to be triggering the area main lights. Also when that happens, the animation of the flame and the area lighting cannot be deactivated using the switch. That’s why it seems like a bug. I wonder if it’s related to the following (quoted from the Lexicon about SetTileSourceLightColor)
"It is reported that it is almost impossible for torches (the source lights themselves) to turn off properly, if at all.
Lighting changes are not recorded in a saved game, so when the save is loaded, the area regresses to its original lighting.
A workaround for this is to apply the change again in the area OnEnter script."
This is why I avoided using that function and used the script I found. When it works, it works well. But when the other light gets turned on, there’s no turning it off. Kind of a bummer.
I finally figured out what was going on with my placeable lights randomly lighting up. They are included in the CEP and have a heartbeat script, and on used script. Once I removed those, my placeable switch script worked as intended. Maybe I can get back to developing a storyline
the next bug is already waiting for you, lurking around the corner x_x there is no escape x_x surrender to your fate, which is to bugfix until the end of time x_x
Nice!