Thread: Zone instancing
View Single Post
  #5  
Old 09-17-2008, 10:24 AM
Rocker8956
Hill Giant
 
Join Date: Sep 2007
Posts: 117
Default

Here is the code for setting a group’s instance flags through quests. This will allow the whole group to zone into the same instance.
Please note, I have no experience writing quests so this is untested. I appreciate any feedback.

zone\perlparser.cpp
Insert at the end around line 1914
Code:
newXS(strcpy(buf, "setgroupinstflag"), XS__setgroupinstflag, file);
zone\perparser.cpp
insert around line 1758
Code:
XS(XS__setgroupinstflag);
XS(XS__setgroupinstflag)
{
	dXSARGS;
	if (items != 2)
		Perl_croak(aTHX_ "Usage: setgroupinstflag(charID, orginalZoneID)");

	int32	charID = (int)SvIV(ST(0));
	int32	orgZoneID = (int)SvIV(ST(1));

	quest_manager.setgroupinstflag(charID, orgZoneID);

	XSRETURN_EMPTY;
}
zone\questmgr.h
Insert around line 151
Code:
void setgroupinstflag(int32 charID, int32 orgZoneID);
zone\questmgr.cpp
Insert at the end
Code:
void QuestManager::setgroupinstflag(int32 charID, int32 orgZoneID)
{
	database.setGroupInstFlagNum(charID, orgZoneID);
}
common\database.cpp
Insert at the end
Code:
void Database::setGroupInstFlagNum(int32 charID, int32 orgZoneID)
{
	char errbuf[MYSQL_ERRMSG_SIZE];
    char *query = 0;
    MYSQL_RES *result;
    MYSQL_ROW row;
	int32 groupid = 0;
	int instFlag = 0;
	int numCharsInGroup = 0; // Used to count number of characters in group
	
	// Get the current instant flag number
	if (RunQuery(query, MakeAnyLenString(&query, "SELECT value FROM variables WHERE varname = 'curInstFlagNum'"), errbuf, &result))
	{
		safe_delete_array(query);
		if (mysql_num_rows(result) == 1) {
			row = mysql_fetch_row(result);
			instFlag = atoi(row[0]);
			mysql_free_result(result);
		}
		mysql_free_result(result);
	}
	else {
		cerr << "Error in GetCurInstFlagNum query '" << query << "' " << errbuf << endl;
		safe_delete_array(query);
	}
	// Find out what group the character is in
	if (RunQuery(query, MakeAnyLenString(&query, "SELECT groupid from group_id where charid=%i", charID), errbuf, &result)) {
		if((row = mysql_fetch_row(result)))
		{
			if(row[0])
				groupid=atoi(row[0]);
		}
		else
			printf("Unable to get group id, char not found!\n");
		mysql_free_result(result);
	}
	else
			printf("Unable to get group id: %s\n",errbuf);
	safe_delete_array(query);
	// Find out how many other characters are in the group
	if (RunQuery(query, ("SELECT COUNT(charid) FROM group_id WHERE groupid=%i", groupid), errbuf, &result)) {
		safe_delete_array(query);
		row = mysql_fetch_row(result);
		if (row && row[0])
		{ 
			numCharsInGroup = atoi(row[0]);
			mysql_free_result(result);
		}
	}
	// Select the character IDs of the characters in the group
	if (RunQuery(query, MakeAnyLenString(&query, "SELECT charid from group_id where groupid='%i'", groupid), errbuf, &result))
	{
		int i = 0;
		// Set each group members instflag
		while ((i <= numCharsInGroup)) 
		{
			charID = atoi(row[i]);
			if (RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET instZflagNum=%i, instZOrgID=%i WHERE id=%i", instFlag, orgZoneID, charID), errbuf, &result))
			{
				safe_delete_array(query);
				mysql_free_result(result);
			}
			else {
				cerr << "Error in setCharInstFlagNum query '" << query << "' " << errbuf << endl;
				safe_delete_array(query);
			}
			i++;
		}
			safe_delete_array(query);
			mysql_free_result(result);
	}
	// Increment the curInstFlagNum
	instFlag++;

	if (RunQuery(query, MakeAnyLenString(&query, "UPDATE variables SET value=%i WHERE varname='curInstFlagNum'", instFlag), errbuf, &result))
	{
		safe_delete_array(query);
		mysql_free_result(result);
	}
	else {
		cerr << "Error in incrCurInstFlagNum query '" << query << "' " << errbuf << endl;
		safe_delete_array(query);
	}
}
common\database.h
Insert at the end
Code:
void	setGroupInstFlagNum(int32 charID, int32 orgZoneID);