View Single Post
  #1  
Old 12-13-2013, 04:48 PM
quido
Fire Beetle
 
Join Date: Oct 2009
Posts: 16
Default New Quest Function help

So I'm trying to add a new quest function to my build and I attempted to follow the instructions at the top of questmgr.cpp to do so.

Quote:
Assuming you want to add a new perl quest function named joe
that takes 1 integer argument....

1. Add the prototype to the quest manager:
questmgr.h: add (~line 50)
void joe(int arg);

2. Define the actual function in questmgr.cpp:
void QuestManager::joe(int arg) {
//... do something
}

3. Copy one of the XS routines in perlparser.cpp, preferably
one with the same number of arguments as your routine. Rename
as needed.
Finally, add your routine to the list at the bottom of perlparser.cpp


4.
If you want it to work in old mode perl and .qst, edit parser.cpp
Parser::ExCommands (~line 777)
else if (!strcmp(command,"joe")) {
quest_manager.joe(atoi(arglist[0]));
}

And then at then end of embparser.cpp, add:
"sub joe{push(@cmd_queue,{func=>'joe',args=>join(',',@_ )});}"
Ok so I added my declaration in questmgr.h in public:

Code:
void InitiateEncounter(char *engager, int mob_index);
And I added an empty function definition in questmgr.cpp:

Code:
void QuestManager::InitiateEncounter(char *engager, int mob_index)
{

}
Now I couldn't find the file perlparser.cpp in the current release, but it appeared such a file got split into a bunch of files all starting with "perl." I found that the function "npcfeature" had the same parameters as my function so I went searching for its XS routine and found it in embparser_api.cpp. So I copied this routine and changed the appropriate names etc:

Code:
XS(XS__InitiateEncounter);
XS(XS__InitiateEncounter)
{
	dXSARGS;
	if (items != 2)
		Perl_croak(aTHX_ "Usage: InitiateEncounter(FTEer, mob_id)");

	char *	fte	= (char *)SvPV_nolen(ST(0));
	int		mobid	= (int)SvIV(ST(1));

	quest_manager.InitiateEncounter(fte, mobid);

	XSRETURN_EMPTY;
}
and then I added the routine to the list at the bottom:

Code:
newXS(strcpy(buf, "InitiateEncounter"), XS__InitiateEncounter, file);

When I try to use the function in an EVENT_COMBAT subroutine for Severilous, it hangs/dies at the invocation.

Code:
sub EVENT_COMBAT {
	if ($combat_state == 1)
	{
		quest::shout("you stink!!!");
		quest::InitiateEncounter("jerk", 7);
		quest::shout("you super stink!!!");
	}
}
I get the first shout, but not the second. What am I doing wrong? Should my XS routine be placed somewhere else? Or do I need to follow step 4 also? I couldn't find the file for those instructions.

I would greatly appreciate any help I could get on this subject - thanks!
Reply With Quote