EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Development::Development (https://www.eqemulator.org/forums/forumdisplay.php?f=590)
-   -   default.pl for NPCs without a quest (https://www.eqemulator.org/forums/showthread.php?t=24534)

Knightly 03-02-2008 06:43 PM

default.pl for NPCs without a quest
 
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?

ChaosSlayer 03-02-2008 08:19 PM

a) can pets be somehow separated from rest of npcs?
like check "if pet" ?
b) a rule "npc automaticly return items" true/flase


btw- curently i don't mind my players giving items to any npc for any reason, with one BIG expection - when these bastards (my players :cool: ) give npc a no drop item as means of passing it to another player/alt :-x

cavedude 03-03-2008 12:33 AM

I'm confused? What does this do actually? default.pl already works, both by zone, and server wide. (It goes in the root directory of quests, not templates. Never made sense to me, but it works)

Though, great idea about setting it so that default NPCs auto return items.

Knightly 03-03-2008 05:44 AM

Quote:

I'm confused? What does this do actually? default.pl already works, both by zone, and server wide. (It goes in the root directory of quests, not templates. Never made sense to me, but it works)
D'oh! Teach me to not look before I leap. At any rate, the same rules apply, the default.pl (if it exists) will cause pets to take items as well. So, ignore the code above, but still feel free to answer the question I posed. ;-)

Angelox 03-03-2008 11:26 AM

This would be a great idea, I know there was a default.pl didn't know it worked - and I can't find one now, does anybody see one in their directory?
if so, can they post ?

cavedude 03-13-2008 12:23 AM

This will do it ;) Though, it does not work for bots. I'll have to go through the bot code and see if I can use another object to identify if the NPC is a bot or not.

Code:

sub EVENT_ITEM {
my $owner = $npc->GetOwnerID();
if ($owner > 0) {
}

else {
plugin::return_items(\%itemcount);
}
 }

Oh, and if interested in using my debugging code I used to make sure everything was kosher, here it is. Nothing fancy of course.

Code:

sub EVENT_SAY {
my $owner = $npc->GetOwnerID();
if($text=~/pet/i && $owner == 0){
quest::say("I don't belong to anybody!");
}
elsif($text=~/pet/i){
quest::say("I belong to player, $owner.");
}
 }

Of course, default.pl won't work for NPCs who already have a script associated with them, so I guess one of these days somebody is going to need to tack plugin::return_items(\%itemcount); at the end of every script. *sigh*

Knightly 03-15-2008 11:28 PM

Great script CD. I don't use the bots on my server, so I'm afraid I'll be no help there...but on the plugin::return_items issue, I started writing a crawler script that would update these. Still needs quite a bit of testing, but I've been swamped at work lately so it may be some time before I can finish it up.


All times are GMT -4. The time now is 02:42 AM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.