08-21-18, 07:55 AM | #1 |
Class icons on nameplates
Hi guys, first timer here!
Did some search on these forums and discovered a lot of useful information, you are really helpful bunch of people! Trying to figure out the nameplate magics. For practice I'm attempting to show class icons over the friendly nameplates. After the initial loading things work well, but after I move my camera and nameplates get dynamically reassigned, icons tend to appear over wrong classes. To narrow things down I've tried to restrict the icons to WARRIOR class only. And it obviously didn't work as planned https://imgur.com/G3UPLIx Lua Code:
I feel that the removeIcon function is faulty as I don't know how to get to the frame I've created on top of the nameplate. Maybe I have to gather all the frames I create in a table? Or perhaps all the stuff I do is just plain wrong and there is a simpler way to accomplish this task that I don't see as a beginner. Thank you very much for taking your time to read this and for any hints and advice! Last edited by Mitur : 08-22-18 at 03:10 AM. |
|
08-21-18, 09:38 AM | #2 |
I see a few things that I think are wrong but I'm not sure since you reference things not in the posted code. Post ALL of your code.
|
|
08-21-18, 09:59 AM | #3 |
You're running :Hide() on the nameplate itself, why?
The nameplate already disappears when unit is removed, that part is redundant, and you're not actually hiding the iconframe. Meaning, once the nameplate gets reassigned to a different unit, it is still anchored to it and will still appear, even if the character is of the wrong class. [I wrote a thing here that I realized would not work, edited out] Also, not related to the functionality of your code, but you are creating a new frame every time a nameplate appears. You should only create one per nameplate. Efficiency reasons. Last edited by Ammako : 08-21-18 at 10:05 AM. |
|
08-21-18, 10:30 AM | #4 | ||
And you're right about the efficiency part for sure. I should somehow check if the nameplate already contains my Frame. If only I knew how to manage the nameplates properly |
|||
08-21-18, 10:47 AM | #5 | |
Code:
if event == events["npu_added"] and not idSet:contains(unit) then Code:
elseif event == events["npu_removed"] and idSet:contains(id) then idSet:remove(id) In short post ALL of your code if you want help. |
||
08-21-18, 11:15 AM | #6 | ||
You could declare iconFrame inside nameplateHandler, and pass it as an argument to addIcon and removeIcon. Ideally, you'd probably do this differently as a whole, but see if that works to begin with. The way nameplates work, there is a finite amount of nameplates, and they are recycled as units appear and disappear. Nameplates aren't unique to the unit.If NamePlate1 gets assigned to a Warrior player character, and that character either dies or moves out of sight, NamePlate1 will get re-assigned to a different unit later on. If you modify that nameplate, the modifications will still be in place when it reappears later with a different unit assigned to it. So that has to be kept in mind. Also, I could be wrong about the multiple frames per nameplate thing, but from my understanding, iconFrame being local to addIcon function, a new instance of it is created every time the function gets called, and references to it are lost once the function exits. Anyone feel free to let me know if that's wrong |
|||
08-22-18, 02:42 AM | #7 |
Thank you guys for pointing out my mistakes, I appreciate it very much!
I've updated my original post with the full code. @Vrul - sorry for the "id" variable, it got mixed up when I decided to rename the argument to "unit" for better readability and missed some occurrences. |
|
08-22-18, 07:17 AM | #8 |
Code:
local addonName = ... 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('TOPLEFT', 10, 10) icon:SetSize(32, 32) 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") |
|
08-22-18, 07:30 AM | #9 |
WoWInterface » Developer Discussions » General Authoring Discussion » Class icons on nameplates |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|