FANDOM


This day and night lamp posts script turns the lamp posts in an area on at night and off during the day. Place this script in the OnHeartbeat event of an object in the area, and give all the lamp posts a tag of "LampPost".


// Script to turn lamps on at night and off during the day.
 
const string TAG_LAMP = "LampPost";
const string LV_LAMPS_ON = "LampsOn";
 
void main()
{
    // define data storage object
    object oData = OBJECT_SELF;
 
    int bLampsAreOn = GetLocalInt(oData, LV_LAMPS_ON);
    int bLampsShouldBeOn = GetIsDusk() || GetIsNight() || GetIsDawn();
 
    if ( bLampsAreOn != bLampsShouldBeOn )
    {
        // Loop through all lamps in the area.
        int nNth = 0;
        object oLamp = GetNearestObjectByTag(TAG_LAMP, oData, nNth);
        while ( oLamp != OBJECT_INVALID )
        {
            // Turn this lamp on or off as appropriate.
            AssignCommand(oLamp, PlayAnimation(
                bLampsShouldBeOn ? ANIMATION_PLACEABLE_ACTIVATE
                                 : ANIMATION_PLACEABLE_DEACTIVATE));
            SetPlaceableIllumination(oLamp, bLampsShouldBeOn);
            // Advance to the next lamp.
            oLamp = GetNearestObjectByTag(TAG_LAMP, oData, ++nNth);
        }
        // Update the area.
        RecomputeStaticLighting(GetArea(oData));
        // Track this.
        SetLocalInt(oData, LV_LAMPS_ON, bLampsShouldBeOn);
    }
}

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.