Angband events in Lua

Introduction

Angband can be controlled by user-created Lua scripts that are called at certain points in the game or at specific times. These "events" can happen under a variety of circumstances. The Lua scripts may set up an arbitrary function to be called when an event occurs, and this event may do whatever is needed. For example, an event is invoked when the player enters a new dungeon level. The scripts can set up an event handler to create a specific monster if he happens to enter dungeon level 100.

Certain events look at the values returned by the Lua event handler to do different things depending on the situation.

Adding event handlers

To associate a Lua function with a given event, use the "add_event_handler" function. The first argument is the event name, and the second argument is the Lua function to be called.

Example:

-- "use_object" is the name of the event
-- "use_object_hook" is the event handler to be called for this event
add_event_handler("use_object", use_object_hook)

It is possible to add several different event handlers to a single event. These event handlers are then called when the event occures in the order they have been added.

Adding new events to the game engine is easy, so if you need a new one for some reason, let me know and I'll try to add it in the next version.

List of events