From 96ab0752dbfbed14eaaab864c2c4e1929b87db33 Mon Sep 17 00:00:00 2001 From: Nova Date: Sun, 5 Oct 2025 01:49:18 -0400 Subject: [PATCH 1/5] Add Lua API for werewolf state management Adds a new function to force the player or NPCS to turn into a werewolf. - setWerewolf(bool): Transform a PC or NPC into/out of werewolf form This enables modders to control werewolf transformations Useage Example: -- Turn player into werewolf types.NPC.setWerewolf(self, true) --- apps/openmw/mwlua/types/npc.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/openmw/mwlua/types/npc.cpp b/apps/openmw/mwlua/types/npc.cpp index 1b4161d923..7e1bb0288b 100644 --- a/apps/openmw/mwlua/types/npc.cpp +++ b/apps/openmw/mwlua/types/npc.cpp @@ -246,6 +246,17 @@ namespace MWLua throw std::runtime_error("NPC or Player expected"); }; + npc["setWerewolf"] = [context](const Object& obj, bool werewolf) -> void { + const MWWorld::Ptr& ptr = obj.ptr(); + if (!ptr.getClass().isNpc()) + throw std::runtime_error("NPC or Player expected"); + context.mLuaManager->addAction( + [obj = Object(ptr), werewolf] { + MWBase::Environment::get().getMechanicsManager()->setWerewolf(obj.ptr(), werewolf); + }, + "setWerewolfAction"); + }; + npc["getDisposition"] = [](const Object& o, const Object& player) -> int { const MWWorld::Class& cls = o.ptr().getClass(); verifyPlayer(player); From dcbda0cbaa47095ac093c6ff2578d8c8ffafe513 Mon Sep 17 00:00:00 2001 From: Nova Date: Thu, 23 Oct 2025 20:06:53 -0400 Subject: [PATCH 2/5] Forgot the luamanagerimp.hpp include. --- apps/openmw/mwlua/types/npc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/openmw/mwlua/types/npc.cpp b/apps/openmw/mwlua/types/npc.cpp index 7e1bb0288b..83e51c1b89 100644 --- a/apps/openmw/mwlua/types/npc.cpp +++ b/apps/openmw/mwlua/types/npc.cpp @@ -19,6 +19,7 @@ #include "../classbindings.hpp" #include "../localscripts.hpp" +#include "../luamanagerimp.hpp" #include "../racebindings.hpp" #include "../stats.hpp" From 5a7678361678756586ef305f575cacacf3e2627f Mon Sep 17 00:00:00 2001 From: Nova Date: Wed, 12 Nov 2025 22:29:16 -0500 Subject: [PATCH 3/5] Added documentation. --- files/lua_api/openmw/types.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index 09cb7b24fa..b5c57f289e 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -1088,6 +1088,17 @@ -- @param openmw.core#GameObject actor -- @return #boolean +--- +-- Turn an NPC or player into werewolf form or back to normal form. +-- Can only be used in global scripts or on self in local scripts. +-- @function [parent=#NPC] setWerewolf +-- @param openmw.core#GameObject actor The NPC or player to transform +-- @param #boolean werewolf True to transform into werewolf, false to transform back to normal +-- @usage -- Transform player into werewolf in a global script +-- types.NPC.setWerewolf(player, true) +-- @usage -- Transform self back to normal in a local script +-- types.NPC.setWerewolf(self, false) + --- -- Returns the read-only @{#NpcRecord} of an NPC -- @function [parent=#NPC] record From 87dc3cd0e827998aaa49232f658fc53bf0256f5d Mon Sep 17 00:00:00 2001 From: Nova Date: Thu, 13 Nov 2025 14:45:49 -0500 Subject: [PATCH 4/5] Enforced local scripts can only modify self. Updated documentation to use self and player in examples. --- apps/openmw/mwlua/types/npc.cpp | 3 +++ files/lua_api/openmw/types.lua | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwlua/types/npc.cpp b/apps/openmw/mwlua/types/npc.cpp index 83e51c1b89..f2d78610eb 100644 --- a/apps/openmw/mwlua/types/npc.cpp +++ b/apps/openmw/mwlua/types/npc.cpp @@ -248,6 +248,9 @@ namespace MWLua }; npc["setWerewolf"] = [context](const Object& obj, bool werewolf) -> void { + if (dynamic_cast(&obj) && !dynamic_cast(&obj)) + throw std::runtime_error("Local scripts can modify only self"); + const MWWorld::Ptr& ptr = obj.ptr(); if (!ptr.getClass().isNpc()) throw std::runtime_error("NPC or Player expected"); diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index b5c57f289e..ff07f8dce3 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -1095,9 +1095,9 @@ -- @param openmw.core#GameObject actor The NPC or player to transform -- @param #boolean werewolf True to transform into werewolf, false to transform back to normal -- @usage -- Transform player into werewolf in a global script --- types.NPC.setWerewolf(player, true) +-- player.type.setWerewolf(player, true) -- @usage -- Transform self back to normal in a local script --- types.NPC.setWerewolf(self, false) +-- self.type.setWerewolf(self, false) --- -- Returns the read-only @{#NpcRecord} of an NPC From 1918c81e4d0727a3319270c9cafd33bb3151caff Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Mon, 24 Nov 2025 23:46:48 +0300 Subject: [PATCH 5/5] Bump Lua API revision --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5af12d187..f7b747d53e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...") set(OPENMW_VERSION_MAJOR 0) set(OPENMW_VERSION_MINOR 51) set(OPENMW_VERSION_RELEASE 0) -set(OPENMW_LUA_API_REVISION 103) +set(OPENMW_LUA_API_REVISION 104) set(OPENMW_POSTPROCESSING_API_REVISION 3) set(OPENMW_VERSION_COMMITHASH "")