I had the idea last night to try adding a primitive form of scripted spells to OpenMW. I would simply use a new or unused magic effect(Like EXTRA SPELL) and, in the code, detect when the magic effect is on an NPC/Creature. Then, it would write to a variable in the stats class(if that would work) called "scriptOverride". It would set it to the name of the spell, with "_script" added on.
Then, on the npc.cpp, I edited getScript to return the base script if the variable is empty, and the variable if it's not.
I've spent a few hours playing with the code, and I feel like I am really starting to understand some of the code, despite only knowing C#.
But all the consts are really giving me issues.
Here is my getScript:
-
Spoiler: Show
- std::string Npc::getScript (const MWWorld::ConstPtr& ptr) const
{
MWWorld::LiveCellRef<ESM::NPC> *ref = ptr.get<ESM::NPC>();
// NpcCustomData *npcdata = static_cast<const NpcCustomData*>(ptr.getRefData().getCustomData());
MWMechanics::NpcStats& stats = ptr.getClass().getNpcStats(ptr);
std::string scrpt = stats.scriptOverride;
if (!scrpt.empty())
{
return scrpt;
}
//
return ref->mBase->mScript;
}
The major error is : error: invalid conversion from ‘const MWWorld::LiveCellRef<ESM::NPC>*’ to ‘MWWorld::LiveCellRef<ESM::NPC>*’ [-fpermissive]
Is there a better way to do this? I tried changing the parameters to Ptr instead of ConstPtr, and it compiles, but that brings a whole new set of problems.