Why would we need this ? Guess you have a weapon, just a katana. You have an enchanter item, when you enchant a weapon with it, XX script is attached on the katana which contains special damage triggers in it. Well we can do it by setting only one script, but what if that katana had another script attached that contains general fixes and modifications about ALL weapons before ?
Guess you have a general script for all NPCs like NPC.js, but when you tame a pet, it will also include another script of TamedPet.js, while including NPC.js which contains important modifications for all NPCs.
And a few implementation notes about it like : last attached script is triggered first, if a trigger ends with a special keyword (i haven't decided yet), the same trigger in other scripts won't be called so it will be some kind of overriding functions.
base functions in cBaseObject.cpp
Code: Select all
SCRIPTLIST CBaseObject::GetAttachedScripts( void ) const
{
return attachedScripts;
}
void CBaseObject::attachTrigger( UI16 trig )
{
attachedScripts.push_back(trig);
}
void CBaseObject::detachTrigger( UI16 trig )
{
SCRIPTLIST_ITERATOR it;
it = std::find(attachedScripts.begin(), attachedScripts.end(), trig);
if (it != attachedScripts.end())
attachedScripts.erase(it);
}Code: Select all
SCRIPTLIST GetAttachedScripts( void ) const;
void attachTrigger( UI16 trig );
void detachTrigger( UI16 trig );typedefs.h
Code: Select all
typedef std::vector<UI16> SCRIPTLIST;
typedef std::vector<UI16>::iterator SCRIPTLIST_ITERATOR;
typedef std::vector<UI16>::reverse_iterator SCRIPTLIST_RITERATOR;if possible and needed, can you help implementing this. it came a bit complicated to me, changing everything for it, iterating through attached scripts etc.