View Single Post
  #1  
Old 07-04-2008, 02:47 PM
spider661
Discordant
 
Join Date: Oct 2005
Location: michigain
Posts: 260
Default adding new code help

im trying to add a new command for quest i came up with the ideal when i was trying to do a quest that did not work the way i wanted. well someone posted code that should work the way i wanted but i decided to go ahead and make the code just to do it as a learning exp well i am havering problems so ill post it here to see if anyone can see whats wrong.

what this should do is read a variable from a new table called server_globals and then the quest should return the correct int.
questmgr.cpp
Code:
////////////////////////////////////////////ADDED/////////////////////////////////////
int QuestManager::GetServerInt(const char *varname, int npcid, int zoneid)
{
	char errbuf[MYSQL_ERRMSG_SIZE];
    char *query = 0;
    MYSQL_RES *result;
	MYSQL_ROW row;
	int var = 0;

if(npcid < 1){
npcid = 0;}

if(zoneid < 1){
zoneid = 0;}

		if (database.RunQuery(query, MakeAnyLenString(&query, "SELECT value FROM server_globals WHERE name='%s' AND npcid = %i AND zoneid = %i", varname, npcid, zoneid), errbuf, &result)){
		safe_delete_array(query);
		if (mysql_num_rows(result) == 1){
			row = mysql_fetch_row(result);
				if (row[0])
					var = atoi(row[0]);
			}
		mysql_free_result(result);
		}
		else{
			LogFile->write(EQEMuLog::Error, "Error in GetServerInt query", query, errbuf);
			//cerr << "Error in GetServerInt query '" << query << "' " << errbuf << endl;
			safe_delete_array(query);
			}

	return var;
}
///////////////END ADD//////////////////////////////////////////////////////////////////////
questmgr.h
Code:
///////////////////ADDED//////////////////////////////////////////////////
	int QuestManager::GetServerInt(const char *varname, int npcid = 0, int zoneid = 0);
///////////////////DONE ADD///////////////////////////////////////////////
perlparser.cpp
Code:
/////////////////////////ADDED//////////////////////////////////////////////////
XS(XS__GetServerInt);
XS(XS__GetServerInt)
{
	dXSARGS;
	if (items == 1)
	{
		char *		varname = (char *)SvPV_nolen(ST(0));
		quest_manager.GetServerInt(varname);
	}
	else if(items == 3)
	{
		char *		varname = (char *)SvPV_nolen(ST(0));
		int	npcid = (int)SvIV(ST(1));
		int	zoneid = (int)SvIV(ST(2));
		quest_manager.GetServerInt(varname, npcid, zoneid);		
	}
	else 
	{
		Perl_croak(aTHX_ "Usage: GetServerInt(varname,npcid = 0,zoneid = 0)");
	}
	XSRETURN_EMPTY;
}
//////////////////////////END ADD////////////////////////////////////////////
/*



added at end
/////////////////////ADDED//////////////////////////////////////////////////////
		newXS(strcpy(buf, "GetServerInt"), XS__GetServerInt, file);
////////////////////END ADDED///////////////////////////////////////////////////
the quest on the npc
Code:
sub EVENT_SAY
{
if ($text =~/Hail/i)
 {
if(quest::GetServerInt("myquest") == 10)
{
quest::say ("yay it worked");
}
else
{
quest::say ("no 10 here");
}
 }
}
the error eqemu_quest_zone_3236.log
Code:
[07.04. - 07:40:02] Use of uninitialized value in numeric eq (==) at quests/qrg/testpet.pl line 6.
i have tryed the quest file many ways and still cant get it working. same error or close to it every time.
Reply With Quote