From 86c28921aef30d62764127bfab7499660dc9f05b Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Fri, 1 Sep 2023 08:06:34 +0000 Subject: [PATCH] Add function to get current disposition, add baseDisposition to NPC record --- apps/openmw/mwlua/types/npc.cpp | 12 ++++++++++++ files/lua_api/openmw/types.lua | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/apps/openmw/mwlua/types/npc.cpp b/apps/openmw/mwlua/types/npc.cpp index 06bcab243b..d1a91cabc9 100644 --- a/apps/openmw/mwlua/types/npc.cpp +++ b/apps/openmw/mwlua/types/npc.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,8 @@ namespace MWLua = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mScript.serializeText(); }); record["hair"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mHair.serializeText(); }); + record["baseDisposition"] + = sol::readonly_property([](const ESM::NPC& rec) -> int { return (int)rec.mNpdt.mDisposition; }); record["head"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mHead.serializeText(); }); record["isMale"] = sol::readonly_property([](const ESM::NPC& rec) -> bool { return rec.isMale(); }); @@ -54,5 +57,14 @@ namespace MWLua else throw std::runtime_error("NPC or Player expected"); }; + + npc["getDisposition"] = [](const Object& o, const Object& player) -> int { + if (player.ptr() != MWBase::Environment::get().getWorld()->getPlayerPtr()) + throw std::runtime_error("The argument must be a player!"); + const MWWorld::Class& cls = o.ptr().getClass(); + if (!cls.isNpc()) + throw std::runtime_error("NPC expected"); + return MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(o.ptr()); + }; } } diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index ab913bc788..b1746bb2e8 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -714,6 +714,13 @@ -- @param openmw.core#GameObject object -- @return #boolean +--- +-- Returns the current disposition of the provided NPC. This is their derived disposition, after modifiers such as personality and faction relations are taken into account. +-- @function [parent=#NPC] getDisposition +-- @param openmw.core#GameObject object +-- @param openmw.core#GameObject player The player that you want to check the disposition for. +-- @return #number + --- -- Whether the NPC or player is in the werewolf form at the moment. -- @function [parent=#NPC] isWerewolf @@ -736,6 +743,7 @@ -- @field #string hair Path to the hair body part model -- @field #string head Path to the head body part model -- @field #number baseGold The base barter gold of the NPC +-- @field #number baseDisposition NPC's starting disposition -- @field #bool isMale The gender setting of the NPC