diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index d72d778688..4aea21f948 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -164,6 +164,8 @@ namespace MWLua }); objectT["position"] = sol::readonly_property( [](const ObjectT& o) -> osg::Vec3f { return o.ptr().getRefData().getPosition().asVec3(); }); + objectT["scale"] + = sol::readonly_property([](const ObjectT& o) -> float { return o.ptr().getCellRef().getScale(); }); objectT["rotation"] = sol::readonly_property( [](const ObjectT& o) -> osg::Vec3f { return o.ptr().getRefData().getPosition().asRotationVec3(); }); objectT["startingPosition"] = sol::readonly_property( @@ -285,6 +287,10 @@ namespace MWLua if constexpr (std::is_same_v) { // Only for global scripts + objectT["setScale"] = [context](const GObject& object, float scale) { + context.mLuaManager->addAction( + [object, scale] { MWBase::Environment::get().getWorld()->scaleObject(object.ptr(), scale); }); + }; objectT["addScript"] = [context](const GObject& object, std::string_view path, sol::object initData) { const LuaUtil::ScriptsConfiguration& cfg = context.mLua->getConfiguration(); std::optional scriptId = cfg.findId(path); diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index eefdc322e6..4fe9b082a5 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -151,6 +151,7 @@ -- @field #string contentFile Lower cased file name of the content file that defines this object; nil for dynamically created objects. -- @field #boolean enabled Whether the object is enabled or disabled. Global scripts can set the value. Items in containers or inventories can't be disabled. -- @field openmw.util#Vector3 position Object position. +-- @field #number scale Object scale. -- @field openmw.util#Vector3 rotation Object rotation (ZXY order). -- @field openmw.util#Vector3 startingPosition The object original position -- @field openmw.util#Vector3 startingRotation The object original rotation @@ -209,6 +210,13 @@ -- @param self -- @param #string scriptPath Path to the script in OpenMW virtual filesystem. +--- +-- Sets the object's scale. +-- Can be called only from a global script. +-- @function [parent=#GameObject] setScale +-- @param self +-- @param #number scale Scale desired in game. + --- -- Moves object to given cell and position. -- Can be called only from a global script.