Torch light

Simple script - I thought…
I’m trying to make it so that the torches in my village only light during nighttime.

code so far…

// For OnHearbeat handler

object oTarget;

void main()
{

object oPC = GetNearestCreature
(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF);

int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));
if (DoOnce==TRUE) return;
SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);

if (GetIsDay())
{
oTarget = OBJECT_SELF;

PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);

SetPlaceableIllumination (oTarget, FALSE);

RecomputeStaticLighting(GetArea(oTarget));

}
else if (GetIsNight())
{
oTarget = OBJECT_SELF;

PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);

SetPlaceableIllumination (oTarget, TRUE);

RecomputeStaticLighting(GetArea(oTarget));

}
else
{
return;
}
}
As it stands now, the lights go off during the day but won’t come on at night. Any help would be great guys. :slight_smile:

You made it that the script runs once only.

You probably need a DoOnceDay and a DoOnceNight:

if (GetIsDay())
{
   if (GetLocalInt(OBJECT_SELF, "DoOnceDay")) return;
   SetLocalInt(OBJECT_SELF, "DoOnceDay", TRUE);
   SetLocalInt(OBJECT_SELF, "DoOnceNight", FALSE);
   ...
}
else if (GetIsNight())
{
   if (GetLocalInt(OBJECT_SELF, "DoOnceNight")) return;
   SetLocalInt(OBJECT_SELF, "DoOnceNight", TRUE);
   SetLocalInt(OBJECT_SELF, "DoOnceDay", FALSE);
   ...
} 

Thank you Kamiryn. Everything is up and running perfectly.