Thread Tools Display Modes
08-17-13, 06:12 PM   #1
nishay77
A Murloc Raider
Join Date: Aug 2013
Posts: 8
I need some help understanding how raid frame sorting works...

So I am making a simple addon to calculate the total amount of absorb heals currently on everyone in my raid. I have a separate frame for each raid member and anchored it to each raid member's unit frame.

Here is the problem:
I refer to each person in the raid group by UnitId that may or may not correspond to which position they occupy on default frames.

For example, Player A is occupying "raid6" (1st frame in group 2) on my raid frames (on default raid frames as well). However, it turns out Player A is the raid leader, so Player A's UnitId is "raid1". So if i update my addon for Player A, "raid1"'s frame is updated instead of "raid6". Domino effect -- "raid2" is now occupying "raid1" on my frames, etc...

Can someone shed some light on how to properly determine which frame I should update? Although Blizzard frames put Player A in its "raid6" (which is reflected in default raid frames after I move him there), his UnitId is still "raid1".

Any help is appreciated here. Thanks!
  Reply With Quote
08-17-13, 11:12 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The default raid frames can be sorted in several different ways, depending on the user's game settings. Fortunately, you don't actually need to worry about how they are sorted. The simplest solution would be to simply hook the function that each frame calls when it updates its own absorb display, and update your attached display frame at the same time:

Code:
hooksecurefunc("CompactUnitFrame_UpdateHealPrediction", function(frame)
	-- Find out which unit the frame is displaying:
	local unit = frame.displayedUnit

	-- Do stuff here.
end)
Without seeing your code, or even knowing what you're adding to the frames -- is it a texture? a font string? a status bar? something else? -- it's hard to give any more relevant suggestions, though.
__________________
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.
  Reply With Quote
08-18-13, 12:01 AM   #3
nishay77
A Murloc Raider
Join Date: Aug 2013
Posts: 8
Thanks for the reply. I am completely new at using LUA so my code is a bit noobish. I am not hooking into my raid frames, but rather I have 10 separate frames, one on top of each unit frame to keep track of that player's buff.

So I start with XML UI frames:
Code:
<Button name="TotalAbsorbsR1" parent="UIParent" enableMouse="false" movable="false" frameStrata="MEDIUM">
		<Size x="50" y="10"/>
		<Anchors>
			<Anchor point="TOP" relativePoint="CENTER" relativeTo="ElvUF_Raid10Group1UnitButton1">
				<Offset x="-2" y="-5"/>
			</Anchor>
		</Anchors>
		<Layers>
			<Layer level="OVERLAY">
			<FontString name="$parentText" inherits="GameFontNormalSmall" justifyH="CENTER" setAllPoints="true" text=""/>
			</Layer>
		</Layers>
	</Button>
I made 10 of these and anchored each one (just a FontString) to each ElvUI raid frame.

Then, I have a list of frames that I made and a list of corresponding units

Code:
unitlist = {"target", "player", "raid1", "raid2", etc..}
buttonlist = {"TotalAbsorbsTar", "TotalAbsorbsSelf", "TotalAbsorbsR1", etc..}
Now on UNIT_AURA event trigger, I loop through all units from "unitlist" and update the FontString with the new value. So when I update "raid1", then "TotalAbsorbsR1" is updated with that value. (obviously this is inefficient, but right now I am just focused on fixing my current problem)

So when I am in a raid and I move, for example, the raid leader from group 1 to group 2, he is now associated with Group2Spot1 in my raid frames and "TotalAbsorbsR6" frame in my addon. Therefore, his UnitId should be "raid6". However, his UnitId is still "raid1". So now my addon will update unit "raid1" and post it to "TotalAbsorbsR1", which has a different person.

How can I check which unit is occupying a specific raid frame. Or if you have another suggestion, I would love to hear it.

Thank you for the help!
  Reply With Quote
08-18-13, 01:27 AM   #4
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
Queue Phanx's "don't use XML" in 3.. 2.. 1..

As an aside, I wonder what it is that leads new addon developers to go the XML route so often.
  Reply With Quote
08-18-13, 01:38 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I'm guessing it's because there are so many ancient tutorials floating around from the early days that nobody has ever bothered to update, and the people reading them don't notice that the article was written before the release of TBC.

Anyway:

It would have been helpful for you to mention that you were working with ElvUI from the beginning. My post was written assuming you were working with the Blizzard raid frames, since your post only talked about those. As I have never used ElvUI or looked at its code, and have no interest in doing so, there's a lot less help I can offer on that front.

However, if you post your entire, actual code (seriously, why does nobody do this, even when explicitly asked to show their code???) instead of just some random snippets and vague descriptions of the code, I can probably solve your problem anyway... right now it looks like you're using a hardcoded list of units in a hardcoded order instead of actually looking at which units are being displayed on the frame.
__________________
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.
  Reply With Quote
08-18-13, 02:25 AM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Originally Posted by Phanx View Post
I'm guessing it's because there are so many ancient tutorials floating around from the early days that nobody has ever bothered to update, and the people reading them don't notice that the article was written before the release of TBC.
Or ancient addons that still might have some relevence were built on XML .
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 08-18-13 at 02:47 AM.
  Reply With Quote
08-18-13, 03:57 AM   #7
nishay77
A Murloc Raider
Join Date: Aug 2013
Posts: 8
Originally Posted by pelf View Post
Queue Phanx's "don't use XML" in 3.. 2.. 1..

As an aside, I wonder what it is that leads new addon developers to go the XML route so often.
I started learning WoW LUA from a WoW Programming book [World of Warcraft Programming (2nd Edition)]. In there, they say to use XML, but I honestly don't really see why. I need to switch everything to LUA to make it manageable.
  Reply With Quote
08-18-13, 06:04 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yeah, ditch that book. Based on your code, I'd have to say that book is incredibly outdated, and is doing you a lot more harm than good.

Anyway, as suspected, the problem is that you are hardcoding your frames/units -- eg. you always attach your first frame to the first raid frame, and assume that corresponds to the "raid1" unit based on your hardcoded table of units. This assumption will nearly always be wrong. Instead, you should do several things:

(1) Parent your frames to the relevant raid frames instead of to the UIParent.

(2) When you update one of your frames, figure out which raid frame it's parented to, and then look at that frame to determine the unit. For default raid frames, the currently displayed unit is stored on the frame itself under the "displayedUnit" key as shown in my earlier post. For ElvUI frames, you'll have to figure it out yourself.

On a side note, there are a lot of other issues in your code:

(1) Currently you are putting your "unitlist" and "buttonlist" variables in the global scope. Don't do that. Make them local instead, as there is no need for them to be accessible outside of this file.

In cases where you do need variables to be global, give them names that are (a) unique and (b) clearly identify them as part of your addon, eg. "TotalAbsorbs_UnitList", but this is not one of those cases.

(2) Currently you are updating all frames whenever (a) any aura changes on any unit, including units who are not group members, (b) your target changes, or (c) any group roster change occurs. This is hugely wasteful, especially (a) which can fire hundreds of times per second in a raid combat situation.

Instead, since your addon is only concerned with absorption amounts, you should ignore all of those events, and just respond to UNIT_ABSORB_AMOUNT_CHANGED, which fires specifically to tell you about changes in the amount of absorption on a unit. When the event fires, you do not need to update every single frame -- only the one connected to that unit.

(3) Instead of looking at a few auras to figure out the amount of absorption, you should use the API functions that exist specifically to tell you how much absorption the unit has from all sources:

Code:
local amount = UnitGetTotalAbsorbs(unit)
(4) The table.getn function is deprecated. You should use the # operator instead:

Code:
for i = 1, #unitlist do
Even if it wasn't deprecated, it's still a function call, which is slow and should be avoided whenever possible.

There are a lot of other minor issues, but none of them are critical and will just distract you from the important issues. I'd suggest starting over using pure Lua, proper parenting, and the absorb-specific event and API as described above.
__________________
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.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » I need some help understanding how raid frame sorting works...


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off