1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-01 10:09:48 +00:00

Fix #6146 (actor:setEquipment doesn't trigger mwscripts)

This commit is contained in:
Petr Mikheev 2023-09-19 10:59:20 +02:00
parent 38d0ece366
commit 95906a34b3

View file

@ -66,11 +66,12 @@ namespace MWLua
static void setEquipment(const MWWorld::Ptr& actor, const Equipment& equipment) 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); MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
std::array<bool, MWWorld::InventoryStore::Slots> usedSlots; std::array<bool, MWWorld::InventoryStore::Slots> usedSlots;
std::fill(usedSlots.begin(), usedSlots.end(), false); 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); auto [it, alreadyEquipped] = findInInventory(store, item, slot);
if (alreadyEquipped) if (alreadyEquipped)
return true; return true;
@ -93,7 +94,22 @@ namespace MWLua
slot = *firstAllowed; slot = *firstAllowed;
} }
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); store.equip(slot, it);
return requestedSlotIsAllowed; // return true if equipped to requested slot and false if slot was changed return requestedSlotIsAllowed; // return true if equipped to requested slot and false if slot was changed
}; };