PDA

View Full Version : Request to slightly improve add grid way point comand


ChaosSlayer
08-19-2008, 02:27 PM
Greetings!

curently adding grid way points uses following format:

#wp add X Y Z

where X is grid id#, Y pause time, and Z is wp id#

what i propose is to slightly modify this so if Z is omited, the comand will automaticly use curently max Z+1.
this will GREATLY improve easiness of adding new way points.

so instead of running around and typing

#wp add 71 60 1
#wp add 71 60 2
#wp add 71 60 3
#wp add 71 60 4
etc etc etc till my fingers bleed

i will make a hot button with
#wp add 71 60

and span simply spam it at will

alternatuivly if comand line does not work with omited parameters, let say if i use MAX keyword at the end of the line it will auto calculate Z+1 like this:
#wp add 71 60 max

thanks =)

trevius
08-19-2008, 05:43 PM
Ya, that would definitely be useful.

AndMetal
08-20-2008, 01:21 AM
Here's the code for the wp command:
zone/command.cpp (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/zone/command.cpp?revision=1.52&view=markup#l_2256)

2256 void command_wp(Client *c, const Seperator *sep)
2257 {
2258 if (strcasecmp("add",sep->arg[1]) == 0)
2259 database.AddWP(c, atoi(sep->arg[2]),atoi(sep->arg[4]), c->GetX(), c->GetY(), c->GetZ(), atoi(sep->arg[3]),zone->GetZoneID());
2260 else if (strcasecmp("delete",sep->arg[1]) == 0)
2261 database.DeleteWaypoint(c, atoi(sep->arg[2]),atoi(sep->arg[4]),zone->GetZoneID());
2262 else
2263 c->Message(0,"Usage: #wp add/delete grid_num pause wp_num");
2264 }


I'm not sure if this will actually work, but you might be able to do something like this:
zone/zonedb.h (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/zone/zonedb.h?revision=1.14&view=markup#l_187)

/*
* Grids/Paths
*/
int32 GetFreeGrid(int16 zoneid);
void DeleteGrid(Client *c, int32 sg2, int32 grid_num, bool grid_too,int16 zoneid);
void DeleteWaypoint(Client *c, int32 grid_num, int32 wp_num,int16 zoneid);
// int32 AddWP(Client *c, int32 sg2, int16 grid_num, int8 wp_num, float xpos, float ypos, float zpos, int32 pause, float xpos1, float ypos1, float zpos1, int type1, int type2,int16 zoneid);
void AddWP(Client *c, int32 gridid, int32 wpnum, float xpos, float ypos, float zpos, int32 pause, int16 zoneid);
int32 AddWPForSpawn(Client *c, int32 spawn2id, float xpos, float ypos, float zpos, int32 pause, int type1, int type2, int16 zoneid);
void ModifyGrid(Client *c, bool remove, int32 id, int8 type = 0, int8 type2 = 0,int16 zoneid = 0);
void ModifyWP(Client *c, int32 grid_id, int32 wp_num, float xpos, float ypos, float zpos, int32 script=0,int16 zoneid =0);
int8 GetGridType(int32 grid,int32 zoneid);
int8 GetGridType2(int32 grid, int16 zoneid);
bool GetWaypoints(int32 grid, int16 zoneid, int32 num, wplist* wp);
void AssignGrid(Client *client, float x, float y, int32 id);
int GetHighestGrid(uint32 zoneid);
int GetHighestWaypoint(uint32 zoneid, int32 gridid);


zone/waypoints.cpp (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/zone/waypoints.cpp?revision=1.19&view=markup)

int ZoneDatabase::GetHighestWaypoint(uint32 zoneid, int32 gridid) {
char *query = 0;
char errbuff[MYSQL_ERRMSG_SIZE];
MYSQL_RES *result;
MYSQL_ROW row;
int res = 0;
if (RunQuery(query, MakeAnyLenString(&query,
"SELECT COALESCE(MAX(number), 0) FROM grid_entries WHERE zoneid = %i AND gridid = %i",
zoneid, gridid),errbuff,&result)) {
safe_delete_array(query);
if (mysql_num_rows(result) == 1) {
row = mysql_fetch_row(result);
res = atoi( row[0] );
}
mysql_free_result(result);
} else {
LogFile->write(EQEMuLog::Error, "Error in GetHighestWaypoint query '%s': %s", query, errbuff);
safe_delete_array(query);
}

return(res);
}


zone/command.cpp (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/zone/command.cpp?revision=1.52&view=markup#l_2256)

void command_wp(Client *c, const Seperator *sep)
{
if (sep->arg[4] == NULL)
int wp = database.GetHighestWaypoint(zone->GetZoneID(), atoi(sep->arg[2]));
else
int wp = atoi(sep->arg[4]);
if (strcasecmp("add",sep->arg[1]) == 0)
database.AddWP(c, atoi(sep->arg[2]),wp, c->GetX(), c->GetY(), c->GetZ(), atoi(sep->arg[3]),zone->GetZoneID());
else if (strcasecmp("delete",sep->arg[1]) == 0)
database.DeleteWaypoint(c, atoi(sep->arg[2]),atoi(sep->arg[4]),zone->GetZoneID());
else
c->Message(0,"Usage: #wp add/delete grid_num pause wp_num");
}


Hope this helps.

trevius
08-31-2008, 08:06 AM
Going to test this now. I was trying to compile this, but it errored out. I had to change this:
void command_wp(Client *c, const Seperator *sep,)

to this:
void command_wp(Client *c, const Seperator *sep,int wp)

*Edit - still not compiling completely yet.

trevius
09-01-2008, 04:53 AM
If anyone can get this working, I will move the post to server code submissions. I wasn't able to get it to compile, but I don't know what I am doing anyway lol.

AndMetal
09-01-2008, 05:17 PM
What kind of error are you getting?

trevius
09-01-2008, 05:23 PM
I was getting errors about "wp" not being referenced or something like that. I forget the exact error.

AndMetal
09-01-2008, 05:33 PM
I thought it would be fine the way I did this, but I guess maybe not.


zone/command.cpp (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/zone/command.cpp?revision=1.52&view=markup#l_2256)

void command_wp(Client *c, const Seperator *sep)
{
if (sep->arg[4] == NULL)
int wp = database.GetHighestWaypoint(zone->GetZoneID(), atoi(sep->arg[2]));
else
int wp = atoi(sep->arg[4]);
if (strcasecmp("add",sep->arg[1]) == 0)
database.AddWP(c, atoi(sep->arg[2]),wp, c->GetX(), c->GetY(), c->GetZ(), atoi(sep->arg[3]),zone->GetZoneID());
else if (strcasecmp("delete",sep->arg[1]) == 0)
database.DeleteWaypoint(c, atoi(sep->arg[2]),atoi(sep->arg[4]),zone->GetZoneID());
else
c->Message(0,"Usage: #wp add/delete grid_num pause wp_num");
}



Try this instead:

void command_wp(Client *c, const Seperator *sep)
{
int wp;
if (sep->arg[4] == NULL)
wp = database.GetHighestWaypoint(zone->GetZoneID(), atoi(sep->arg[2]));
else
wp = atoi(sep->arg[4]);
if (strcasecmp("add",sep->arg[1]) == 0)
database.AddWP(c, atoi(sep->arg[2]),wp, c->GetX(), c->GetY(), c->GetZ(), atoi(sep->arg[3]),zone->GetZoneID());
else if (strcasecmp("delete",sep->arg[1]) == 0)
database.DeleteWaypoint(c, atoi(sep->arg[2]),atoi(sep->arg[4]),zone->GetZoneID());
else
c->Message(0,"Usage: #wp add/delete grid_num pause wp_num");
}

Let me know if that works. I knew when I wrote it that 2nd one would work, I just figured the other way would be a little cleaner & still work :confused:

Oh well, that's why KLS & Derision are the "devs", and I just tinker :D

trevius
09-01-2008, 06:16 PM
Derision isn't an official Dev yet, but he probably should be :)

I will give that a try later and see if it compiles like that. It looks like that could resolve it. But, I was getting a similar error when trying to compile some code with a rule I made up. I will post more after I get to test it.

ChaosSlayer
09-24-2008, 10:19 AM
So Trev - did you ever managed to get this one working? 8-)

trevius
09-25-2008, 05:56 AM
I guess I never tried the latest code change AndMetal made on this. Now it compiles just fine. Going to test it later after the next server reboot to verify it works. If so, I will sticky this in the Server Code Submissions section :)

ChaosSlayer
09-25-2008, 10:49 AM
that be perfect - trying to populated something as large as West Karana by hand... is simply insane without this feature :grin:

AndMetal
09-28-2008, 07:51 AM
The original code didn't work as intended, but I had a chance to compile & debug, and this is what I came up with.

In zone/zonedb.h (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/zone/zonedb.h?view=log) around line 215 (under the Grids/Paths heading), add
int GetHighestWaypoint(uint32 zoneid, int32 gridid);

In zone/waypoints.cpp (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/zone/waypoints.cpp?view=log) around line 1300 (the end of the file), add

int ZoneDatabase::GetHighestWaypoint(uint32 zoneid, int32 gridid) {
char *query = 0;
char errbuff[MYSQL_ERRMSG_SIZE];
MYSQL_RES *result;
MYSQL_ROW row;
int res = 0;
if (RunQuery(query, MakeAnyLenString(&query,
"SELECT COALESCE(MAX(number), 0) FROM grid_entries WHERE zoneid = %i AND gridid = %i",
zoneid, gridid),errbuff,&result)) {
safe_delete_array(query);
if (mysql_num_rows(result) == 1) {
row = mysql_fetch_row(result);
res = atoi( row[0] );
}
mysql_free_result(result);
} else {
LogFile->write(EQEMuLog::Error, "Error in GetHighestWaypoint query '%s': %s", query, errbuff);
safe_delete_array(query);
}

return(res);
}


And in zone/command.cpp (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/zone/command.cpp?view=log) around line 2345, change

void command_wp(Client *c, const Seperator *sep)
{
if (strcasecmp("add",sep->arg[1]) == 0)
database.AddWP(c, atoi(sep->arg[2]),atoi(sep->arg[4]), c->GetX(), c->GetY(), c->GetZ(), atoi(sep->arg[3]),zone->GetZoneID());
else if (strcasecmp("delete",sep->arg[1]) == 0)
database.DeleteWaypoint(c, atoi(sep->arg[2]),atoi(sep->arg[4]),zone->GetZoneID());
else
c->Message(0,"Usage: #wp add/delete grid_num pause wp_num");
}

to this

void command_wp(Client *c, const Seperator *sep)
{
int wp = atoi(sep->arg[4]);

if (strcasecmp("add",sep->arg[1]) == 0) {
if (wp == 0) //AndMetal: default to highest if it's left blank, or we enter 0
wp = database.GetHighestWaypoint(zone->GetZoneID(), atoi(sep->arg[2])) + 1;
database.AddWP(c, atoi(sep->arg[2]),wp, c->GetX(), c->GetY(), c->GetZ(), atoi(sep->arg[3]),zone->GetZoneID());
}
else if (strcasecmp("delete",sep->arg[1]) == 0)
database.DeleteWaypoint(c, atoi(sep->arg[2]),wp,zone->GetZoneID());
else
c->Message(0,"Usage: #wp add/delete grid_num pause wp_num");
}