diff --git a/CMakeLists.txt b/CMakeLists.txt index d7571dbc1e..4c99b8029d 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 108) +set(OPENMW_LUA_API_REVISION 109) set(OPENMW_POSTPROCESSING_API_REVISION 4) set(OPENMW_VERSION_COMMITHASH "") diff --git a/apps/openmw/mwlua/types/actor.cpp b/apps/openmw/mwlua/types/actor.cpp index 33e88c4ea2..a58225f454 100644 --- a/apps/openmw/mwlua/types/actor.cpp +++ b/apps/openmw/mwlua/types/actor.cpp @@ -421,6 +421,24 @@ namespace MWLua return ptr.getClass().getCapacity(ptr); }; + actor["getBarterGold"] = [](const Object& object) -> int { + const MWWorld::Ptr ptr = object.ptr(); + return ptr.getClass().getCreatureStats(ptr).getGoldPool(); + }; + + actor["setBarterGold"] = [context](const Object& object, int gold) { + if (gold < 0) + throw std::runtime_error("Barter gold must be positive"); + if (dynamic_cast(&object) == nullptr && dynamic_cast(&object) == nullptr) + throw std::runtime_error("Can only be used in global scripts or in local scripts on self."); + context.mLuaManager->addAction( + [obj = Object(object), gold] { + const MWWorld::Ptr ptr = obj.ptr(); + ptr.getClass().getCreatureStats(ptr).setGoldPool(gold); + }, + "SetBarterGoldAction"); + }; + actor["_onHit"] = [context](const SelfObject& self, const sol::table& options) { sol::optional damageLua = options.get>("damage"); std::map damageCpp; diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index ff07f8dce3..ecb64910a7 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -22,6 +22,19 @@ -- @param openmw.core#GameObject actor -- @return #number +--- +-- Get the actor's current barter gold. +-- @function [parent=#Actor] getBarterGold +-- @param openmw.core#GameObject actor +-- @return #number + +--- +-- Set the actor's current barter gold. +-- Available in global and local scripts. Can only be used on self in local scripts. +-- @function [parent=#Actor] setBarterGold +-- @param openmw.core#GameObject actor +-- @param #number amount + --- -- Check if the given actor is dead (health reached 0, so death process started). -- @function [parent=#Actor] isDead