FANDOM


Automatically turn Lights On / Off

What it does

Takes any placeable light object with the tag "LampPost" and turns it on at night and off during the day. The beauty about this script is it will turn on / off every placeable in your module with the tag "LampPost".


Notes

How to use this script is included in the script itself.

The Script

////////////////////////////////////////////////////////////////////////////////
// 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);
    };
    }
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.