From 3771e523f1a778c38a0301b2454fae91c1461f89 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Fri, 9 Jul 2021 00:31:57 +0200 Subject: [PATCH] More object bindings --- apps/openmw/mwlua/luabindings.cpp | 2 +- apps/openmw/mwlua/objectbindings.cpp | 26 ++++++++++++++++++++++++ files/lua_api/openmw/core.lua | 30 ++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwlua/luabindings.cpp b/apps/openmw/mwlua/luabindings.cpp index e50af836b5..ed788eb525 100644 --- a/apps/openmw/mwlua/luabindings.cpp +++ b/apps/openmw/mwlua/luabindings.cpp @@ -25,7 +25,7 @@ namespace MWLua { auto* lua = context.mLua; sol::table api(lua->sol(), sol::create); - api["API_REVISION"] = 4; + api["API_REVISION"] = 5; api["quit"] = [lua]() { std::string traceback = lua->sol()["debug"]["traceback"]().get(); diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index d4ae041549..b7607c8b2c 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -158,6 +158,32 @@ namespace MWLua luaManager->addAction(std::move(action)); }; } + else + { // Only for local scripts + objectT["isOnGround"] = [](const ObjectT& o) + { + return MWBase::Environment::get().getWorld()->isOnGround(o.ptr()); + }; + objectT["isSwimming"] = [](const ObjectT& o) + { + return MWBase::Environment::get().getWorld()->isSwimming(o.ptr()); + }; + objectT["isInWeaponStance"] = [](const ObjectT& o) + { + const MWWorld::Class& cls = o.ptr().getClass(); + return cls.isActor() && cls.getCreatureStats(o.ptr()).getDrawState() == MWMechanics::DrawState_Weapon; + }; + objectT["isInMagicStance"] = [](const ObjectT& o) + { + const MWWorld::Class& cls = o.ptr().getClass(); + return cls.isActor() && cls.getCreatureStats(o.ptr()).getDrawState() == MWMechanics::DrawState_Spell; + }; + objectT["getCurrentSpeed"] = [](const ObjectT& o) + { + const MWWorld::Class& cls = o.ptr().getClass(); + return cls.getCurrentSpeed(o.ptr()); + }; + } } template diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index eed2005cfa..50706b9770 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -127,6 +127,36 @@ -- @param self -- @return #number +------------------------------------------------------------------------------- +-- Current speed. Can be called only from a local script. +-- @function [parent=#GameObject] getCurrentSpeed +-- @param self +-- @return #number + +------------------------------------------------------------------------------- +-- Is the actor standing on ground. Can be called only from a local script. +-- @function [parent=#GameObject] isOnGround +-- @param self +-- @return #boolean + +------------------------------------------------------------------------------- +-- Is the actor in water. Can be called only from a local script. +-- @function [parent=#GameObject] isSwimming +-- @param self +-- @return #boolean + +------------------------------------------------------------------------------- +-- Is the actor in weapon stance. Can be called only from a local script. +-- @function [parent=#GameObject] isInWeaponStance +-- @param self +-- @return #boolean + +------------------------------------------------------------------------------- +-- Is the actor in magic stance. Can be called only from a local script. +-- @function [parent=#GameObject] isInMagicStance +-- @param self +-- @return #boolean + ------------------------------------------------------------------------------- -- Send local event to the object. -- @function [parent=#GameObject] sendEvent