Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-19-2004, 08:57 AM
Cisyouc
Demi-God
 
Join Date: Jun 2004
Location: Heaven.
Posts: 1,260
Default Adding Perl Functions in New Quest System

In this tutorial I will be demonstrating how to add functions using the new perl quest system by FatherNitwit; similar to the tutorial for the old system written by Cofruben.

In this example I will be creating a completely useless function but it should show how all the features work. It will be quest::qcalc();. The function will bascially just add the 2 numeric parameters and display them to the client.

First, start by opening up questmgr.h and go to line ~109 or about here:
Code:
	void clear_proximity();
Below this, insert this line:
Code:
	void	qcalc(int numberone, int numbertwo);
Now open up questmgr.cpp and head to line ~1007 or:
Code:
void QuestManager::clear_proximity() {
	safe_delete(npc->proximity);
	entity_list.RemoveProximity(npc->GetID());
}
Below this, add:
Code:
void QuestManager::qcalc(int numberone, int numbertwo)
{
	Client *c = GetInitiator();
	int result = numberone+numbertwo;
	char* resultmessage;
	sprintf(resultmessage, "Quest Calculator 1.0: %i + %i = %i", numberone, numbertwo, result);
	c->Message(15, resultmessage);
}
GetInitiator(); gets your client class so any function after that (c->Message(int,char*) in this example) would be the equal as c->CastToClient()->...

Now open up perlparser.cpp and go to line ~193, where you should see the ending of
Code:
XS(XS_EntityList_new)
{
	dXSARGS;
	if (items != 1)
		Perl_croak(aTHX_ "Usage: EntityList::new()");
	{
		EntityList *		RETVAL;

		RETVAL = &entity_list;
		ST(0) = sv_newmortal();
		if(RETVAL)
			sv_setref_pv(ST(0), "EntityList", (void*)RETVAL);
	}
	XSRETURN(1);
}

#endif
After this, add in the qcalc code:
Code:
XS(XS__qcalc);		 //Defines the function
XS(XS__qcalc)		//Adding the function
{
	dXSARGS;		//Retrieves quest args
	if (items != 2)			//Number of args used
		Perl_croak(aTHX_ "Usage: quest::qcalc(int, int);");		//Return an error
	int x = SvUV(ST(0));		 //Load Argument '0'
	int y = SvUV(ST(1));		//Load Argument '1'

	quest_manager.qcalc(x, y);		/*load QuestManager::qcalc(int numberone, int numbertwo); with parameters x and y (see above definitions)*/
}
Finally, at around line 1277, add in after
Code:
XS_VERSION_BOOTCHECK ;
Add this:
Code:
newXS(strcpy(buf, "qcalc"), XS__qcalc, file);
Enjoy your new function...and hopefully you'll come up with better ideas than me...
__________________
namespace retval { template <class T> class ReturnValueGen { private: T x; public: ReturnValueGen() { x = 0; }; T& Generator() { return x; }; }; } int main() { retval::ReturnValueGen<int> retvalue; return retvalue.Generator(); }
C++ is wonderful.
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 03:56 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3