Jump to content

Calculate Character XY Coordinates?


antiroot

Recommended Posts

Is there a way to use the data in the database to calculate a character's relative coordinates on any given map in the form of X:[0-100],Y:[0-100]

There's a macro for the client that can report this, and is used on many 3rd-party sites to give the location of an object relative to the map it's in.

I would like to be able to query the DB and return these simplified percent based coords rather than the ones that are stored in the DB so i can display character locations on a text output page. I know there's the .gps command, however this returns coordinates relative to (i assume) the world, not the map

Link to comment
Share on other sites

There is this function in mangos:

bool Map2ZoneCoordinates(float& x,float& y,uint32 zone)
{
   WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);

   // if not listed then map coordinates (instance)
   if (!maEntry || maEntry->x2 == maEntry->x1 || maEntry->y2 == maEntry->y1)
       return false;

   x = (x-maEntry->x1)/((maEntry->x2-maEntry->x1)/100);
   y = (y-maEntry->y1)/((maEntry->y2-maEntry->y1)/100);    // client y coord from top to down
   std::swap(x,y);                                         // client have map coords swapped

   return true;
}

If you put in the X and Y world co-ords (such as from .gps) and the zone ID, it will give you the 0-100 co-ords like in the client. This is also outputed when you use .gps (I think it says zone co-ords or something similar.)

Basically, in WorldMapArea.dbc is a list of zones and their boundaries in x1, x2, y1, y2. To convert world co-ordinates into zone co-ordinates, take them, subtract the first boundary co-ordinate, then divide it by the second bounary subtracted by the first boundary, then divide by 100, then swap the X and Y.

For example, let's say you are are at co-ordinates (90, 50) in the world and the zone's bounaries are x1: 100 x2 10 y1 60 y2 0, then you would do

    x = (x - x1) / ((x2 - x1) / 100)
   y = (y - y1) / ((y2 - y1) / 100)

   x = (90 - 100) / ((10 - 100) / 100)
   y = (50 - 60) / ((0 - 60) / 100)

   x = (-10) / ((-90) / 100)
   y = (-10) / ((-60) / 100)

   x = (-10) / (-0.9)
   y = (-10) / (-0.6)

   x = 11.11
   y = 16.67

   then swap these 2

   x = 16.67, y = 11.11

Note that x1 and y1 are always bigger than x2 and y2.

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use