diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index 7db7877245..2f3a020971 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -312,11 +312,17 @@ namespace MWLua }; objectT["ownerFactionId"] = sol::property(getOwnerFactionId, setOwnerFactionId); - auto getOwnerFactionRank = [](const ObjectT& o) -> int { return o.ptr().getCellRef().getFactionRank(); }; - auto setOwnerFactionRank = [](const ObjectT& object, int factionRank) { + auto getOwnerFactionRank = [](const ObjectT& o) -> sol::optional { + int rank = o.ptr().getCellRef().getFactionRank(); + if (rank < 0) + return sol::nullopt; + else + return rank; + }; + auto setOwnerFactionRank = [](const ObjectT& object, sol::optional factionRank) { if (std::is_same_v && !dynamic_cast(&object)) throw std::runtime_error("Local scripts can set an owner faction rank only on self"); - object.ptr().getCellRef().setFactionRank(factionRank); + object.ptr().getCellRef().setFactionRank(factionRank.value_or(-1)); }; objectT["ownerFactionRank"] = sol::property(getOwnerFactionRank, setOwnerFactionRank); diff --git a/components/lua/utilpackage.cpp b/components/lua/utilpackage.cpp index 85c5dcdbc1..e9b8e886d2 100644 --- a/components/lua/utilpackage.cpp +++ b/components/lua/utilpackage.cpp @@ -133,7 +133,8 @@ namespace LuaUtil // Lua bindings for Box util["box"] = sol::overload([](const Vec3& center, const Vec3& halfSize) { return Box(center, halfSize); }, - [](const TransformM& transform) { return Box(transform.mM); }); + [](const TransformM& transform) { return Box(transform.mM); }, + [](const TransformQ& transform) { return Box(Vec3(), Vec3(1, 1, 1), transform.mQ); }); sol::usertype boxType = lua.new_usertype("Box"); boxType["center"] = sol::readonly_property([](const Box& b) { return b.mCenter; }); boxType["halfSize"] = sol::readonly_property([](const Box& b) { return b.mHalfSize; }); diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index 44ab4473fa..ccac83bd4b 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -161,7 +161,7 @@ -- @field openmw.util#Transform startingRotation The object original rotation -- @field #string ownerRecordId NPC who owns the object (nil if missing). Global and self scripts can set the value. -- @field #string ownerFactionId Faction who owns the object (nil if missing). Global and self scripts can set the value. --- @field #number ownerFactionRank Rank required to be allowed to pick up the object. Global and self scripts can set the value. +-- @field #number ownerFactionRank Rank required to be allowed to pick up the object (`nil` if any rank is allowed). Global and self scripts can set the value. -- @field #Cell cell The cell where the object currently is. During loading a game and for objects in an inventory or a container `cell` is nil. -- @field #GameObject parentContainer Container or actor that contains (or has in inventory) this object. It is nil if the object is in a cell. -- @field #any type Type of the object (one of the tables from the package @{openmw.types#types}).