Thread Tools Display Modes
03-08-14, 03:27 AM   #1
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Help with a table issue

Ok so, here's my good old nameplates addon

http://pastebin.com/ATJTK2VN

Now here's my threat oUF module

http://pastebin.com/ghNQfx5k

I don't want to use the default nameplates threat coloring instead, i want to use my own. So, i feed the plates in a global table (nameplates lines 307 and 328) and then use that table to color them (threat lines 132 to 141)

The issue i need help with:

Currently, when i enter combat with a group of mobs, all the plates light up showing the threat color of my target instead of their own threat in relation to me.

Does anyone know what i have to change to make it work on a plate per plate basis ? (so that each plate show their own threat) ?
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
03-08-14, 06:18 AM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Read http://wowprogramming.com/docs/api/UnitThreatSituation

Add the nameplate unit to test to
Lua Code:
  1. local status = UnitThreatSituation("player")

Or use http://wowprogramming.com/docs/api/U...hreatSituation. I'm not sure. Just read the descriptions.

Last edited by Duugu : 03-08-14 at 06:21 AM.
  Reply With Quote
03-08-14, 06:57 AM   #3
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
That's not the issue at all, actually the threat module works just fine, it's the nameplates. in other words, ALL the nameplates visible on screen show the colors of the nameplate of my target, probably because they're all being fed to the table without any distinction. So, the threat module takes everything in the table and colors it according to my current target when they should be fed one by one, independently.
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
03-08-14, 07:21 AM   #4
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Well, as far as I understand your code you are iterating over all the nameplates and recolor them here:

Code:
                       for _, plate in pairs(caelUI.plates) do
133.                                local status = UnitThreatSituation("player")
135.                                if (status and status > 0) then
136.                                        local r, g, b = unpack(aggroColors[playerIsTank][status])
137.                                        plate.healthBar.hpGlow:SetBackdropBorderColor(r, g, b)
138.                                else
139.                                        plate.healthBar.hpGlow:SetBackdropBorderColor(0, 0, 0)
140.                                end
141.                        end
The color values are based on
Code:
local status = UnitThreatSituation("player")
if (status and status > 0) then
The if clause has the same result for every single nameplate. Because you're requesting a general aggro value and not the value for the actual namplate unit (I'm not sure what UnitThreatSituation("player") does reaturn. But whatever it is ... it's the same value for ever single step in you loop.)
  Reply With Quote
03-08-14, 08:06 AM   #5
Oppugno
A Fallenroot Satyr
Join Date: Sep 2012
Posts: 22
So two hours later the website is stable enough so I can finally post:

As far as I'm aware it is unfeasible to get accurate threat information for nameplates other than from the supplied threat region on the nameplate(s). This is because the methods for determining threat (UnitThreatSituation, UnitDetailedThreatSituation) require a unitID (for both the threater and threatee). Because nameplates inherently don't have unitIDs linked to them and although it would be possible to match unitIDs to nameplates in a limited scope it's just not feasible as a threat indicator on a large scale.

The practical way to guarantee known threat on nameplates is to use the provided threat region on them.

If you want a simple solution to your answer replace lines 132-141 in Threat with this:
Lua Code:
  1. for _, plate in pairs(caelUI.plates) do
  2.     if plate:Visible() -- This won't be neccessary if the table only contains active nameplates
  3.         if plate.healthBar.oldGlow:IsShown() then
  4.             local r, g, b = plate.healthBar.oldGlow:GetVertexColor()
  5.            
  6.             -- 0 - Unit has less than 100% raw threat (default UI shows no indicator)
  7.             -- 1 - Unit has 100% or higher raw threat but isn't mobUnit's primary target (default UI shows yellow indicator)
  8.             -- 2 - Unit is mobUnit's primary target, and another unit has 100% or higher raw threat (default UI shows orange indicator)
  9.             -- 3 - Unit is mobUnit's primary target, and no other unit has 100% or higher raw threat (default UI shows red indicator)
  10.             -- You can get the colours from GetThreatStatusColor(#)
  11.             local status = (g + b == 0 and 3) or (b == 0 and 2) or 1
  12.            
  13.             plate.healthBar.hpGlow:SetBackdropBorderColor(unpack(aggroColors[playerIsTank][status]))
  14.         else
  15.             plate.healthBar.npGlow:SetBackdropBorderColor(0, 0, 0)
  16.         end
  17.     end
  18. end
However, I'm not certain nameplates update for events as immediately as standard frames (I've seen 0.5s + delays) so your threat update events will probably trigger before the new threat colours show up on the nameplates.

Personally, the way I do it is as you've done previously, with an OnUpdate script. However, I use a single OnUpdate script and a table for tracking currently visible nameplates. It will benefit from less CPU time and less memory usage (compared to giving each nameplate it's own OnUpdate script).

Last edited by Oppugno : 03-08-14 at 08:19 AM. Reason: Clarified some stuff.
  Reply With Quote
03-08-14, 10:09 AM   #6
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Originally Posted by Oppugno View Post
Lua Code:
  1. if plate:Visible() -- This won't be neccessary if the table only contains active nameplates
If i'm not mistaken, once nameplates aren't visible on screen they don't exist anymore, meaning that the same applies to the table, or do you mean i have to clear the table manually ?
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
03-08-14, 08:15 AM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Duugu View Post
The if clause has the same result for every single nameplate. Because you're requesting a general aggro value and not the value for the actual namplate unit (I'm not sure what UnitThreatSituation("player") does reaturn. But whatever it is ... it's the same value for ever single step in you loop.)
UnitThreatSituation("player") without a second unit will return information based on the unit the player's threat is highest against. If you're on the threat table for 5 mobs, but only have aggro on 1, then it will indicate that you have aggro. To get information about your threat vs. a specific unit, you need to pass a second unit, eg. UnitThreatSituation("player", "target")

However, this only works for units with a current (and known) unit token, so it isn't a suitable solution for nameplates. Use the solution posted by Oppugno instead to get the information from the nameplate's default threat region.
__________________
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 » Help with a table issue


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