From 42ea43c3d1a0c6b525596170476eecd08799eacf Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 28 May 2014 18:45:07 +0200 Subject: [PATCH] Fix container scripts not getting removed properly on cell change Broken by f99eda1a543c7 --- apps/openmw/mwworld/containerstore.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 2496a6eff..8a076c3fc 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -229,22 +229,26 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr std::string script = item.getClass().getScript(item); if(script != "") { - CellStore *cell; - - MWBase::Environment::get().getWorld()->getLocalScripts().add(script, item); - - if(&(player.getClass().getContainerStore (player)) == this) + if (actorPtr == player) { - cell = 0; // Items in player's inventory have cell set to 0, so their scripts will never be removed - - // Set OnPCAdd special variable, if it is declared - item.getRefData().getLocals().setVarByInt(script, "onpcadd", 1); + // Items in player's inventory have cell set to 0, so their scripts will never be removed + item.mCell = 0; } else - cell = player.getCell(); + { + // Set mCell to the cell of the container/actor, so that the scripts are removed properly when + // the cell of the container/actor goes inactive + item.mCell = actorPtr.getCell(); + } - item.mCell = cell; item.mContainerStore = 0; + + MWBase::Environment::get().getWorld()->getLocalScripts().add(script, item); + + // Set OnPCAdd special variable, if it is declared + // Make sure to do this *after* we have added the script to LocalScripts + if (actorPtr == player) + item.getRefData().getLocals().setVarByInt(script, "onpcadd", 1); } return it;