From 09f9557ecb516a0a4d0d3db5e0364712a0c21b8a Mon Sep 17 00:00:00 2001 From: Tom Mason Date: Thu, 31 Jan 2013 00:34:16 +0000 Subject: [PATCH] Implemented OnPCEquip special variable --- apps/openmw/mwworld/actionequip.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/apps/openmw/mwworld/actionequip.cpp b/apps/openmw/mwworld/actionequip.cpp index 60260a812b..c519a3ee54 100644 --- a/apps/openmw/mwworld/actionequip.cpp +++ b/apps/openmw/mwworld/actionequip.cpp @@ -3,6 +3,9 @@ #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" +#include "../mwbase/scriptmanager.hpp" + +#include #include "inventorystore.hpp" #include "player.hpp" @@ -35,6 +38,8 @@ namespace MWWorld std::string npcRace = actor.get()->mBase->mRace; + bool equipped = false; + // equip the item in the first free slot for (std::vector::const_iterator slot=slots.first.begin(); slot!=slots.first.end(); ++slot) @@ -91,6 +96,7 @@ namespace MWWorld if (slot == --slots.first.end()) { invStore.equip(*slot, it); + equipped = true; break; } @@ -98,8 +104,16 @@ namespace MWWorld { // slot is not occupied invStore.equip(*slot, it); + equipped = true; break; } } + + /* Set OnPCEquip Variable on item's script, if it has a script with that variable declared */ + if(equipped && actor == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() && MWWorld::Class::get(*it).getScript(*it) != ""){ + int index = MWBase::Environment::get().getScriptManager()->getLocals(MWWorld::Class::get(*it).getScript(*it)).getIndex("onpcequip"); + if(index != -1) + (*it).mRefData->getLocals().mShorts.at (index) = 1; + } } }