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 around line 215 (under the Grids/Paths heading), add
Code:
int GetHighestWaypoint(uint32 zoneid, int32 gridid);
In
zone/waypoints.cpp around line 1300 (the end of the file), add
Code:
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 around line 2345, change
Code:
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
Code:
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");
}