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 "") diff --git a/apps/openmw/mwlua/types/npc.cpp b/apps/openmw/mwlua/types/npc.cpp index 1b4161d923..f2d78610eb 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" @@ -246,6 +247,20 @@ namespace MWLua throw std::runtime_error("NPC or Player expected"); }; + 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"); + 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); diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index 09cb7b24fa..ff07f8dce3 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 +-- player.type.setWerewolf(player, true) +-- @usage -- Transform self back to normal in a local script +-- self.type.setWerewolf(self, false) + --- -- Returns the read-only @{#NpcRecord} of an NPC -- @function [parent=#NPC] record