WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   friendly nameplate remove healthbar (https://www.wowinterface.com/forums/showthread.php?t=57945)

Igorcovran 04-16-20 02:47 PM

friendly nameplate remove healthbar
 
Hello.
I found something i need on tihos forums <3

so its class icon for friendly players
Code:

local iconKey = addonName .. "Icon"

local GetNamePlateForUnit = C_NamePlate.GetNamePlateForUnit

local iconTexture = {
    ["DEATHKNIGHT"] = 135771,
    ["DEMONHUNTER"] = 236415,
    ["DRUID"] = 625999,
    ["HUNTER"] = 626000,
    ["MAGE"] = 626001,
    ["MONK"] = 626002,
    ["PALADIN"] = 626003,
    ["PRIEST"] = 626004,
    ["ROGUE"] = 626005,
    ["SHAMAN"] = 626006,
    ["WARLOCK"] = 626007,
    ["WARRIOR"] = 626008
}

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, 22)
                icon:SetSize(22, 22)
                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")

now the only problem is i want the name and healthbar gone from frindly nameplates ramianing just the class icon

https://ibb.co/KhLZ5SZ

Igorcovran 04-17-20 10:24 AM

it cant be done?

sezz 04-23-20 07:05 AM

Quote:

Originally Posted by Igorcovran (Post 335686)
it cant be done?

friendly nameplates are protected in instances/pvp

Igorcovran 04-23-20 10:28 AM

thanks for replay

Xruptor 04-24-20 05:36 AM

Quote:

Originally Posted by sezz (Post 335747)
friendly nameplates are protected in instances/pvp

Sezz pretty much hit it on the nail. You can't modify nameplates in instances or pvp, if you try to do so you will trigger taint errors and such. Blizzard did this to prevent nameplates from being used to calculate positioning and what not and other things they didn't want folks doing.

Outside of that scope you can modify them as you like. A question though? Why not just use the colored healthbars to know the class? It shouldn't be necessary to place a class icon. Even if you are color blind there are settings that can adjust that.

Otherwise you if you want to use that code you need to add measures to prevent errors.


Code:

local iconKey = addonName .. "Icon"

local GetNamePlateForUnit = C_NamePlate.GetNamePlateForUnit

local iconTexture = {
    ["DEATHKNIGHT"] = 135771,
    ["DEMONHUNTER"] = 236415,
    ["DRUID"] = 625999,
    ["HUNTER"] = 626000,
    ["MAGE"] = 626001,
    ["MONK"] = 626002,
    ["PALADIN"] = 626003,
    ["PRIEST"] = 626004,
    ["ROGUE"] = 626005,
    ["SHAMAN"] = 626006,
    ["WARLOCK"] = 626007,
    ["WARRIOR"] = 626008
}

local frame = CreateFrame("Frame")
 
frame:SetScript("OnEvent", function(self, event, unit)
        local inInstance, instanceType = IsInInstance()
       
        --make sure we aren't in an instance
        if not inInstance then
                --next check to see if you can even TOUCH the namePlate, using CanAccessObject
                local namePlate = GetNamePlateForUnit(unit)
                if namePlate and CanAccessObject(namePlate) then
       
                        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, 22)
                                                icon:SetSize(22, 22)
                                                namePlate[iconKey] = icon
                                        end
                                        icon:SetTexture(iconTexture[class])
                                        icon:Show()
                                        return
                                end
                        end
                        if namePlate[iconKey] then
                                namePlate[iconKey]:Hide()
                        end
               
                end
        end
end)

frame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
frame:RegisterEvent("NAME_PLATE_UNIT_REMOVED")


Igorcovran 04-30-20 11:54 AM

rather have icons for friends and color hp bars for enemy just like thrille streemer


All times are GMT -6. The time now is 03:46 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI