From 25d1b18b75c1667014fa76ead9f7f6d1fa29d4bf Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sat, 13 Dec 2025 20:09:30 +0100 Subject: [PATCH] Add barter gold bindings --- apps/openmw/mwlua/types/actor.cpp | 16 ++++++++++++++++ files/lua_api/openmw/types.lua | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/apps/openmw/mwlua/types/actor.cpp b/apps/openmw/mwlua/types/actor.cpp index 33e88c4ea2..5e75c00182 100644 --- a/apps/openmw/mwlua/types/actor.cpp +++ b/apps/openmw/mwlua/types/actor.cpp @@ -421,6 +421,22 @@ 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 SelfObject& object, int gold) { + if (gold < 0) + throw std::runtime_error("Barter gold must be positive"); + 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..d9be89a9cb 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. +-- 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