mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 21:15:36 +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:
commit
4c3acfbcc0
1 changed files with 18 additions and 2 deletions
|
@ -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<bool, MWWorld::InventoryStore::Slots> 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
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue