08-09-16, 08:41 AM | #1 |
Nameplate Unit Classification
So I'm trying to add Unit Classifications to my nameplates. This is just a very very alpha version, simply to test the functionality of detecting the UnitClassification.
In the function that creates the frame for frame.healthBar, I have a few additional lines of code to create artwork on the sides and around the border of the nameplates, aswell as change the statusbar texture of them. All of this functions fine, however, when I add a function to determine the UnitClassification, it always returns "normal" no matter what. Here is the code I am using: Lua Code:
Since I am not using UnitClassification(unit) I can be sure it's not trying to use myself as the 'unit' in question (though that would be unlikely anyways) Also, I have fallbacks incase UnitClassification(u) returns a nil/error or just doesn't give any return. I can be certain, from the way the if function is fired, that UnitClassification(u) IS returning the value "normal", and since the variable u is set to namePlateUnitToken, I fail to see why this function does not behave properly. My issue is, it ALWAYS returns 'normal', whether the unit is normal, boss, elite or rare. The function this code is inside is hooked into the "DefaultCompactNamePlateFrameSetupInternal" function, so it is fired anytime a nameplate is created, removed or changed. Code:
hooksecurefunc("DefaultCompactNamePlateFrameSetupInternal", SetupNamePlate) |
|
08-09-16, 09:19 AM | #2 |
Where is "namePlateUnitToken" coming from? The DefaultCompactNamePlateFrameSetupInternal function doesn't receive any such value, so neither will anything you secure-hook it with.
However, the whole point (well, one of the points) of the nameplate changes in 7.0 is that you don't need to hook default UI functions to modify nameplates. There are events that fire specifically to inform you about this stuff. Use them. The NAME_PLATE_UNIT_ADDED and NAME_PLATE_UNIT_REMOVED events do include a unit token, and the default UI code does name it "namePlateUnitToken", so maybe you're already using events, but since you didn't actually show your code, I can only make assumptions based on the snippet you provided. Nobody here is psychic. We can't read your mind through the ether, or see your screen in a scrying bowl, or telepathically commune with your hard drive. Please just show your code -- all of your code -- when you ask for help with code.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
08-09-16, 10:12 AM | #3 | |
Lua Code:
The hooksecurefunc stuff was done by zork, he updated the addon so that it would have access to the new nameplates, but handed it over to me to do all of the visual work on it, such as re-skinning, adding borders, changing text, etc. I assumed since that was the func that he used to grab the creation of the nameplates, that it included the namePlateUnitToken variable in it. I will do my best to re-write this using events instead of hooks when servers come back up. :s |
||
08-09-16, 02:11 PM | #4 |
Well, the problem remains:
Code:
98. local u = namePlateUnitToken If you can add a "print(namePlateUnitToken)" there and get anything other than "nil", then something is leaking a variable with that name into the global namespace. Make sure it's not your addon doing the leaking. Beyond that, you're making the same mistake here that you're making in our other thread about the oUF layout. You're executing code one time when a frame is created, and expecting it to magically run again and update stuff based on things that change later. That's not how it works. In this case, you probably need to run that classification-related code in response to the NAME_PLATE_UNIT_ADDED event. Code:
local f = CreateFrame("Frame") f:RegisterEvent("NAME_PLATE_UNIT_ADDED") f:SetScript("OnEvent", function(f, event, ...) if event == "NAME_PLATE_UNIT_ADDED" then local unit = ... local nameplate = C_NamePlate.GetNamePlateForUnit(unit) if not nameplate then return end -- Do stuff here that needs to happen every -- time a nameplate's unit changes. end end)
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
08-09-16, 04:30 PM | #5 |
You could also hook CompactUnitFrame_UpdateClassificationIndicator and set showClassificationIndicator to false on nameplates to hide the default icon.
DefaultCompactNamePlateFrameSetupInternal is executed on NAME_PLATE_UNIT_ADDED. |
|
08-09-16, 05:48 PM | #6 |
Yea, the code does fire everytime a nameplate is added, so I got that bar right. I don't know where I'm getting a variable leak from but I will double check my other embeds.
Thanks for that hook sazz, THAT I know how to do. XD |
|
08-09-16, 07:35 PM | #7 | |
I'm learning much from you thanks. I found out why my function was always returning 'normal', apparently UnitClassification(unit) always returns 'normal' on bosses now? So you have to check for UnitLevel(unit) == -1 instead. I was failing to properly test the detection against elites and rares aswell, woops. So my way of doing it actually did work. But keeping it seperate in it's own function is loads better. |
||
08-09-16, 08:53 PM | #8 |
Sooo.. I tried to change name text and failed epically! Woo!
Lua Code:
I would LIKE it to simply replace the name on the nameplate with the units name plus their level in () (for now, at least) It does this, but whenever a new frame is added, all the existing frames take the same name as the new one. Onbviously this is due to the NAME_PLATE_UNIT_ADDED event but I'm unsure how else to go about it? I tried NAME_PLATE_UNIT_CREATED and had the same effect. Full addon code: Lua Code:
|
|
08-10-16, 12:54 PM | #9 | |
You should also not install hooks in such a function, of you'll end up with 10000 copies of the same function running every time the original hooked function is called, which will eventually have a very negative effect on your framerate. I still stand by my statement that one-time setup should be run in an event handler for NAME_PLATE_CREATED. Anything that runs for NAME_PLATE_UNIT_ADDED or NAME_PLATE_UNIT_REMOVED should not create any new objects or do one-time setup. Use those events (or hooks on functions that run in response to those events) only to show, hide, reposition, or otherwise change things that depend on the properties of the nameplate's current unit (like its classification).
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
||
08-10-16, 01:57 PM | #10 | |
What I would do, instead of hooking DefaultCompactNamePlateFrameSetupInternal(), is to hook the NamePlateDriver's ApplyFrameOptions() method.
Code:
hooksecurefunc(NamePlateDriverFrame,"ApplyFrameOptions",function(nameplate,unit) -- Code here end);
__________________
WoWInterface AddOns
|
||
08-10-16, 09:03 PM | #11 | |
Lua Code:
On a side note, inside a NAME_PLATE_UNIT_ADDED handler i am attempting to change the name shown on the nameplate with Code:
frame.name:SetText() I was thinking of various ideas to try and counter this, in BASH it would be easy enough to handle it with an if/then/else function, would that still be viable in Lua? And if so, how do I compare UnitName(unit) to frame.name, since frame.name is a table? Is it even possible? Would i have to use variables to compare the two? My idea was something like... Code:
local name = UnitName(unit) local level = UnitLevel(unit) local string = name.."("..level..")" hooksecurefunc( if frame.name == name then frame.name:SetText(string) end Last edited by Joker119 : 08-10-16 at 09:29 PM. |
||
08-10-16, 10:26 PM | #12 |
I was able to solve the name problem myself:
Lua Code:
Last edited by Joker119 : 08-10-16 at 10:28 PM. |
|
08-10-16, 11:33 PM | #13 |
New problem
Running into a new issue..
http://imgur.com/a/TeFTW After more and more nameplates are created, it does this. Lua Code:
I put the function that adds the textures inside a NAME_PLATE_CREATED event handler as you suggested, but it's still doing this. (i took it back out and confirmed it does the same thing either way) I'm unsure how I would go about changing the frame textures and such WITHOUT hooking into this function, I tried the one Phantom recommended but can't seem to get it to work, Code:
--SetupNamePlate local h = CreateFrame("Frame") h:RegisterEvent("NAME_PLATE_CREATED") h:SetScript("OnEvent", function(h, event, ...) if event == "NAME_PLATE_CREATED" then hooksecurefunc(NamePlateDriverFrame,"ApplyFrameOptions", function(nameplate,unit) --Health Bar nameplate.healthBar:SetStatusBarTexture(mediapath.."statusbar_fill") I also tried nameplate.UnitFrame.healthBar, nameplate.UnitFrame, nameplate.frame.healthBar, frame.unitplate.healthBar and frame.unitplate.UnitFrame.healthBar |
|
08-11-16, 03:14 PM | #14 | |
*cough*
Functions can be hooked more than once, so every time you call hooksecurefunc, it adds the provided function to the end of the chain. It doesn't replace the function you provided the last time you called it.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
||
08-11-16, 04:49 PM | #15 | |
Lua Code:
I moved the hook to the main chunk and put the rest in a event handler and use a variable to tie the frame.healthBar provided by the hook to the functions inside the event handler for NAME_PLATE_CREATED I was unsure how to work editing frame.healthBar without hooking that function, so that was my compromise. Am I getting at least alittle better now? |
||
08-11-16, 07:30 PM | #16 |
Is your GitHub repo up to date with your latest code?
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
08-11-16, 10:30 PM | #17 |
It should be (1.7....7? Or 8) if not I will fix it tonight when I get home. At work currently.
I may have moved the hook into the main chunk after my last git commit and forgot to resync the repo I was I'm a rush to finish putting together my motorcycle engine in time for work today. Woops. XD |
|
08-12-16, 10:29 AM | #18 |
GitHub is up to date, apparently I wasn't able to get the hook to pass the variable for some reason so I gave up on it, since the only thing the hook will do every time it's run is replace the statusbar texture and check if the others exist or not, it's not causing textures to be created a million times, so i left it alone.
If you know a way to get the hook to register a variable and pass it on in the main chunk, i'd much rather use the hook in the main chunk just to grab the frame.healthBar and pass it along, or if there's another hook I can use instead (I tried using NamePlateDriverFrame,"ApplyFrameOptions" but it always returns frame.healthBar is a nil value) |
|
08-12-16, 07:38 PM | #19 |
I don't really understand what variable you're trying to pass around.
If you're adding new objects and need to refer to them later, just store them on the frame. If you're adding multiple new objects, it may be easiest (and less prone to interference) to store them all in a table just for your addon: Code:
nameplateFrame.RothUI = {} local customBar = CreateFrame("StatusBar", nil, nameplateFrame) nameplateFrame.RothUI.customBar = customBar local customTexture = nameplateFrame:CreateTexture(nil, "OVERLAY") nameplateFrame.RothUI.customTexture = customTexture If you're working with the nameplate's default health bar or other objects/regions, you don't need a variable at all; just refer to it normally under "nameplateFrame.UnitFrame.healthBar".
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
08-14-16, 01:52 PM | #20 | |
Code:
8x ...ceRoth_UI\embeds\rNamePlates\rNamePlates.lua:62: attempt to index global 'nameplateFrame' (a nil value) |
||
WoWInterface » Developer Discussions » Lua/XML Help » Nameplate Unit Classification |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|