NWNWiki
Advertisement
NWNWiki
3,718
pages

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