When I run C_Map.GetBestMapForUnit("player") it gives me an ID representing the UiMapID which can be found on https://wow.tools/dbc/?dbc=uimap.db2. Now, let’s say I’m in Goldshire… my UiMapID is 37 (Elwynn Forest).
Goldshire is found on areatable.db2 (https://wow.tools/dbc/?dbc=areatable.db2&bc=eb9dc13f6f32a1b4992b61d6217dd6ab#search=Goldshire&page=1) with ID = 87.
Is there any API function that would return 87 instead of 37?
Would you allow me a last question? I don’t think I’m using the right vector to get my current position:
local ui_map_id = C_Map.GetBestMapForUnit("player")
local unit_x, unit_y = UnitPosition("player")
local unit_vector = CreateVector2D(unit_x, unit_y)
local result = C_MapExplorationInfo.GetExploredAreaIDsAtPosition(ui_map_id, unit_vector)
print(result)
You can also skip a step since GetPlayerMapPosition already returns a Vector2D
function GetAreaIDsForPlayer()
local mapID = C_Map.GetBestMapForUnit("player")
local pos = C_Map.GetPlayerMapPosition(mapID, "player")
local areaIDs = C_MapExplorationInfo.GetExploredAreaIDsAtPosition(mapID, pos)
local areaString = areaIDs and table.concat(areaIDs, ", ") or "none"
print(format("MapID=%d, Position=%.3f:%.3f, AreaIDs=%s", mapID, pos.x, pos.y, areaString))
end
But if I understood correctly, GetExploredAreaIDsAtPosition returns the areaIDs that I already explored around my position, which can return more than one location, right?
I’m wondering if I can get my current area ID from the results of this function call.
function MapUtil.FindBestAreaNameAtMouse(mapID, normalizedCursorX, normalizedCursorY)
local exploredAreaIDs = C_MapExplorationInfo.GetExploredAreaIDsAtPosition(mapID, CreateVector2D(normalizedCursorX, normalizedCursorY));
if exploredAreaIDs then
for i, areaID in ipairs(exploredAreaIDs) do
local name = C_Map.GetAreaInfo(areaID);
if name then
return name;
end
end
end
return nil;
end
From what I understand, it can return more than one location and the first location will be used for GetAreaInfo to show the area name for the mouse location on the worldmap
I don’t know what exactly you’re trying to do but the first returned area ID could be the closest to your current location. However GetExploredAreaIDsAtPosition doesn’t always seem to return information for every part of the zone. Otherwise you could do some math with map coords or check GetSubZoneText if all you want is the current subzone text
I think I can mix both solutions to get what I need for my addon. GetSubZoneText by itself wouldn’t solve because I need the area ID. I can try to compare it with C_Map.GetAreaInfo(areaID) and return the areaID.
Update: Guys, thanks a lot!
It worked perfectly!
I’ve just tweaked FindBestAreaNameAtMouse to return the areaID instead of the name.