WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Current WorldMap Zone Text (https://www.wowinterface.com/forums/showthread.php?t=50083)

Resike 10-15-14 02:41 PM

Current WorldMap Zone Text
 
How can i get the current continent/zone text which is currently shown by the map?

Choonstertwo 10-15-14 03:15 PM

Have you looked at WorldMapFrame.xml?

WorldMapZoneInfo might be the FontString you want.

Fizzlemizz 10-15-14 03:22 PM

GetMinimapZoneText() will get the current zone text.

If you want to update it while moving, use events:

PLAYER_ENTERING_WORLD
ZONE_CHANGED
ZONE_CHANGED_INDOORS
ZONE_CHANGED_NEW_AREA

Edit: You can also use GetZonePVPInfo() to get the zone type, sanctuary, contested, friendly, hostile, arena.

semlar 10-15-14 03:36 PM

Lua Code:
  1. local function GetMapName()
  2.     local mapName, _, _, isMicroDungeon, microDungeonMapName = GetMapInfo()
  3.     local name = WORLD_MAP
  4.     if GetCurrentMapZone() > 0 then
  5.         name = GetMapNameByID(GetCurrentMapAreaID())
  6.         local floorNum = DungeonUsesTerrainMap() and GetCurrentMapDungeonLevel() - 1 or GetCurrentMapDungeonLevel()
  7.         if floorNum > 0 then
  8.             name = name .. ': ' .. _G["DUNGEON_FLOOR_" .. strupper(mapName or '') .. floorNum]
  9.         end
  10.     else
  11.         local currentContinent = GetCurrentMapContinent()
  12.         if currentContinent ~= WORLDMAP_WORLD_ID and currentContinent ~= WORLDMAP_COSMIC_ID then
  13.             name = select(currentContinent, GetMapContinents())
  14.         end
  15.     end
  16.     return name or (isMicroDungeon and microDungeonMapName or mapName)
  17. end

Resike 10-15-14 03:39 PM

Quote:

Originally Posted by Fizzlemizz (Post 297909)
GetMinimapZoneText() will get the current zone text.

If you want to update it while moving, use events:

PLAYER_ENTERING_WORLD
ZONE_CHANGED
ZONE_CHANGED_INDOORS
ZONE_CHANGED_NEW_AREA

Edit: You can also use GetZonePVPInfo() to get the zone type, sanctuary, contested, friendly, hostile, arena.

That returns the player's zone, i need the zone which is shown on the map, not the minimap.

Resike 10-15-14 03:44 PM

Quote:

Originally Posted by semlar (Post 297914)
Lua Code:
  1. local function GetMapName()
  2.     local mapName, _, _, isMicroDungeon, microDungeonMapName = GetMapInfo()
  3.     local name = WORLD_MAP
  4.     if GetCurrentMapZone() > 0 then
  5.         name = GetMapNameByID(GetCurrentMapAreaID())
  6.         local floorNum = DungeonUsesTerrainMap() and GetCurrentMapDungeonLevel() - 1 or GetCurrentMapDungeonLevel()
  7.         if floorNum > 0 then
  8.             name = name .. ': ' .. _G["DUNGEON_FLOOR_" .. strupper(mapName or '') .. floorNum]
  9.         end
  10.     else
  11.         local currentContinent = GetCurrentMapContinent()
  12.         if currentContinent ~= WORLDMAP_WORLD_ID and currentContinent ~= WORLDMAP_COSMIC_ID then
  13.             name = select(currentContinent, GetMapContinents())
  14.         end
  15.     end
  16.     return name or (isMicroDungeon and microDungeonMapName or mapName)
  17. end

Sexy that what i need, thanks.
Shame Blizzard doesn't have a global function something like this.

semlar 10-15-14 03:51 PM

I pulled that out of my map function that just sort of returns everything about the current map, "name" can't not exist at the end of the function unless you remove "= WORLD_MAP" from the top of it, so the last part isn't really necessary.

It depends on what you want it to default to if the current map has no name from the other methods.

It also concats the floor name from multi-level maps to the parent map name, so if you want to change that behavior you'll have to edit the floorNum > 0 part.

Resike 10-15-14 03:56 PM

Quote:

Originally Posted by semlar (Post 297917)
I pulled that out of my map function that just sort of returns everything about the current map, "name" can't not exist at the end of the function unless you remove "= WORLD_MAP" from the top of it, so the last part isn't really necessary.

It depends on what you want it to default to if the current map has no name from the other methods.

It also concats the floor name from multi-level maps to the parent map name, so if you want to change that behavior you'll have to edit the floorNum > 0 part.

I actually use this for note handling.

Resike 12-05-14 08:54 AM

I have some issues specially with the new Zone Names.

Since "Nagrand" and "Shadowmoon Valley" are also exists on Outland, the function save values from both zone into the same table.

Any way to properly differentiate these zones? Or i'm gonna need to slap the zone id into the string?

Phanx 12-05-14 09:18 AM

Names are a really bad way to identify zones. You should be storing map IDs, not names. If you need to display something to the user, you can use GetMapNameByID to get the correct name when needed.

Resike 12-05-14 03:37 PM

Quote:

Originally Posted by Phanx (Post 301811)
Names are a really bad way to identify zones. You should be storing map IDs, not names. If you need to display something to the user, you can use GetMapNameByID to get the correct name when needed.

I know, but the saved variables force me to do it, and i don't have time to write a proper conversion tool atm.

SDPhantom 12-05-14 06:05 PM

Quote:

Originally Posted by Resike (Post 301833)
I know, but the saved variables force me to do it...

How so? If you don't know how to wipe saved data, here's a couple commands you can use.

Code:

/run MySavedVar=nil
/reload

Setting your saved variable to nil effectively wipes it out and lets the addon reinitialize to its defaults. This requires a UI reload in order to apply.

Phanx 12-05-14 09:58 PM

Quote:

Originally Posted by Resike (Post 301833)
I know, but the saved variables force me to do it, and i don't have time to write a proper conversion tool atm.

For a one-time conversion of key names in a saved variables table, you really don't need a "proper conversion tool"... just do it quick and dirty, and don't worry about efficiency, because it doesn't matter in this context:

Code:

local function FindMapID(name)
    for i = 1, 1200 do
          if GetZoneNameByID(i) == name then
              return i
          end
    end
end

for k, v in pairs(db) do
    if type(k) == "string" then
        local id = FindMapID(k)
        if id then
              db[id] = v
              db[k] = nil
        else
              print("ERROR: no mapID found for zone name:", k)
        end
    end
end


Resike 12-07-14 07:47 AM

Quote:

Originally Posted by Phanx (Post 301850)
For a one-time conversion of key names in a saved variables table, you really don't need a "proper conversion tool"... just do it quick and dirty, and don't worry about efficiency, because it doesn't matter in this context:

Code:

local function FindMapID(name)
    for i = 1, 1200 do
          if GetZoneNameByID(i) == name then
              return i
          end
    end
end

for k, v in pairs(db) do
    if type(k) == "string" then
        local id = FindMapID(k)
        if id then
              db[id] = v
              db[k] = nil
        else
              print("ERROR: no mapID found for zone name:", k)
        end
    end
end


To be honest after i started thinking about it how could i do it, i ended up with a very similar method.
My question is that is that 1200 max value for the loop is gonna be enough?

Rilgamon 12-07-14 09:13 AM

http://wowpedia.org/MapID

Phanx 12-07-14 08:28 PM

Yes, I specifically picked 1200 by looking at the list of mapIDs and determining that none are above 1200. Since this is a one-time process, and not something that needs to be future-proof, the fact that future content patches and expansions might add maps with IDs higher than 1200 isn't relevant.

semlar 12-08-14 08:39 AM

You could also just use GetAreaMaps() for a list of map ids, if you're into that sort of thing.

Resike 12-11-14 11:37 AM

Quote:

Originally Posted by semlar (Post 302037)
You could also just use GetAreaMaps() for a list of map ids, if you're into that sort of thing.

Nice, how did i missed that function?

myrroddin 12-11-14 02:42 PM

Quote:

Originally Posted by Resike (Post 302278)
Nice, how did i missed that function?

I believe it is new to 6.x. There is also GetAreaMapInfo() but so far neither has been documented.

semlar 12-11-14 05:22 PM

Quote:

Originally Posted by myrroddin (Post 302287)
I believe it is new to 6.x. There is also GetAreaMapInfo() but so far neither has been documented.

It was in the MoP beta, people are just too lazy to document things.


All times are GMT -6. The time now is 04:56 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI