View Single Post
04-13-10, 09:26 AM   #190
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
Originally Posted by Dudeface View Post
Greetings everyone,

I'm interested in creating a small panel parented to my oUF target frame that shows how many people are targeting my target. I'm not sure on the API function for showing how many people are targeting my own target. I've had a look through wowwiki but haven't come up with anything yet.

Cheers.
Didn't see this till now, but I'll answer anyway since it would be a cool script to make. I also cannot test this in-game, so if someone could verify, that would be great.

Code:
{   parent = UIParent, anchor_to = "TOP",
    x_off = 0, y_off = -10, height = 100, width = 200,
    border = true, text = "",
    
    OnLoad = function(self)
        self:RegisterEvent("UNIT_TARGET")
    end,

    OnEvent = function(self)
        local unitsWithSameTarget, colors, colorTag = ""
        for i=1, MAX_PARTY_MEMBERS do
            if GetNumRaidMembers() > 0 then
                unitId = "raid"..i
            else
                unitId = "party"..i
            end

            -- Check if unit has same target as you.
            if UnitExists(unitId) and UnitGUID(unitId.."target") == UnitGUID("target") then
                -- Check if the unit is not dead and not yourself.
                if not UnitIsDead(unitId) and UnitGUID(unitId) ~= UnitGUID("player") then
                    -- Class coloring.
                    _, unitClass = UnitClass(unitId)
                    colors = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[unitClass]
                    colorTag = format("|cff%02x%02x%02x", colors.r*255, colors.g*255, colors.b*255)
        
                    -- Append class name to unitsWithSameTarget.
                    unitsWithSameTarget = (unitsWithSameTarget == "") and "" or unitsWithSameTarget..", "
                    unitsWithSameTarget = format("%s%s%s|r", unitsWithSameTarget, colorTag, UnitName(unitId))
                end
            end
        end

        if unitsWithSameTarget ~= "" then
            self.text:SetText(unitsWithSameTarget)
            self:SetAlpha(1)
        else
            self.text:SetText("")
            self:SetAlpha(0)
        end
    end
}

Last edited by Katae : 04-13-10 at 09:35 AM.
  Reply With Quote