Thread Tools Display Modes
04-06-20, 03:27 AM   #1
Lybrial
A Flamescale Wyrmkin
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 120
Russians in Battlegrounds?!

Hi,

im currently working on my nameplates and so I want to give some additional informations
on my nameplates when im in a battleground.

Im showing the class spec of enemies.

So at first im gathering class informations:

Lua Code:
  1. VALUES.Classes = {}
  2.  
  3. for classID = 1, MAX_CLASSES do
  4.     local _, class = GetClassInfo(classID);
  5.  
  6.     VALUES.Classes[class] = {}
  7.  
  8.     for i = 1, GetNumSpecializationsForClassID(classID) do
  9.         local specID, specName, _, iconID, role = GetSpecializationInfoForClassID(classID, i);
  10.  
  11.         VALUES.Classes[class][specName] = {
  12.             specID = specID,
  13.             role = role,
  14.             iconID = iconID,
  15.         }
  16.     end
  17. end

Second im building an array of current players in the battleground:

Lua Code:
  1. local players = {}
  2.  
  3. local function buildName(unit)
  4.     local name, realm = UNITS:UnitName(unit);
  5.  
  6.     -- UnitName realm: The realm the specified unit is from.
  7.     -- For "player" returns nil.
  8.     -- For any other character on your own realm returns an empty string.
  9.     -- This is as of 1.12.
  10.  
  11.     if (realm and (realm ~= "")) then
  12.         name = name .. "-" .. realm;
  13.     end
  14.  
  15.     return name;
  16. end
  17.  
  18. local function deleteSpecs()
  19.     TABLES:Wipe(players);
  20. end
  21.  
  22. local function updateSpecs()
  23.     local _, instanceType = GetInstanceInfo();
  24.  
  25.     if (instanceType == "pvp") then
  26.         for i = 1, GetNumBattlefieldScores() do
  27.             local name, _, _, _, _, _, _, _, class, _, _, _, _, _, _, specialization = GetBattlefieldScore(i);
  28.  
  29.             if (name and class and specialization) then
  30.                 players[name] = {
  31.                     class = class;
  32.                     specialization = specialization;
  33.                 }
  34.             end
  35.         end
  36.     elseif (instanceType == "arena") then
  37.         for i = 1, GetNumArenaOpponentSpecs() do
  38.             local name = buildName(STRINGS:Format("arena%d", i));
  39.  
  40.             if (name and (name ~= UNKNOWN)) then
  41.                 local specID = GetArenaOpponentSpec(i);
  42.                 local _, specialization, _, _, _, class = GetSpecializationInfoByID(specID);
  43.  
  44.                 if (class and specialization) then
  45.                     players[name] = {
  46.                         class = class;
  47.                         specialization = specialization;
  48.                     }
  49.                 end
  50.             end
  51.         end
  52.     end
  53. end
  54.  
  55. local frame = FRAMES:CreateFrame("Frame", nil, FRAMES.UIParent);
  56.  
  57. frame:SetScript("OnEvent", function(_, event)
  58.     if (event == "PLAYER_ENTERING_WORLD") then
  59.         deleteSpecs();
  60.         updateSpecs();
  61.     elseif ((event == "ARENA_OPPONENT_UPDATE") or (event == "UPDATE_BATTLEFIELD_SCORE")) then
  62.         updateSpecs();
  63.     end
  64. end);
  65. frame:RegisterEvent("UPDATE_BATTLEFIELD_SCORE");
  66. frame:RegisterEvent("ARENA_OPPONENT_UPDATE");
  67. frame:RegisterEvent("PLAYER_ENTERING_WORLD");

And on my nameplate update function im doing:

Lua Code:
  1. local function update(self)
  2.     local element = self.Specialization;
  3.  
  4.     if (element.PreUpdate) then
  5.         element:PreUpdate();
  6.     end
  7.  
  8.     local _, instanceType = GetInstanceInfo();
  9.  
  10.     if (instanceType == "pvp" or instanceType == "arena") then
  11.         local name = buildName(self.unit);
  12.  
  13.         if (players[name]) then
  14.             local class = players[name].class;
  15.             local specialization = players[name].specialization;
  16.  
  17.             element.Icon:SetTexture(VALUES.Classes[class][specialization].iconID);
  18.             element.Icon:SetTexCoord(0.1, 0.9, 0.1, 0.9);
  19.  
  20.             element:Show();
  21.         else
  22.             element:Hide();
  23.         end
  24.     end
  25.  
  26.     if (element.PostUpdate) then
  27.         return element:PostUpdate(self.unit);
  28.     end
  29. end

This works perfectly! For everybody except russian players. There are some rogue and demon hunter specs for which I get no results for. Is there anything special about some russian names, server names or spec names (except from the character set ofcourse)?

Last edited by Lybrial : 04-06-20 at 03:48 AM.
  Reply With Quote
04-06-20, 09:29 AM   #2
Lybrial
A Flamescale Wyrmkin
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 120
Actually I was mistaken. That only rogues or demon hunters are having this problem
and it was also wrong that it is only related to russians.
It was just coincidence that this happened 3 times in a row for me

The thing is, the event:

Lua Code:
  1. UPDATE_BATTLEFIELD_SCORE

Does not fire often enough. I see people joining the battleground without this event getting fired.

Do you guys know of a better event for my case?

Last edited by Lybrial : 04-06-20 at 10:31 AM.
  Reply With Quote
04-06-20, 11:40 AM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Can't someone join the battleground without the score changing?

You could use /eventtrace
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
04-06-20, 12:00 PM   #4
Lybrial
A Flamescale Wyrmkin
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 120
I would think that it is not possible. Scoreboard changes when someone joins, in my opinion this should trigger the mentioned event.

Maybe I should do something with that: https://wow.gamepedia.com/API_Reques...fieldScoreData

Lua Code:
  1. RequestBattlefieldScoreData()

Should request new score data from the server and trigger the event.
But I really dont like to call this function from a timer.

Maybe someone knows how to deal with that a better way? All the other addons I have found so far which are doing something similar to what im doing are using the UPDATE_BATTLEFIELD_SCORE event too.

But I think this is already the solution. To periodically call RequestBattlefieldScoreData()
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Russians in Battlegrounds?!

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off