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:
VALUES.Classes = {}
for classID = 1, MAX_CLASSES do
local _, class = GetClassInfo(classID);
VALUES.Classes[class] = {}
for i = 1, GetNumSpecializationsForClassID(classID) do
local specID, specName, _, iconID, role = GetSpecializationInfoForClassID(classID, i);
VALUES.Classes[class][specName] = {
specID = specID,
role = role,
iconID = iconID,
}
end
end
Second im building an array of current players in the battleground:
Lua Code:
local players = {}
local function buildName(unit)
local name, realm = UNITS:UnitName(unit);
-- UnitName realm: The realm the specified unit is from.
-- For "player" returns nil.
-- For any other character on your own realm returns an empty string.
-- This is as of 1.12.
if (realm and (realm ~= "")) then
name = name .. "-" .. realm;
end
return name;
end
local function deleteSpecs()
TABLES:Wipe(players);
end
local function updateSpecs()
local _, instanceType = GetInstanceInfo();
if (instanceType == "pvp") then
for i = 1, GetNumBattlefieldScores() do
local name, _, _, _, _, _, _, _, class, _, _, _, _, _, _, specialization = GetBattlefieldScore(i);
if (name and class and specialization) then
players[name] = {
class = class;
specialization = specialization;
}
end
end
elseif (instanceType == "arena") then
for i = 1, GetNumArenaOpponentSpecs() do
local name = buildName(STRINGS:Format("arena%d", i));
if (name and (name ~= UNKNOWN)) then
local specID = GetArenaOpponentSpec(i);
local _, specialization, _, _, _, class = GetSpecializationInfoByID(specID);
if (class and specialization) then
players[name] = {
class = class;
specialization = specialization;
}
end
end
end
end
end
local frame = FRAMES:CreateFrame("Frame", nil, FRAMES.UIParent);
frame:SetScript("OnEvent", function(_, event)
if (event == "PLAYER_ENTERING_WORLD") then
deleteSpecs();
updateSpecs();
elseif ((event == "ARENA_OPPONENT_UPDATE") or (event == "UPDATE_BATTLEFIELD_SCORE")) then
updateSpecs();
end
end);
frame:RegisterEvent("UPDATE_BATTLEFIELD_SCORE");
frame:RegisterEvent("ARENA_OPPONENT_UPDATE");
frame:RegisterEvent("PLAYER_ENTERING_WORLD");
And on my nameplate update function im doing:
Lua Code:
local function update(self)
local element = self.Specialization;
if (element.PreUpdate) then
element:PreUpdate();
end
local _, instanceType = GetInstanceInfo();
if (instanceType == "pvp" or instanceType == "arena") then
local name = buildName(self.unit);
if (players[name]) then
local class = players[name].class;
local specialization = players[name].specialization;
element.Icon:SetTexture(VALUES.Classes[class][specialization].iconID);
element.Icon:SetTexCoord(0.1, 0.9, 0.1, 0.9);
element:Show();
else
element:Hide();
end
end
if (element.PostUpdate) then
return element:PostUpdate(self.unit);
end
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)?