Highlight Targeted unit
So I'm wondering is there a good way to highlight the currently targeted unit frame (using oUF to do Nameplates)?
I've been testing it out and I have it working nicely to show nameplates but the issue I have is I would really like to slap a border on the currently targeted units nameplate. I thought maybe I could use the callback event but it doesn't fire (always) fire an event when changing through targets. Any ideas? Thanks, R |
Pass a function as the second parameter to oUF:SpawnNamePlates, it will be called whenever a new nameplate unit is used or when the player changes targets.
Then use UnitIsUnit('target', unit) in that function to check if they match (unit being the 3rd argument passed to the function), and proceed to show/hide your border. Drycoded example: Lua Code:
Shorter version Lua Code:
|
Thanks for the response. That's almost identical to what I am doing. If I attack more than one mob at a time, so I tag one it will highlight properly (don't kill it), then I tag another unrelated mob (don't kill it) both mobs stay highlighted. It's so close! lol. Thanks.
Code:
local OnSpawnNamePlates = function(self, event, unit) |
It's been years since I worked on a oUF layout, but in this case, I guess it would be as simple as this:
Code:
local oldTarget |
Just a semantic nitpick, but if you're going to name your function instead of just passing it anonymously to oUF, you should change "OnSpawnNamePlates" to something that more accurately reflects when the function is actually called, like "OnAcquireNamePlate". In oUF land, "spawn" is something that happens once per frame, the first time the object is created, but the nameplate callback happens every time a nameplate frame (whether it's newly created or pulled from the pool of existing frames to be reused) gets assigned a unit.
It may not make much difference now, but when you're going back to your code in 6 months or 3 years, having that function named "spawn" is going to confuse you. |
Good lord I thought I was anal retentive about naming conventions at the office, you're right though. :)
|
Thanks aallkkaa, I went with something similar. :)
|
If I just add it in the spawn fieid, it would not work properly for me. When I change units, the old mark won't go away.
This is what I currently do. Code:
local function UpdateTargetMark(self) |
Thanks Siweia, I've gotten mine working. :)
|
Quote:
|
Quote:
This does not mean the function will also run for the nameplate that was the previous target, hence the solution you had to come up with (which IMO is the correct solution). To sum it up in code: Lua Code:
|
Quote:
Quote:
-- edit #1 aallkkaa's solution is a good one if you want to use only spawn callback. You need to update old target and new target nameplates, so you have to track the old target. On a side note, we could probably remove PLAYER_TARGET_CHANGE handling from oUF nameplate driver entirely and make layout devs handle it on their own. |
Quote:
If you set the cvar nameplateMaxDistance in 40 yards, but you select a unit outside 40 yards, the highlight border would not show up properly. |
Quote:
|
Lua Code:
|
All times are GMT -6. The time now is 09:34 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI