Quantcast
WoWInterface - View Single Post - Arena ClassSpec-Icons appear/mirror friendly/neutral nameplates
View Single Post
02-27-21, 06:31 PM   #1
rulezyx
A Wyrmkin Dreamwalker
 
rulezyx's Avatar
Join Date: Jan 2020
Posts: 59
Arena ClassSpec-Icons appear/mirror friendly/neutral nameplates

Hello,

I use alot of scripts for pvp and one of the codes is giving me trouble since Shadowlands.


Code:
local U = UnitIsUnit;
local GetNamePlate = C_NamePlate.GetNamePlateForUnit;
local frame = CreateFrame("frame");
local data = {};

function NamePlate_Added(...)
   local nameplateId = ...;
   local nameplate = GetNamePlate(nameplateId).UnitFrame;

   for i=1,5 do
      if UnitIsUnit(nameplateId, "arena"..i) then
         addIcon(data[i], nameplate);
      end
   end
end

function NamePlate_Removed(...)
   local nameplateId = ...;
   local nameplate = GetNamePlate(nameplateId).UnitFrame;

   if (nameplate.iconClass) then
      nameplate.iconClass:Hide();
   end
end

function SetupIcons()
   for i = 1, GetNumArenaOpponentSpecs() do
      local specID = GetArenaOpponentSpec(i)
      if specID > 0 then
         local id, name, description, icon, role, class = GetSpecializationInfoByID(specID);
         data[i] = icon;
      end
   end
end

function addIcon (icon, frame)
   local button = CreateFrame("Button", "ClassIcon", frame);
   local txt = button:CreateTexture();

   txt:SetTexture(icon);
   txt:SetAllPoints();
   
   button:SetNormalTexture(txt);
   button:SetWidth(20);
   button:SetHeight(20);
   button:SetPoint("RIGHT", 10, -5);

   frame.iconClass = button;
end

frame:RegisterEvent('NAME_PLATE_UNIT_ADDED');
frame:RegisterEvent('NAME_PLATE_UNIT_REMOVED');
frame:RegisterEvent('ARENA_PREP_OPPONENT_SPECIALIZATIONS');
frame:SetScript('OnEvent', function (self, event, ...)
      if (event == "ARENA_PREP_OPPONENT_SPECIALIZATIONS") then
         SetupIcons();
      elseif (event == 'NAME_PLATE_UNIT_ADDED') then
         NamePlate_Added(...)
      elseif (event == 'NAME_PLATE_UNIT_REMOVED') then
         NamePlate_Removed(...);
      end
end)
The code works but sometimes icons will randomly appear on other non related units even outside of arena.

Also I get lua.errors which I couldnt fix myself but I dont think it is related to this problem itself:

Code:
Message: Interface\AddOns\RulezPvPScripts\core.lua:21: attempt to index local 'nameplate' (a nil value)
Time: Sun Feb 28 00:59:43 2021
Count: 2
Stack: Interface\AddOns\RulezPvPScripts\core.lua:21: attempt to index local 'nameplate' (a nil value)
[string "@Interface\AddOns\RulezPvPScripts\core.lua"]:21: in function `NamePlate_Removed'
[string "@Interface\AddOns\RulezPvPScripts\core.lua"]:60: in function <Interface\AddOns\RulezPvPScripts\core.lua:54>

Locals: nameplateId = "nameplate1"
nameplate = nil
(*temporary) = "nameplate1"
(*temporary) = NamePlate1 {
 OnSizeChanged = <function> defined @Interface\AddOns\Blizzard_NamePlates\Blizzard_NamePlates.lua:485
 GetPreferredInsets = <function> defined @Interface\AddOns\Blizzard_NamePlates\Blizzard_NamePlates.lua:466
 GetAdditionalInsetPadding = <function> defined @Interface\AddOns\Blizzard_NamePlates\Blizzard_NamePlates.lua:455
 NCIconsCount = 0
 ApplyOffsets = <function> defined =[C]:-1
 NCIcons = <table> {
 }
 OnRemoved = <function> defined @Interface\AddOns\Blizzard_NamePlates\Blizzard_NamePlates.lua:424
 OnAdded = <function> defined @Interface\AddOns\Blizzard_NamePlates\Blizzard_NamePlates.lua:413
 template = "NamePlateUnitFrameTemplate"
 0 = <userdata>
 OnOptionsUpdated = <function> defined @Interface\AddOns\Blizzard_NamePlates\Blizzard_NamePlates.lua:431
}
(*temporary) = "attempt to index local 'nameplate' (a nil value)"
GetNamePlate = <function> defined =[C]:-1
Since I use the code for enemy nameplates only' it is pretty annoying when wrong spec-icons from enemy players appear on friendly nameplates.

It is not my own code so it would be really kind if someone is able to fix it up.

For friendly nameplates I use a different code because I need different positioning and Iconsize (smaller nameplates):

Code:
local frame = CreateFrame("Frame")
 
frame:SetScript("OnEvent", function(self, event, unit)
    local namePlate = GetNamePlateForUnit(unit)
    if event == "NAME_PLATE_UNIT_ADDED" and UnitIsFriend("player", unit) then
        local _, class = UnitClass(unit)
        if iconTexture[class] then
            local icon = namePlate[iconKey]
            if not icon then
                icon = namePlate:CreateTexture(nil, "OVERLAY")
                icon:SetPoint('CENTER', 0, 29.46)
                icon:SetSize(24, 24)
                namePlate[iconKey] = icon
            end
            icon:SetTexture(iconTexture[class])
            icon:Show()
            return
        end
    end
    if namePlate[iconKey] then
        namePlate[iconKey]:Hide()
    end
end)

frame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
frame:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function()
	
	nameplateSize()

end)

function nameplateSize()
Is it possible to fix the first code with enemy_units (lua errors/wrong display)

and to rewrite the second code with friendly_units but to show spec-icons instead of class-icons (see example) in arenas?

Basically friendly and enemy nameplate class-icons outside of arena/pvp (or when :GetSpec isnt working) and turn to friendly/enemy specialization-icons inside arena/pvp (if possible).

I know its a mess and alot of work but I usually just put all the stuff mixed together in one addon and I dont have alot of expierence with lua.

It would be really helpful and maybe its possible to create a small addon with both functions/codes (friendly, enemy) with the possibility to seperate edit friendly icons from enemy icons in sizes/positioning (no ingame config just simple lua-code).

I would also like to share the result to the community if someone get this to work.

Thank you for reading.

Attachments: Issues (wrong/discplacement_example), Friendly_Nameplates (default_ like usually), Enemy_Nameplates (default_ like usually)
The icon on the top of the first image is from BigDebuffs which is bugged too but addon related (already reportet).
Attached Thumbnails
Click image for larger version

Name:	ISSUES.PNG
Views:	27
Size:	102.2 KB
ID:	9592  Click image for larger version

Name:	Enemy_Nameplate_example.PNG
Views:	24
Size:	33.3 KB
ID:	9594  
Attached Images
 

Last edited by rulezyx : 03-01-21 at 06:49 AM.
  Reply With Quote