From 95906a34b37dbd18507c0c5e1bc7611ab2734090 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Tue, 19 Sep 2023 10:59:20 +0200 Subject: [PATCH] Fix #6146 (`actor:setEquipment` doesn't trigger mwscripts) --- apps/openmw/mwlua/types/actor.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwlua/types/actor.cpp b/apps/openmw/mwlua/types/actor.cpp index 08fd98c41c..6edb363cd0 100644 --- a/apps/openmw/mwlua/types/actor.cpp +++ b/apps/openmw/mwlua/types/actor.cpp @@ -66,11 +66,12 @@ namespace MWLua static void setEquipment(const MWWorld::Ptr& actor, const Equipment& equipment) { + bool isPlayer = actor == MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor); std::array usedSlots; std::fill(usedSlots.begin(), usedSlots.end(), false); - auto tryEquipToSlot = [&store, &usedSlots](int slot, const EquipmentItem& item) -> bool { + auto tryEquipToSlot = [&store, &usedSlots, isPlayer](int slot, const EquipmentItem& item) -> bool { auto [it, alreadyEquipped] = findInInventory(store, item, slot); if (alreadyEquipped) return true; @@ -93,7 +94,22 @@ namespace MWLua slot = *firstAllowed; } - store.equip(slot, it); + bool skipEquip = false; + + if (isPlayer) + { + const ESM::RefId& script = itemPtr.getClass().getScript(itemPtr); + if (!script.empty()) + { + MWScript::Locals& locals = itemPtr.getRefData().getLocals(); + locals.setVarByInt(script, "onpcequip", 1); + skipEquip = locals.getIntVar(script, "pcskipequip") == 1; + } + } + + if (!skipEquip) + store.equip(slot, it); + return requestedSlotIsAllowed; // return true if equipped to requested slot and false if slot was changed };