From c7e3f9b0cf47a0797572b61b0f0396592df64838 Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Fri, 4 Jul 2025 21:38:14 +0200 Subject: [PATCH 1/4] Add some events from the dehardcode spellcasting MR, that do not need to be specific to that MR. --- .../source/reference/lua-scripting/events.rst | 70 +++++++++++++++++++ files/data/CMakeLists.txt | 2 + files/data/builtin.omwscripts | 2 + .../scripts/omw/mechanics/actorcontroller.lua | 23 ++++++ .../omw/mechanics/globalcontroller.lua | 39 +++++++++++ .../omw/mechanics/playercontroller.lua | 6 ++ 6 files changed, 142 insertions(+) create mode 100644 files/data/scripts/omw/mechanics/actorcontroller.lua create mode 100644 files/data/scripts/omw/mechanics/globalcontroller.lua diff --git a/docs/source/reference/lua-scripting/events.rst b/docs/source/reference/lua-scripting/events.rst index 007e0e43d1..d6ccd93003 100644 --- a/docs/source/reference/lua-scripting/events.rst +++ b/docs/source/reference/lua-scripting/events.rst @@ -41,9 +41,53 @@ Example: core.sendGlobalEvent('UseItem', {object = potion, actor = player, force = true}) +**ModifyStat** + +Modify the corresponding stat. + +.. code-block:: Lua + + -- Consume 10 magicka + actor:sendEvent('ModifyStat', {name = 'magicka', amount = -10}) + +**AddVfx** + +Calls the corresponding method in openmw.animation + +.. code-block:: Lua + + local eventParams = { + model = 'vfx_default', + options = { + textureOverride = effect.particle, + }, + } + actor:sendEvent('AddVfx', eventParams) + +**PlaySound3d** + +Calls the corresponding function in openw.core on the target. Will use core.sound.playSoundFile3d instead of core.sound.playSound3d if you put `file` instead of `sound` in the event data. + +.. code-block:: Lua + actor:sendEvent('PlaySound3d', {sound = 'Open Lock'}) + + +**BreakInvisibility** + +Forces the actor to lose all active invisibility effects. + + UI events --------- +**ShowMessage** + +If sent to a player, shows a message as if a call to ui.showMessage was made. + +.. code-block:: Lua + + player:sendEvent('ShowMessage', {message = 'Lorem ipsum'}) + **UiModeChanged** Every time UI mode is changed built-in scripts send to player the event ``UiModeChanged`` with arguments ``oldMode, ``newMode`` (same as ``I.UI.getMode()``) @@ -91,3 +135,29 @@ Global events that just call the corresponding function in `openmw.world`. -- world.setSimulationTimeScale(scale) core.sendGlobalEvent('SetSimulationTimeScale', scale) + + +**SpawnVfx, PlaySound3d** + +Calls the corresponding function in openw.core. Note that PlaySound3d will call core.sound.playSoundFile3d instead of core.sound.playSound3d if you put `file` instead of `sound` in the event data. + +.. code-block:: Lua + core.sendGlobalEvent('SpawnVfx', {position = hitPos, model = 'vfx_destructarea', options = {scale = 10}}) + core.sendGlobalEvent('PlaySound3d', {sound = 'Open Lock', position = container.position}) + +**ConsumeItem** + +Reduces stack size of an item by a given amount, removing the item complete if removing all items in the stack are removed. + +.. code-block:: Lua + + core.sendGlobalEvent('ConsumeItem', {item = foobar, amount = 1}) + +**ModifyItemCharge** + +Modify a specified amount of enchantment charge of an item + +.. code-block:: Lua + + -- Reduce charge by 10 + core.sendGlobalEvent('ModifyItemCharge', {item = foobar, amount = -10}) diff --git a/files/data/CMakeLists.txt b/files/data/CMakeLists.txt index d9218b45b2..39715af75d 100644 --- a/files/data/CMakeLists.txt +++ b/files/data/CMakeLists.txt @@ -91,7 +91,9 @@ set(BUILTIN_DATA_FILES scripts/omw/console/local.lua scripts/omw/console/player.lua scripts/omw/console/menu.lua + scripts/omw/mechanics/actorcontroller.lua scripts/omw/mechanics/animationcontroller.lua + scripts/omw/mechanics/globalcontroller.lua scripts/omw/mechanics/playercontroller.lua scripts/omw/settings/menu.lua scripts/omw/music/actor.lua diff --git a/files/data/builtin.omwscripts b/files/data/builtin.omwscripts index 37367783ab..6126c0b761 100644 --- a/files/data/builtin.omwscripts +++ b/files/data/builtin.omwscripts @@ -23,6 +23,8 @@ PLAYER: scripts/omw/input/actionbindings.lua PLAYER: scripts/omw/input/smoothmovement.lua PLAYER: scripts/omw/input/gamepadcontrols.lua NPC,CREATURE: scripts/omw/ai.lua +GLOBAL: scripts/omw/mechanics/globalcontroller.lua +CREATURE, NPC, PLAYER: scripts/omw/mechanics/actorcontroller.lua # User interface PLAYER: scripts/omw/ui.lua diff --git a/files/data/scripts/omw/mechanics/actorcontroller.lua b/files/data/scripts/omw/mechanics/actorcontroller.lua new file mode 100644 index 0000000000..fe8c75b244 --- /dev/null +++ b/files/data/scripts/omw/mechanics/actorcontroller.lua @@ -0,0 +1,23 @@ +local self = require('openmw.self') +local core = require('openmw.core') +local types = require('openmw.types') +local Actor = types.Actor + +return { + eventHandlers = { + ModifyStat = function(data) + local stat = Actor.stats.dynamic[data.stat](self) + stat.current = stat.current + data.amount + end, + PlaySound3d = function(data) + if data.sound then + core.sound.playSound3d(data.sound, self, data.options) + else + core.sound.playSoundFile3d(data.file, self, data.options) + end + end, + BreakInvisibility = function(data) + Actor.activeEffects(self):remove(core.magic.EFFECT_TYPE.Invisibility) + end, + }, +} diff --git a/files/data/scripts/omw/mechanics/globalcontroller.lua b/files/data/scripts/omw/mechanics/globalcontroller.lua new file mode 100644 index 0000000000..22d92e7c24 --- /dev/null +++ b/files/data/scripts/omw/mechanics/globalcontroller.lua @@ -0,0 +1,39 @@ +local types = require('openmw.types') +local Lockable = types.Lockable +local Item = require('openmw.types').Item +local world = require('openmw.world') +local core = require('openmw.core') + +local function onConsumeItem(data) + local item = data.item + local amount = data.amount + if amount > item.count then + print('Warning: tried to consume '..tostring(amount)..' '..tostring(item)..'s, but there were only '..tostring(item.count)) + amount = item.count + end + item:remove(amount) +end + +local function onPlaySound3d(data) + if data.sound then + core.sound.playSound3d(data.sound, data.position, data.options) + elseif data.file then + core.sound.playSoundFile3d(data.file, data.position, data.options) + end +end + +return { + eventHandlers = { + SpawnVfx = function(data) + world.vfx.spawn(data.model, data.position, data.options) + end, + PlaySound3d = onPlaySound3d, + ConsumeItem = onConsumeItem, + Lock = function(data) + Lockable.lock(data.target, data.magnitude) + end, + Unlock = function(data) + Lockable.unlock(data.target) + end, + }, +} diff --git a/files/data/scripts/omw/mechanics/playercontroller.lua b/files/data/scripts/omw/mechanics/playercontroller.lua index 870f24415c..8b4d618917 100644 --- a/files/data/scripts/omw/mechanics/playercontroller.lua +++ b/files/data/scripts/omw/mechanics/playercontroller.lua @@ -111,4 +111,10 @@ return { engineHandlers = { onUpdate = onUpdate, }, + + eventHandlers = { + ShowMessage = function(data) + if data.message then ui.showMessage(data.message) end + end + }, } From 1b9802472da6b446b1f5fd2c2af0c4a1a30fd016 Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Sat, 5 Jul 2025 01:43:39 +0200 Subject: [PATCH 2/4] Doc updates --- docs/source/reference/lua-scripting/events.rst | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/source/reference/lua-scripting/events.rst b/docs/source/reference/lua-scripting/events.rst index d6ccd93003..a4683b0dc2 100644 --- a/docs/source/reference/lua-scripting/events.rst +++ b/docs/source/reference/lua-scripting/events.rst @@ -147,7 +147,7 @@ Calls the corresponding function in openw.core. Note that PlaySound3d will call **ConsumeItem** -Reduces stack size of an item by a given amount, removing the item complete if removing all items in the stack are removed. +Reduces stack size of an item by a given amount, removing the item completely if stack size is reduced to 0 or less. .. code-block:: Lua @@ -161,3 +161,19 @@ Modify a specified amount of enchantment charge of an item -- Reduce charge by 10 core.sendGlobalEvent('ModifyItemCharge', {item = foobar, amount = -10}) + +**Lock** + +Lock a container or door + +.. code-block:: Lua + + core.sendGlobalEvent('Lock', {taret = selected, magnitude = 50}) + +**Unlock** + +Unlock a container or door + +.. code-block:: Lua + + core.sendGlobalEvent('Unlock', {taret = selected}) From 7143115e57011fca4f3fbbcb2af8d53116173929 Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Sat, 5 Jul 2025 13:09:27 +0200 Subject: [PATCH 3/4] Doc update --- docs/source/reference/lua-scripting/events.rst | 9 --------- 1 file changed, 9 deletions(-) diff --git a/docs/source/reference/lua-scripting/events.rst b/docs/source/reference/lua-scripting/events.rst index a4683b0dc2..15c9b52eea 100644 --- a/docs/source/reference/lua-scripting/events.rst +++ b/docs/source/reference/lua-scripting/events.rst @@ -153,15 +153,6 @@ Reduces stack size of an item by a given amount, removing the item completely if core.sendGlobalEvent('ConsumeItem', {item = foobar, amount = 1}) -**ModifyItemCharge** - -Modify a specified amount of enchantment charge of an item - -.. code-block:: Lua - - -- Reduce charge by 10 - core.sendGlobalEvent('ModifyItemCharge', {item = foobar, amount = -10}) - **Lock** Lock a container or door From 45c187028fe23fde4eba4f021badb70c3ec402cd Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Sat, 5 Jul 2025 13:25:22 +0200 Subject: [PATCH 4/4] Bump --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c755ad315f..3a194450fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...") set(OPENMW_VERSION_MAJOR 0) set(OPENMW_VERSION_MINOR 50) set(OPENMW_VERSION_RELEASE 0) -set(OPENMW_LUA_API_REVISION 79) +set(OPENMW_LUA_API_REVISION 80) set(OPENMW_POSTPROCESSING_API_REVISION 3) set(OPENMW_VERSION_COMMITHASH "")