Skip to content

Commit 93c4424

Browse files
committed
Merge branch 'werewolf-lua-api' into 'master'
Add Lua API for werewolf state management See merge request OpenMW/openmw!4940
2 parents 0d4bff8 + 1918c81 commit 93c4424

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
8282
set(OPENMW_VERSION_MAJOR 0)
8383
set(OPENMW_VERSION_MINOR 51)
8484
set(OPENMW_VERSION_RELEASE 0)
85-
set(OPENMW_LUA_API_REVISION 103)
85+
set(OPENMW_LUA_API_REVISION 104)
8686
set(OPENMW_POSTPROCESSING_API_REVISION 3)
8787

8888
set(OPENMW_VERSION_COMMITHASH "")

apps/openmw/mwlua/types/npc.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "../classbindings.hpp"
2121
#include "../localscripts.hpp"
22+
#include "../luamanagerimp.hpp"
2223
#include "../racebindings.hpp"
2324
#include "../stats.hpp"
2425

@@ -246,6 +247,20 @@ namespace MWLua
246247
throw std::runtime_error("NPC or Player expected");
247248
};
248249

250+
npc["setWerewolf"] = [context](const Object& obj, bool werewolf) -> void {
251+
if (dynamic_cast<const LObject*>(&obj) && !dynamic_cast<const SelfObject*>(&obj))
252+
throw std::runtime_error("Local scripts can modify only self");
253+
254+
const MWWorld::Ptr& ptr = obj.ptr();
255+
if (!ptr.getClass().isNpc())
256+
throw std::runtime_error("NPC or Player expected");
257+
context.mLuaManager->addAction(
258+
[obj = Object(ptr), werewolf] {
259+
MWBase::Environment::get().getMechanicsManager()->setWerewolf(obj.ptr(), werewolf);
260+
},
261+
"setWerewolfAction");
262+
};
263+
249264
npc["getDisposition"] = [](const Object& o, const Object& player) -> int {
250265
const MWWorld::Class& cls = o.ptr().getClass();
251266
verifyPlayer(player);

files/lua_api/openmw/types.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,17 @@
10881088
-- @param openmw.core#GameObject actor
10891089
-- @return #boolean
10901090

1091+
---
1092+
-- Turn an NPC or player into werewolf form or back to normal form.
1093+
-- Can only be used in global scripts or on self in local scripts.
1094+
-- @function [parent=#NPC] setWerewolf
1095+
-- @param openmw.core#GameObject actor The NPC or player to transform
1096+
-- @param #boolean werewolf True to transform into werewolf, false to transform back to normal
1097+
-- @usage -- Transform player into werewolf in a global script
1098+
-- player.type.setWerewolf(player, true)
1099+
-- @usage -- Transform self back to normal in a local script
1100+
-- self.type.setWerewolf(self, false)
1101+
10911102
---
10921103
-- Returns the read-only @{#NpcRecord} of an NPC
10931104
-- @function [parent=#NPC] record

0 commit comments

Comments
 (0)