OnOpen

From NWN Lexicon
Jump to: navigation, search

OnOpen

The script attached to this event fires when an object has been opened.


Trigger

Door or placeable object was opened.


Function(s)

GetLastOpenedBy() returns the object that opened OBJECT_SELF.


Remarks

Only placeable objects with inventories (has the "Has Inventory" check box checked) can be opened. If a placeable object is opened, it doesn't mean anything has been, will be, or might be taken from it. Also, there is no real way to set a state of a placeable - unlike a door, which can be closed again. Placeables are only closed if the creature opening them is stopped (ClearAllActions()), killed, removed, or moves away and so forth.


Example

// In an doors On Open event, we close ourselves after 15 seconds
// because of drafts.
 
void CloseMe()
{
    // Can't close ourselves twice
    if(GetIsOpen(OBJECT_SELF))
    {
        ActionCloseDoor(OBJECT_SELF);
        SpeakString("*A draft closes this door*);
    }
}
 
void main()
{
    // 15 second delay in the On Open event.
    DelayCommand(15.0, CloseMe());
}

See Also

functions: 

GetLastOpenedBy()