1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-12-18 15:43:10 +00:00

Merge branch 'creeperbutitslua' into 'master'

Add barter gold bindings

Closes #2903

See merge request OpenMW/openmw!5046
This commit is contained in:
Alexei Kotov 2025-12-15 15:32:34 +03:00
commit dba8b21c75
3 changed files with 32 additions and 1 deletions

View file

@ -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 "")

View file

@ -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<const GObject*>(&object) == nullptr && dynamic_cast<const SelfObject*>(&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<sol::table> damageLua = options.get<sol::optional<sol::table>>("damage");
std::map<std::string, float> damageCpp;

View file

@ -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