2021-04-24 22:55:08 +00:00
|
|
|
Engine handlers reference
|
|
|
|
=========================
|
|
|
|
|
2023-08-27 18:43:12 +00:00
|
|
|
.. include:: version.rst
|
|
|
|
|
2021-04-24 22:55:08 +00:00
|
|
|
Engine handler is a function defined by a script, that can be called by the engine.
|
|
|
|
|
2024-01-10 18:34:33 +00:00
|
|
|
**Can be defined by any script**
|
2021-04-24 22:55:08 +00:00
|
|
|
|
2024-01-10 18:34:33 +00:00
|
|
|
.. list-table::
|
|
|
|
:widths: 20 80
|
2024-01-14 12:38:35 +00:00
|
|
|
|
2024-01-10 18:34:33 +00:00
|
|
|
* - onInterfaceOverride(base)
|
|
|
|
- | Called if the current script has an interface and overrides an interface
|
|
|
|
| (``base``) of another script.
|
2022-02-21 19:49:00 +00:00
|
|
|
|
2024-01-10 18:34:33 +00:00
|
|
|
**Can be defined by any non-menu script**
|
2022-02-21 19:49:00 +00:00
|
|
|
|
|
|
|
.. list-table::
|
|
|
|
:widths: 20 80
|
|
|
|
|
|
|
|
* - onInit(initData)
|
|
|
|
- | Called once when the script is created (not loaded). `InitData can be`
|
|
|
|
| `assigned to a script in openmw-cs (not yet implemented).`
|
|
|
|
| ``onInterfaceOverride`` can be called before ``onInit``.
|
|
|
|
* - onUpdate(dt)
|
2022-05-13 16:22:59 +00:00
|
|
|
- | Called every frame if the game is not paused. `dt` is
|
|
|
|
| the simulation time from the last update in seconds.
|
2022-02-21 19:49:00 +00:00
|
|
|
* - onSave() -> savedData
|
|
|
|
- | Called when the game is saving. May be called in inactive state,
|
|
|
|
| so it shouldn't use `openmw.nearby`.
|
|
|
|
* - onLoad(savedData, initData)
|
|
|
|
- | Called on loading with the data previosly returned by
|
|
|
|
| ``onSave``. During loading the object is always inactive. ``initData`` is
|
|
|
|
| the same as in ``onInit``.
|
|
|
|
| Note that ``onLoad`` means loading a script rather than loading a game.
|
|
|
|
| If a script did not exist when a game was saved onLoad will not be
|
|
|
|
| called, but ``onInit`` will.
|
|
|
|
|
|
|
|
**Only for global scripts**
|
|
|
|
|
|
|
|
.. list-table::
|
|
|
|
:widths: 20 80
|
|
|
|
|
|
|
|
* - onNewGame()
|
2023-03-26 23:36:45 +00:00
|
|
|
- New game is started.
|
2022-02-21 19:49:00 +00:00
|
|
|
* - onPlayerAdded(player)
|
2023-08-11 21:16:32 +00:00
|
|
|
- | Player added to the game world. The argument is a `Game object`.
|
|
|
|
| Note that this is triggered at the start of a game, and when a game is loaded.
|
2022-05-20 19:27:21 +00:00
|
|
|
* - onObjectActive(object)
|
|
|
|
- Object becomes active.
|
2022-02-21 19:49:00 +00:00
|
|
|
* - onActorActive(actor)
|
|
|
|
- Actor (NPC or Creature) becomes active.
|
2022-05-20 19:27:21 +00:00
|
|
|
* - onItemActive(item)
|
|
|
|
- | Item (Weapon, Potion, ...) becomes active in a cell.
|
|
|
|
| Does not apply to items in inventories or containers.
|
2023-03-26 23:36:45 +00:00
|
|
|
* - onActivate(object, actor)
|
|
|
|
- Object is activated by an actor.
|
2023-06-13 15:30:52 +00:00
|
|
|
* - onNewExterior(cell)
|
|
|
|
- A new exterior cell not defined by a content file has been generated.
|
2022-02-21 19:49:00 +00:00
|
|
|
|
|
|
|
**Only for local scripts**
|
|
|
|
|
|
|
|
.. list-table::
|
|
|
|
:widths: 20 80
|
|
|
|
|
|
|
|
* - onActive()
|
|
|
|
- | Called when the object becomes active
|
|
|
|
| (either a player came to this cell again, or a save was loaded).
|
|
|
|
* - onInactive()
|
|
|
|
- | Object became inactive. Since it is inactive the handler
|
|
|
|
| can not access anything nearby, but it is possible to send
|
|
|
|
| an event to global scripts.
|
2023-06-18 19:19:34 +00:00
|
|
|
* - onTeleported()
|
|
|
|
- Object was teleported.
|
2022-02-21 19:49:00 +00:00
|
|
|
* - onActivated(actor)
|
|
|
|
- | Called on an object when an actor activates it. Note that picking
|
|
|
|
| up an item is also an activation and works this way: (1) a copy of
|
|
|
|
| the item is placed to the actor's inventory, (2) count of
|
|
|
|
| the original item is set to zero, (3) and only then onActivated is
|
|
|
|
| called on the original item, so self.count is already zero.
|
2022-05-12 16:03:50 +00:00
|
|
|
* - onConsume(item)
|
|
|
|
- | Called on an actor when they consume an item (e.g. a potion).
|
|
|
|
| Similarly to onActivated, the item has already been removed
|
|
|
|
| from the actor's inventory, and the count was set to zero.
|
2022-02-21 19:49:00 +00:00
|
|
|
|
2024-01-10 18:27:39 +00:00
|
|
|
**Only menu scripts and local scripts attached to a player**
|
2022-02-21 19:49:00 +00:00
|
|
|
|
|
|
|
.. list-table::
|
|
|
|
:widths: 20 80
|
2024-01-14 12:38:35 +00:00
|
|
|
|
2024-01-10 18:34:33 +00:00
|
|
|
* - onFrame(dt)
|
|
|
|
- | Called every frame (even if the game is paused) right after
|
|
|
|
| processing user input. Use it only for latency-critical stuff
|
|
|
|
| and for UI that should work on pause.
|
|
|
|
| `dt` is simulation time delta (0 when on pause).
|
|
|
|
* - onKeyPress(key)
|
2022-02-21 19:49:00 +00:00
|
|
|
- | `Key <openmw_input.html##(KeyboardEvent)>`_ is pressed.
|
2022-04-09 21:07:57 +00:00
|
|
|
| Usage example:
|
|
|
|
| ``if key.symbol == 'z' and key.withShift then ...``
|
2024-01-14 12:38:35 +00:00
|
|
|
* - onKeyRelease(key)
|
2022-02-21 19:49:00 +00:00
|
|
|
- | `Key <openmw_input.html##(KeyboardEvent)>`_ is released.
|
2022-04-09 21:07:57 +00:00
|
|
|
| Usage example:
|
|
|
|
| ``if key.symbol == 'z' and key.withShift then ...``
|
2022-02-21 19:49:00 +00:00
|
|
|
* - onControllerButtonPress(id)
|
|
|
|
- | A `button <openmw_input.html##(CONTROLLER_BUTTON)>`_ on a game controller is pressed.
|
2022-04-09 21:07:57 +00:00
|
|
|
| Usage example:
|
|
|
|
| ``if id == input.CONTROLLER_BUTTON.LeftStick then ...``
|
2022-02-21 19:49:00 +00:00
|
|
|
* - onControllerButtonRelease(id)
|
|
|
|
- | A `button <openmw_input.html##(CONTROLLER_BUTTON)>`_ on a game controller is released.
|
2022-04-09 21:07:57 +00:00
|
|
|
| Usage example:
|
|
|
|
| ``if id == input.CONTROLLER_BUTTON.LeftStick then ...``
|
2022-02-21 19:49:00 +00:00
|
|
|
* - onInputAction(id)
|
2023-12-29 18:56:59 +00:00
|
|
|
- | (DEPRECATED, use `registerActionHandler <openmw_input.html##(registerActionHandler)>`_)
|
|
|
|
| `Game control <openmw_input.html##(ACTION)>`_ is pressed.
|
2022-04-09 21:07:57 +00:00
|
|
|
| Usage example:
|
|
|
|
| ``if id == input.ACTION.ToggleWeapon then ...``
|
2022-02-21 19:49:00 +00:00
|
|
|
* - onTouchPress(touchEvent)
|
|
|
|
- | A finger pressed on a touch device.
|
|
|
|
| `Touch event <openmw_input.html##(TouchEvent)>`_.
|
|
|
|
* - onTouchRelease(touchEvent)
|
|
|
|
- | A finger released a touch device.
|
|
|
|
| `Touch event <openmw_input.html##(TouchEvent)>`_.
|
|
|
|
* - onTouchMove(touchEvent)
|
|
|
|
- | A finger moved on a touch device.
|
2022-04-09 21:07:57 +00:00
|
|
|
| `Touch event <openmw_input.html##(TouchEvent)>`_.
|
2024-02-10 21:53:29 +00:00
|
|
|
* - onMouseButtonPress(button)
|
|
|
|
- | A mouse button was pressed
|
|
|
|
| Button id
|
|
|
|
* - onMouseButtonRelease(button)
|
|
|
|
- | A mouse button was released
|
|
|
|
| Button id
|
|
|
|
* - onMouseWheel(vertical, horizontal)
|
|
|
|
- | Mouse wheel was scrolled
|
|
|
|
| vertical and horizontal mouse wheel change
|
2022-04-09 21:07:57 +00:00
|
|
|
* - | onConsoleCommand(
|
|
|
|
| mode, command, selectedObject)
|
|
|
|
- | User entered `command` in in-game console. Called if either
|
|
|
|
| `mode` is not default or `command` starts with prefix `lua`.
|
|
|
|
|
2024-01-10 18:27:39 +00:00
|
|
|
**Only for local scripts attached to a player**
|
|
|
|
|
|
|
|
.. list-table::
|
|
|
|
:widths: 20 80
|
2024-01-14 12:38:35 +00:00
|
|
|
|
2024-01-10 18:27:39 +00:00
|
|
|
* - onKeyPress(key)
|
|
|
|
- | `Key <openmw_input.html##(KeyboardEvent)>`_ is pressed.
|
|
|
|
| Usage example:
|
|
|
|
| ``if key.symbol == 'z' and key.withShift then ...``
|
|
|
|
* - onQuestUpdate(questId, stage)
|
|
|
|
- | Called when a quest is updated.
|
|
|
|
|
2024-01-08 20:58:07 +00:00
|
|
|
**Only for menu scripts**
|
|
|
|
|
|
|
|
.. list-table::
|
|
|
|
:widths: 20 80
|
2024-01-14 12:38:35 +00:00
|
|
|
|
2024-01-08 20:58:07 +00:00
|
|
|
* - onStateChanged()
|
|
|
|
- | Called whenever the current game changes
|
|
|
|
| (i. e. the result of `getState <openmw_menu.html##(getState)>`_ changes)
|