OnExit

From NWN Lexicon
Jump to: navigation, search

OnExit

The script attached to this event fires when an area, trigger, or encounter boundry is exited. This can be used for such effects as slaying all the zombies that just animated to kill the intruding tomb robbing PC or removing the Holy Grail from the PC's inventory and triggering a series of encounters that send creatures after the PC. Area of effects also can have On Exit events defined when they are created.

Trigger

Something left the current area, encounter, trigger or area of effect (not neccessarily a PC).

Function(s)

GetExitingObject() returns the object that just left the area, encounter, or trigger.

Remarks

The OnExit event fires for an Area of Effect if it is dispelled or runs out of duration. For spells such as Acid Fog, it removes the slowing effect.

Known Bugs

The OnExit event for trigger nor area of effect doesn't fire for player exiting the game. Also, the area OnExit event doesn't fire for dead player exiting the game. To workaround this, you need to store trigger/area object in OnEnter with local object variable, read it in OnClientLeave and ExecuteScript on this object from there.

Example

// see the OnEnter event for the stage for the below script
// sends "HUNTER" home (aptly named "HUNTER_CAVE") if
// the PC leaves the area
void main()
{
     object oExiting = GetExitingObject();
     object oMonster = GetObjectByTag("HUNTER");
     object oCave = GetObjectByTag("HUNTER_CAVE");
     if (GetIsPC(oExiting))
     {
          SetLocalObject(OBJECT_SELF, "PC_Entered", OBJECT_INVALID);
     }
     // if "HUNTER" is leaving while giving chase, send him home
     if (oExiting == oMonster)
     {
          AssignCommand(oMonster, ClearAllActions());
          AssignCommand(oMonster, ActionMoveToObject(oCave));
     }
}

See Also

functions: 

GetExitingObject()