Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-19-2008, 06:59 PM
AiliaMorisato
Sarnak
 
Join Date: Sep 2005
Posts: 34
Default

finally, the actual command to be added to command.cpp
Code:
void command_advnpcspawn(Client *c, const Seperator *sep)
{
	Mob *target=c->GetTarget();
	char errbuf[MYSQL_ERRMSG_SIZE];
	char *query = 0;
	MYSQL_RES *result;
    MYSQL_ROW row;
	int32 tmp = 0;
	int32 tmp2 = 0;
    int32 last_insert_id = 0;

		if (strcasecmp(sep->arg[1], "maketype") == 0){
			if(target && target->IsNPC())
			{
			database.NPCSpawnDB(6, zone->GetShortName(), c, target->CastToNPC());
			}
			else
			c->Message(0, "Target Required!");
		}
		else if (strcasecmp(sep->arg[1], "makegroup") == 0) {
			if(sep->arg[2])
			{
				if (!database.RunQuery(query, MakeAnyLenString(&query, "INSERT INTO spawngroup (name,spawn_limit,dist,max_x,min_x,max_y,min_y,delay) VALUES (\"%s\",%i,%f,%f,%f,%f,%f,%i)", sep->arg[2], (sep->arg[3]?atoi(sep->arg[3]):0), (sep->arg[4]?atof(sep->arg[4]):0), (sep->arg[5]?atof(sep->arg[5]):0), (sep->arg[6]?atof(sep->arg[6]):0), (sep->arg[7]?atof(sep->arg[7]):0), (sep->arg[8]?atof(sep->arg[8]):0), (sep->arg[9]?atoi(sep->arg[9]):0)), errbuf, 0, 0, &last_insert_id)) 
				{
					c->Message(0, "Invalid Arguments -- MySQL gave the following error:");
					c->Message(13, errbuf);
				}
				else
				{
				c->LogSQL(query);
				c->Message(0, "Group ID %i created successfully!", last_insert_id);
				}
				safe_delete_array(query);
			}
			else
			{
				c->Message(0, "Format: #advnpdspawn makegroup <name> [spawn limit] [dist] [max x] [min x] [max y] [min y] [delay]");
			}
		}
		else if (strcasecmp(sep->arg[1], "addgroupentry") == 0) {
			if(atoi(sep->arg[2]) && atoi(sep->arg[3]) && atoi(sep->arg[4]))
			{
				if (!database.RunQuery(query, MakeAnyLenString(&query, "INSERT INTO spawnentry (spawngroupID,npcID,chance) VALUES (%i,%i,%i)", atoi(sep->arg[2]), atoi(sep->arg[3]), atoi(sep->arg[4]), errbuf, 0, 0, &last_insert_id)))
				{
					c->Message(0, "Invalid Arguments -- MySQL gave the following error:");
					c->Message(13, errbuf);
				}
				else
				{
				c->LogSQL(query);
				c->Message(0, "NPC %i added to group %i with %i chance!", atoi(sep->arg[3]), atoi(sep->arg[2]), atoi(sep->arg[4]) );
				}
				safe_delete(query);
			}
			else
			{
				c->Message(0, "Format: #advnpdspawn addgroupentry <spawnggroupID> <npcID> <chance>");
			}
		}
		else if (strcasecmp(sep->arg[1], "editgroupbox") == 0) {
			if(atof(sep->arg[2]) && atof(sep->arg[3]) && atof(sep->arg[4]) && atof(sep->arg[5]) && atof(sep->arg[6]) && atof(sep->arg[7]) && atof(sep->arg[8]))
			{
				if (!database.RunQuery(query, MakeAnyLenString(&query, "UPDATE spawngroup SET dist='%f',max_x='%f',min_x='%f',max_y='%f',min_y='%f',delay='%i' WHERE id='%i'", atof(sep->arg[3]),atof(sep->arg[4]),atof(sep->arg[5]),atof(sep->arg[6]),atof(sep->arg[7]),atoi(sep->arg[8]),atoi(sep->arg[2]), errbuf, 0, 0, &last_insert_id)))
				{
					c->Message(0, "Invalid Arguments -- MySQL gave the following error:");
					c->Message(13, errbuf);
				}
				else
				{
				c->LogSQL(query);
				c->Message(0, "Group ID %i created successfully!", last_insert_id);
				}
				safe_delete_array(query);
			}
			else
			{
				c->Message(0, "Format: #advnpdspawn editgroupbox <spawngroupID> <dist> <max x> <min x> <max y> <min y> <delay>");
			}
		}
		else if (strcasecmp(sep->arg[1], "cleargroupbox") == 0) {
			if(atoi(sep->arg[2]))
			{
				if (!database.RunQuery(query, MakeAnyLenString(&query, "UPDATE spawngroup SET dist='0',max_x='0',min_x='0',max_y='0',min_y='0',delay='0' WHERE id='%i'",atoi(sep->arg[2])), errbuf, 0, 0, &last_insert_id)) 
				{
					c->Message(0, "Invalid Arguments -- MySQL gave the following error:");
					c->Message(13, errbuf);
				}
				else
				{
				c->LogSQL(query);
				c->Message(0, "Group ID %i created successfully!", last_insert_id);
				}
				safe_delete_array(query);
			}
			else
			{
				c->Message(0, "Format: #advnpdspawn cleargroupbox <spawngroupID>");
			}
		}
		else if (strcasecmp(sep->arg[1], "addgroupspawn") == 0 && atoi(sep->arg[2])!=0) {
			database.NPCSpawnDB(5, zone->GetShortName(), c, 0, atoi(sep->arg[2]));
			c->Message(0, "Mob of group %i added successfully!", atoi(sep->arg[2]));
		}
		else if (strcasecmp(sep->arg[1], "removegroupspawn") == 0) {
			if (!target || !target->IsNPC())
				c->Message(0, "Error: Need an NPC target.");
			else {
				Spawn2* s2 = target->CastToNPC()->respawn2;

				if(!s2) {
					c->Message(0, "removegroupspawn FAILED -- cannot determine which spawn entry in the database this mob came from.");
				}
				else
				{
					if(database.RunQuery(query, MakeAnyLenString(&query, "DELETE FROM spawn2 WHERE id='%i'",s2->GetID()), errbuf))
					{
						c->LogSQL(query);
						c->Message(0, "Spawnpoint Removed successfully.");
						target->Depop(false);
					}
					else
					{
						c->Message(13, "Update failed! MySQL gave the following error:");
						c->Message(13, errbuf);
	  				}
					safe_delete_array(query);
				}
			} 
		}
		else if (strcasecmp(sep->arg[1], "movespawn") == 0) {
			if (!target || !target->IsNPC())
				c->Message(0, "Error: Need an NPC target.");
			else {
				Spawn2* s2 = target->CastToNPC()->respawn2;

				if(!s2) {
					c->Message(0, "movespawn FAILED -- cannot determine which spawn entry in the database this mob came from.");
				}
				else
				{
					if(database.RunQuery(query, MakeAnyLenString(&query, "UPDATE spawn2 SET x='%f', y='%f', z='%f', heading='%f' WHERE id='%i'",c->GetX(), c->GetY(), c->GetZ(), c->GetHeading(),s2->GetID()), errbuf))
					{
						c->LogSQL(query);
						c->Message(0, "Updating coordinates successful.");
						target->CastToNPC()->GMMove(c->GetX(), c->GetY(), c->GetZ(), c->GetHeading());
						target->CastToNPC()->SaveGuardSpot(true);
						target->SendPosition();
					}
					else
					{
						c->Message(13, "Update failed! MySQL gave the following error:");
						c->Message(13, errbuf);
	  				}
					safe_delete_array(query);
				}
			} 
		}
		else if (strcasecmp(sep->arg[1], "testload") == 0 && atoi(sep->arg[2])!=0) {
			database.LoadSpawnGroupsByID(atoi(sep->arg[2]),&zone->spawn_group_list);
			c->Message(0, "Group %i loaded successfully!", atoi(sep->arg[2]));
		}
		else {
			c->Message(0, "Error: #advnpcspawn: Invalid command.");
			c->Message(0, "Usage: #advnpcspawn [maketype|makegroup|addgroupentry|addgroupspawn]");
			c->Message(0, "Usage: #advnpcspawn [removegroupspawn|movespawn|editgroupbox|cleargroupbox]");
		}
}
Hope thats everything, probably forgot some header changes but those should be easy enough to fix.

Code currently being used on the server EDGE as our primary worldbuilding tool due to not creating redundant spawngroups and spawnentries allowing much faster queries and less redundancy in the database.
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:11 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 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3