An event is a signal to an object that something has happened, will happen, or is just about to happen. An event is usually caused by the activity of a player character (PC), but can also be triggered by non-player characters, by the normal operation of the game (e.g. OnHeartbeat event), or even by scripting (see SignalEvent). When an event occurs, the game responds by having the signaled object run the event handler (the script assigned to the event, usually through the Toolset). This script determines how (and if) the object responds to the event.
Each type of object has its own set of events that it can be configured to receive. Not all objects have all events. The classification of events (by the type of object that receives them) are:
- module events,
- area events,
- creature events,
- door events,
- encounter events,
- merchant events,
- placeable events, and
- trigger events.
Items do not directly raise events, but can cause module events to be raised to handle specific situations. Waypoints do not have events associated with them.
PCs are similar to items in that the events most commonly associated with them are actually module events. This is because most of the time, PCs are controlled by players, hence do not require scripts to cause them to react to their environment. However, PCs do in fact have the events associated with creatures, even though these are rarely made use of. The script handling a PC's creature events is named
default, unless a different script is specified in statescripts.2da. Normally, the only creature event used for a PC is the OnHeartbeat event, and then only when a PC is removed from a player's control, such as when the PC is frightened.
Class event matrix
The following table summarizes which object types get which events. The events for traps exist in addition to the events for the underlying object (door, placeable, or trigger).
While events are handled by scripts, they can also be represented by variables of the type
event within a script. Variables of this type are not often used in NWScript other than as an intermediary between a command that returns an event and SignalEvent(), the command that accepts an event as a parameter.