1. #1

    BG/Arena - change target portrait into specialization icon

    Inspired by the great AJ sticky that puts class icons as portraits...

    Code:
    hooksecurefunc("UnitFramePortrait_Update",function(self)
            if self.portrait then
                    if UnitIsPlayer(self.unit) then                         
                            local t = CLASS_ICON_TCOORDS[select(2, UnitClass(self.unit))]
                            if t then
                                    self.portrait:SetTexture("Interface\\TargetingFrame\\UI-Classes-Circles")
                                    self.portrait:SetTexCoord(unpack(t))
                            end
                    else
                            self.portrait:SetTexCoord(0,1,0,1)
                    end
            end
    end)

    ... I'd like to do the same thing but for specs. I'm not the first person to ask this but I haven't found any answers.

    I know the spec info is available to the UI, at least in BGs, from the BG targets addon. I have figured out a WA to do this...

    Code:
    function ()
        id = GetInspectSpecialization("target")
         _,name,_,_,_,_ = GetSpecializationInfoByID(id)
         if not name then name = "-" end
         return name
     end
    ... but there's a delay in changing targets before it snags the info. It would be great if there's a way to get this info locked down once the BG starts. Anyone have any thoughts or suggestions?

    - - - Updated - - -

    One idea would be to make a code snippet that can be pasted into BG Targets addon to piggyback on the spec data it's already collecting (and which is locked down once the BG begins).
    http://www.curse.com/addons/wow/battlegroundtargets
    That addon seems to store the spec info in the ENEMY_Data variable.

    This code suggested by this post http://www.arenajunkies.com/topic/24...traits-script/
    Code:
    function Addon:PLAYER_TARGET_CHANGED()
      if not UnitExists("target") then return end -- We have no target
    
      local TargetArenaID
      for i = 1, 5 do -- Getting the ArenaID of the target
    	if UnitIsUnit("target", "arena"..i) then
    	  TargetArenaID = i
    	  break
    	end
      end
      if not TargetArenaID then return end -- Target is not a enemy player
    
      local IconPath = select(4, GetSpecializationInfoByID(GetArenaOpponentSpec(TargetArenaID)))
      SetPortraitToTexture(TargetFrame.portrait, IconPath)
    end

    It seems like it would be pretty simple to check if my target is one of the entities in ENEMY_Data, and if so then to set the portrait using the SetPortraitToTexture as shown. I'm just not exactly sure how to pull all of this together as a standalone snippet that could be pasted into BGtargets. Any help would be greatly appreciated.
    Last edited by Malvesti; 2014-07-29 at 07:49 PM.

  2. #2
    I copied the arena part and added handling for battlegrounds. I tested it in an unrated battleground and it seems to work fine (arena and RBG are untested). You'll just have to make the code into an addon for yourself.

    This replaces the icon of your targets portrait with the specialization icon of your target, when in arena or battleground:

    Code:
    local SpecTextures = {};
    
    for i = 1, GetNumClasses() do
    	local _, classTag, classID = GetClassInfo(i);
    
    	SpecTextures[classTag] = {};
    
    	for specID = 1, GetNumSpecializationsForClassID(classID) do
    		local _, specName, _, specIcon = GetSpecializationInfoForClassID(classID,specID);
    
    		SpecTextures[classTag][specName] = specIcon;
    	end;
    end;
    
    local TargetFrameSpec = CreateFrame("Frame");
    TargetFrameSpec:RegisterEvent("PLAYER_TARGET_CHANGED");
    TargetFrameSpec:SetScript("OnEvent",function()
    	if not UnitExists("target") then
    		return;
    	end;
    
    	local _, instanceType = IsInInstance();
    
    	if instanceType == "arena" then
    		for i = 1, 5 do
    			if UnitIsUnit("target","arena"..i) then
    				local icon = (select(4,GetSpecializationInfoByID(GetArenaOpponentSpec(i))));
    				if icon then
    					SetPortraitToTexture(TargetFrame.portrait,icon);
    					return;
    				end;
    			end;
    		end;
    	elseif instanceType == "pvp" then
    		for scoreIndex = 1, GetNumBattlefieldScores() do
    			local name, _, _, _, _, _, _, _, classTag, _, _, _, _, _, _, specName = GetBattlefieldScore(scoreIndex);
    			if GetUnitName("target",true) == name then
    				local icon = SpecTextures[classTag][specName];
    				
    				if icon then
    					SetPortraitToTexture(TargetFrame.portrait,icon);
    					return;
    				end;
    			end;
    		end;
    	end;
    end);

  3. #3
    Seems to work perfectly. Thanks so much!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •