Skip to content

event⚓︎

The event library helps to instruct mwse to call a given function when a specific action is taken in the game.

Functions⚓︎

event.clear⚓︎

Removes all callbacks registered for a given event.

event.clear(eventId, filter)

Parameters:


event.isRegistered⚓︎

Returns true for a function previously registered to an event with event.register().

local result = event.isRegistered(eventId, callback, { filter = ... })

Parameters:

  • eventId (string, tes3.event)
  • callback (function)
  • options (table): Optional.
    • filter (userdata, string, number, tes3baseObject): Optional. Allows searching for a callback function registered with the specified filter.

Returns:

  • result (boolean)

event.register⚓︎

Registers a function to be called when an event is raised.

event.register(eventId, callback, { doOnce = ..., filter = ..., priority = ..., unregisterOnLoad = ... })

Parameters:

  • eventId (string, tes3.event)
  • callback (function)
  • options (table): Optional.
    • doOnce (boolean): Default: false. If this option is set to true, the function registered will be executed only once, and automatically unregistered thereafter.
    • filter (userdata, string, number, tes3baseObject): Optional. This parameter allows selectively executing the callback function only when a specific condition is met. The exact behavior depends on each event.
    • priority (number): Optional. Event callback with higher priority is executed before callback with lower priority. Typically used to make certain mods compatible.
    • unregisterOnLoad (boolean): Default: false. If this option is set to true, the registered function will be unregistered when the next load event triggers.

event.trigger⚓︎

Triggers an event. This can be used to trigger custom events with specific data.

local resultPayload = event.trigger(eventId, payload, { filter = ... })

Parameters:

  • eventId (string, tes3.event)
  • payload (table): Optional.
  • options (table): Optional.
    • filter (userdata, string, number, tes3baseObject): Optional. Assigning a filter will make the event callbacks with filters matching this one to be executed first. All the other unfiltered callbacks are executed after.

Returns:

  • resultPayload (table): This is the modified payload after all the callback functions registered on the triggered event are executed. Returning true from a callback function will set both payload.block and payload.claim to true. After an event has been claimed by a certain function (by setting the claim in eventData to true) no other registered callback functions will be executed on this event trigger. This is useful if you wish to implement blocking system for your event. In addition, this can be used to the same effect as some MWSE's events allow changing some of the eventData values to modify the behavior of the vanilla mechanics.

event.unregister⚓︎

Unregisters a function previously registered for an event with event.register().

event.unregister(eventId, callback, { filter = ... })

Parameters:

  • eventId (string, tes3.event)
  • callback (function)
  • options (table): Optional.
    • filter (userdata, string, number, tes3baseObject): Optional. If a callback function was registered with a filter, the same filter needs to be passed to event.unregister to successfully unregister the callback function.