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:

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

Event name module area creature door encounter merchant placeable trigger trap
OnAcquireItem event                
OnActivateItem event                
OnAreaTransitionClick event                
OnBlocked event                
OnClick event              
OnClientEnter event                
OnClientLeave event                
OnClose event              
OnCombatRoundEnd event                
OnConversation event                
OnCutsceneAbort event                
OnDamaged event            
OnDeath event            
OnDisarm event                
OnDisturbed event              
OnEnter event            
OnExhausted event                
OnExit event            
OnFailToOpen event                
OnHeartbeat event    
OnLock event              
OnModuleLoad event                
OnOpen event              
OnOpenStore event                
OnPerception event                
OnPhysicalAttacked event            
OnPlayerChat event                
OnPlayerDeath event                
OnPlayerDying event                
OnPlayerEquipItem event                
OnPlayerLevelUp event                
OnPlayerRespawn event                
OnPlayerRest event                
OnPlayerUnEquipItem event                
OnRested event                
OnSpawn event                
OnSpellCastAt event            
OnStoreClosed event                
OnTrapTriggered event                
OnUnAcquireItem event                
OnUnlock event              
OnUsed event                
OnUserDefined event    


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.

See also[]