Difference between revisions of "OnUserDefined"

From NWN Lexicon
Jump to: navigation, search
(See Also)
Line 56: Line 56:
[[ event | Event Constants  ]]
[[ event | Event Constants  ]]
| width="1px" align="right" valign="top" | <font color="gray">events: </font>
[[OnUserDefined|OnUserDefined Event]]

Revision as of 00:57, 4 July 2020


The script attached to this event fires depending on settings made during the OnSpawn event for creatures and some general level blanket signals for all objects (including creatures). Typically this script is a switch/case statement that does something different depending on the signal (numerical value) sent to it by an event that calls the script. This event makes it very easy to retain the default behavior of an object while adding custom mannerisms of your own.


A script has used the SignalEvent() function.


GetUserDefinedEventNumber() to return the user defined event number being sent.


In a script that generates a user-defined event, use the EventUserDefined(int) function to generate the appropriate internal event identification number which can be consumed in the OnUserDefined script. Also note that the UserDefined Death event is considered unreliable by Bioware. This is because the UserDefined event runs after the calling event has finished, in this case OnDeath. And as such, a call to DestroyObject(OBJECT_SELF) in the OnDeath event will remove the object, closing its action queue and thus prevent the UserDefined Death event from executing.


// OnUserDefined exists as an event for many objects
// to invoke it for a module, try something like...
// SignalEvent(GetModule(), EventUserDefined(112));
// then say we want to capture user-defined event number 112
// in our module's OnUserDefined event...
void main()
     switch (GetUserDefinedEventNumber())
          case 112:
               PrintString("Event #112 occurred!");
          // ... additional case statements for other user-defined
          // events can be added as necessary

See Also


GetUserDefinedEventNumber() SignalEvent EventUserDefined


Event Constants