1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-01 12:15:35 +00:00

Implemented OnPCAdd special variable

Had to edit OpAddItem in miscextensions.cpp, as local variables were not being initialised
for items added through it.
Does not get reset on drop, as per original morrowind.
This commit is contained in:
Tom Mason 2013-02-02 17:36:12 +00:00
parent 0f58e03343
commit f785659297
2 changed files with 34 additions and 2 deletions

View file

@ -50,6 +50,14 @@ namespace MWScript
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), item);
ref.getPtr().getRefData().setCount (count);
// Configure item's script variables
std::string script = MWWorld::Class::get(ref.getPtr()).getScript(ref.getPtr());
if (script != "")
{
const ESM::Script *esmscript = MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (script);
ref.getPtr().getRefData().setLocals(*esmscript);
}
MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr());
}

View file

@ -8,9 +8,11 @@
#include <boost/algorithm/string.hpp>
#include <components/esm/loadcont.hpp>
#include <components/compiler/locals.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/scriptmanager.hpp"
#include "manualref.hpp"
#include "refdata.hpp"
@ -83,9 +85,31 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr)
CellStore *cell;
Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer();
// Items in players inventory have cell set to 0, so their scripts will never be removed
if(&(MWWorld::Class::get (player).getContainerStore (player)) == this)
cell = 0;
{
cell = 0; // Items in players inventory have cell set to 0, so their scripts will never be removed
// Set OnPCAdd special variable, if it is declared
Compiler::Locals locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
int index = locals.getIndex("onpcadd");
char type = locals.getType("onpcadd");
if(index != -1)
{
switch(type)
{
case 's':
item.mRefData->getLocals().mShorts.at (index) = 1; break;
case 'l':
item.mRefData->getLocals().mLongs.at (index) = 1; break;
case 'f':
item.mRefData->getLocals().mFloats.at (index) = 1.0; break;
}
}
}
else
cell = player.getCell();