Difference between revisions of "OnEnter"

From NWN Lexicon
Jump to: navigation, search
 
Line 8: Line 8:
 
====Function(s)====
 
====Function(s)====
  
[[GetEnteringObject]] returns the object that has entered the area, encounter, or trigger.
+
* [[GetEnteringObject]] returns the object that has entered the area, encounter, or trigger.
  
  
Line 18: Line 18:
  
 
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.
 +
 +
 +
====Player Login Order====
 +
 +
Important mainly for multiplayer servers, the order of events of a player entering is:
 +
 +
# [[OnAcquireItem]] for each item in the inventory (including those equipped)
 +
# [[OnPlayerEquipItem]] for any item is equipped
 +
#* (Repeat 1 for each item in inventory)
 +
# [[OnClientEnter]]
 +
# [[OnEnter]] - Order: Triggers, Area of Effects then the Area they are in.
  
  

Latest revision as of 00:12, 20 August 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.


Player Login Order

Important mainly for multiplayer servers, the order of events of a player entering is:

  1. OnAcquireItem for each item in the inventory (including those equipped)
  2. OnPlayerEquipItem for any item is equipped
    • (Repeat 1 for each item in inventory)
  3. OnClientEnter
  4. OnEnter - Order: Triggers, Area of Effects then the Area they are in.


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()