Events
Source
The framework handles two types of events: the NWN stock events, and the additional NWNX:EE events. In addition to the user defined scripts, all events are grouped together into a single event system.
Events are sent from:
From any object that has
fw_event
set as a script for an eventFrom a NWNX:EE registered event handler.
From the combat
x2_def
scripts.From certain spells such as Raise Dead or Ressurection.
Events are recieved by:
Any unit who registered an event.
Any user defined script which set
fw_event
as a script for an event.
A user-defined script can register global events in addition to the object specific events.
Usage
In order for an event to fire, it must either be used in the UserDefined script with a fw_event
script in the appropriate script event, or it’s filename must start with fu_
or un_
.
Example unit
Given an example unit with filename un_example
, the following code will first be called with the EVENT_REGISTER
event. On said event, the script will register itself to all OnOpened events where the script is fw_event
:
#include "fi_events"
void main()
{
switch (GetEvent())
{
case EVENT_REGISTER:
RegisterEvent(EVENT_OBJECT_OPENED);
return;
case EVENT_OBJECT_OPENED:
// do something...
return;
}
}
Example OnUserDefined
OnUserDefined scripts do not need to register events for events that has fw_event
as it’s event handler, unless it also wishes to recieve said event for all events, those of other objects included. This will result in recieving two events for the object: one via a BroadcastEvent
and one via ExecuteUserDefinedScript
.
The OnUserDefined script can register other events as well.
#include "fi_events"
void main()
{
switch (GetEvent())
{
case EVENT_OBJECT_OPENED:
// do something...
return;
}
}