Difference between revisions of "OnEnter"

From NWN Lexicon
Jump to: navigation, search
m (Spelling fix(es))
Line 14: Line 14:
  
 
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.
 +
 +
It needs further testing if an Encounters OnEnter fires before or after the check for SetEncounterActive is done. It is likely after, or fired in parallel, with monsters being spawned. If so a larger non-encounter trigger needs to be placed around it to set the encounter status.
  
 
====Example====
 
====Example====

Revision as of 13:06, 26 January 2021

OnEnter

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.

It needs further testing if an Encounters OnEnter fires before or after the check for SetEncounterActive is done. It is likely after, or fired in parallel, with monsters being spawned. If so a larger non-encounter trigger needs to be placed around it to set the encounter status.

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