The issue in question is that bound items do not re-equip after the spell expires. I checked, and in the released openmw version NPCs already requip their items, though Balmora's favorite Khajiit friend did not recast his devil weapon's bound effect after it expired. In the version of OpenMW I compiled from the github, however, he did recast it. Point being, actors already work (for weapons at least). I could not find an NPC that casts bound armor spells but if they don't work the code to run an autoequip is pretty simplistic and preferable from storing records for every NPC.
I have the following, with the red text being my (two) additions
Code: Select all
actors.cpp
void adjustBoundItem (const std::string& item, bool bound, const MWWorld::Ptr& actor)
{
if (bound)
{
if (actor.getClass().getContainerStore(actor).count(item) == 0)
{
MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
MWWorld::Ptr newPtr = *store.MWWorld::ContainerStore::add(item, 1, actor);
//Store pointer to previously equiped item
MWWorld::Ptr BoundPtr = *store.getSlot(newPtr.getContainerStore()->getType(newPtr));
MWWorld::ActionEquip action(newPtr);
action.execute(actor);
MWWorld::ConstContainerStoreIterator rightHand = store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
// change draw state only if the item is in player's right hand
if (actor == MWMechanics::getPlayer()
&& rightHand != store.end() && newPtr == *rightHand)
{
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
}
}
}
else
{
actor.getClass().getContainerStore(actor).remove(item, 1, actor);
//If actor is player, equip the player's previous item.
if (actor == MWMechanics::getPlayer())
{
//load pointer and actionequip it.
}
}
}
edit: Color tags don't actually work in code tags (unfortunate) so I've just formatted my additions so they stand out.