1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-26 06:40:22 +00:00

Merge branch 'onpcequip' into 'master'

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

Closes #6146

See merge request OpenMW/openmw!3437
This commit is contained in:
psi29a 2023-09-20 07:44:56 +00:00
commit 4c3acfbcc0

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;
} }
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 return requestedSlotIsAllowed; // return true if equipped to requested slot and false if slot was changed
}; };