I've been working lately on making it so that NPCs return items when they've no use for them. Rather than go in deep and rewrite the item & quest handling code, I thought it would be easier if I just had a default quest file that NPCs used when they don't have an existing quest file. This allows me to leave the current quest files completely alone, but still make changes to NPC item handling.
This is what I have so far (and it works very well, except for the exceptions noted below). Change zone\embparser.cpp adding the red lines below:
Code:
//if there is no file for the NPC's ID or name,
//try for the NPC's name in the templates directory
//only works if we have gotten the NPC's name above
if(! filefound && ! filefound2) {
bool filefound3 = false;
if(tmpname[0] != 0) {
//revert to just path
filename = "quests/";
filename += QUEST_TEMPLATES_DIRECTORY;
filename += "/";
filename += tmpname;
filename += ".pl";
curmode = questTemplate;
//LogFile->write(EQEMuLog::Debug, " template '%s'", filename.c_str(), filefound2);
} else {
//LogFile->write(EQEMuLog::Debug, " no template name");
filename += itoa(npcid);
filename += ".pl";
curmode = questDefault;
}
tmpf = fopen(filename.c_str(), "r");
if(tmpf != NULL) {
fclose(tmpf);
filefound3 = true;
}
//if we haven't been able to find a quest file
//let's use a default.pl file so we can make
//all NPCs react the same on any event.
if(!filefound3) {
// Try default.pl
filename = "quests/";
filename += QUEST_TEMPLATES_DIRECTORY;
filename += "/";
filename += "default.pl";
curmode = questTemplate;
}
}
Once that is in I created a quest\templates\default.pl with this:
Code:
sub EVENT_ITEM {
plugin::return_items(\%itemcount);
}
So, the exceptions to the "working well" portion are what I would like to discuss. When are the times that you would want an NPC to accept an item when they didn't have a quest for it? I'll give you the obvious one: Pets. The code above will make it so that pets will no longer accept your gifts which is bad (especially for magicians).
So, I'd like to code the exceptions but before I spend a ton of time on this, can anyone think of other times when an NPC rejecting an item would be bad?