Difference between revisions of "OnEnter"

From NWN Lexicon
Jump to: navigation, search
Line 15: Line 15:
 
Area of effects can have a On Enter script to apply effects while in the effect. When the Area of Effect is removed, or runs out, it does fire its [[OnExit]] event for all creatures currently in it.
 
Area of effects can have a On Enter script to apply effects while in the effect. When the Area of Effect is removed, or runs out, it does fire its [[OnExit]] event for all creatures currently in it.
  
Frustratingly for whatever reason encounters fire the [[OnEnter]] event ''after'' spawning monsters (ie when [[SetEncoutnerActive]] works). A larger non-encounter trigger needs to be placed around it to set the encounter status, or it done through some other means.
+
Frustratingly for whatever reason encounters fire the [[OnEnter]] event ''after'' spawning monsters (ie when [[SetEncounterActive]] would stop them). A larger non-encounter trigger needs to be placed around it to set the encounter status, or it done through some other means.
  
 
Note that [[CreateObject]] and similar functions will generate an [[OnEnter]] event for the creature in the area they're created in. Make sure to test if the entering object is a PC if you're creating such creatures in the OnEnter script itself to stop game crashing loops.
 
Note that [[CreateObject]] and similar functions will generate an [[OnEnter]] event for the creature in the area they're created in. Make sure to test if the entering object is a PC if you're creating such creatures in the OnEnter script itself to stop game crashing loops.

Revision as of 17:45, 18 July 2021

The script attached to this event fires when a certain area boundary has been violated allowing you to throw a custom event, update the PC's journal, or a variety of other things. Area of effects also can have On Enter events defined when they are created, for example an Acid Fog cloud in a spell.

Trigger

Something has entered the area, encounter, trigger or area of effect (not necessarily a PC).


Function(s)

GetEnteringObject returns the object that has entered the area, encounter, or trigger.


Remarks

Area of effects can have a On Enter script to apply effects while in the effect. When the Area of Effect is removed, or runs out, it does fire its OnExit event for all creatures currently in it.

Frustratingly for whatever reason encounters fire the OnEnter event after spawning monsters (ie when SetEncounterActive would stop them). A larger non-encounter trigger needs to be placed around it to set the encounter status, or it done through some other means.

Note that CreateObject and similar functions will generate an OnEnter event for the creature in the area they're created in. Make sure to test if the entering object is a PC if you're creating such creatures in the OnEnter script itself to stop game crashing loops.


Example

// notifies a monster tagged "HUNTER" that a PC has entered
// the area this script is attached to; also set a local variable
// that can be checked later to see if the PC went into an area
// to prevent an event from occurring again to the same PC
// (until another PC comes along and triggers this event that is).
// "HUNTER" can also use the object (oEntering) stored on the
// event to help track down the trespassing PC.
void main()
{
     object oEntering = GetEnteringObject();
     // make sure its a PC
     if (GetIsPC(oEntering))
     {
          // prevent "HUNTER" from coming again
          if (!(GetLocalObject(OBJECT_SELF, "PC_Entered") == oEntering))
          {
               object oMonster = GetObjectByTag("HUNTER");
               // set a local variable on the Area
               SetLocalObject(OBJECT_SELF, "PC_Entered", oEntering);
               // tell "HUNTER" to come and eat
               SignalEvent(oMonster, EventUserDefined(100));
          }
     }
}

See Also

functions: 

GetEnteringObject()