Thread Tools Display Modes
12-03-10, 04:34 AM   #1
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Threat addon, help needed

Allright, this is a module i've made for my layout a while ago and always had the same issue with it, it works for the most part exept for warriors.

I use it to detect who's tank and who's not, it's fine for every tanking classes exept warriors since their defensive stance isn't an aura, it isn't even listed in the buffs list. So i'm simply checking if they have a shield equipped, unfortunately, it only works for myself.

For testing purposes, i play a dps warrior and run a dungeon with another warrior tanking. What is happening is, whenever i equip a shield, the tanking warrior is considered as a tank, but if i equip 2x 2h weapons, he's also being considered as a dps.

Could anyone shed some light on this please ?

Code:
local _, caelThreat = ...

local abs = math.abs
local playerClass = caelLib.playerClass
local unitClass, lastWarning, itemLink, itemType

caelThreat.eventFrame = CreateFrame("Frame", nil, self)

local warningSounds = true

local isTankClassSpec = {
	["PALADIN"] = {
		GetSpellInfo(25780), -- Righteous Fury
		(GetSpellInfo(465)), -- Devotion Aura
	},
	["WARRIOR"] = function(unit) -- We check for this since Defensive Stance isn't an aura
		if unit == "player" then
			return IsEquippedItemType("Shields")
		else
			if CheckInteractDistance("unit", 1) then
				NotifyInspect("unit")
				itemLink = GetInventoryItemLink(unit, 17)
					if itemLink then
						itemType = select(7, GetItemInfo(itemLink))
					end
				return itemLink and (itemType == "Shields")
			end
		end
	end,
	["DEATHKNIGHT"] = GetSpellInfo(48263), -- Blood Presence
	["DRUID"] = GetSpellInfo(5487), -- Bear Form
}

local function IsTankCheck(unit, check)
	local status = false
	_, unitClass = UnitClass(unit)

	if type(check) == "table" then
		status = true
		for i = 1, #check do
			if not UnitAura(unit, check[i]) then
				status = false
			end
		end
	elseif type(check) == "function" then
		if isTankClassSpec[unitClass](unit) then
			status = true
		end
	elseif check then
		if UnitAura(unit, check) then
			status = true
		end
	end

	return status
end

local aggroColors = {
	[true] = {
		[1] = {1, 0.6, 0, 1},
		[2] = {1, 1, 0.47, 1},
		[3] = {0.33, 0.59, 0.33, 1},
	},
	[false] = {
		[1] = {1, 1, 0.47, 1},
		[2] = {1, 0.6, 0, 1},
		[3] = {0.69, 0.31, 0.31, 1},
	}
}

caelThreat.eventFrame:RegisterEvent("UNIT_AURA")
caelThreat.eventFrame:RegisterEvent("PARTY_MEMBERS_CHANGED")
caelThreat.eventFrame:RegisterEvent("UNIT_INVENTORY_CHANGED")
caelThreat.eventFrame:RegisterEvent("UNIT_THREAT_LIST_UPDATE")
caelThreat.eventFrame:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE")
caelThreat.eventFrame:HookScript("OnEvent", function(self, event, unit)
	if tostring(GetZoneText()) == "Wintergrasp" or MiniMapBattlefieldFrame.status == "active" then return end

	if not unit then return end

	_, unitClass = UnitClass(unit)

	local unitIsTank = IsTankCheck(unit, isTankClassSpec[unitClass])
	local playerIsTank = IsTankCheck("player", isTankClassSpec[playerClass])

	if GetNumPartyMembers() > 0 then

		if IsAddOnLoaded("oUF_Caellian") then
			if not oUF.units[unit] then return end

			local status = UnitThreatSituation(unit)

			if (status and status > 0) then
				local r, g, b = unpack(aggroColors[unitIsTank][status])
				oUF.units[unit].FrameBackdrop:SetBackdropColor(r, g, b, a)
				if oUF.units[unit].Overlay then
					oUF.units[unit].Overlay:SetStatusBarColor(r, g, b, a)
				end
			else
				oUF.units[unit].FrameBackdrop:SetBackdropColor(0, 0, 0, 0)
				if oUF.units[unit].Overlay then
					oUF.units[unit].Overlay:SetStatusBarColor(0.1, 0.1, 0.1, 0.75)
				end
			end
		end
	end
end)
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
12-03-10, 05:19 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,336
There are a bunch of errors in the code posted, but I'll address the question asked directly for now. After using NotifyInspect(), inspection information won't be available until after INSPECT_READY fires.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
12-03-10, 05:23 AM   #3
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Originally Posted by SDPhantom View Post
There are a bunch of errors in the code posted, but I'll address the question asked directly for now. After using NotifyInspect(), inspection information won't be available until after INSPECT_READY fires.
i've ripped off a part of the code that was irrelevant to the issue, that might be the errors you're seeing, or not, please explain.

About the NotifyInspect, correct me if i'm wrong, but you only need to wait for INSPECT_TALENT_READY if you want the talents data, this is not as far as i know necessary for gear inspection

Marks a unit for inspection and requests talent data from the server. Information about the inspected item's equipment can be retrieved immediately using Inventory APIs (e.g. GetInventoryItemLink("target",1)). Talent data is not available immediately; the INSPECT_TALENT_READY event fires once the inspected unit's talent information can be retrieved using Talent APIs (e.g. GetTalentInfo(1,1,true)).
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
12-03-10, 05:49 AM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,336
The inspection system changed in the 4.0.1 patch and WoWWiki hasn't been updated yet. I haven't tested the equipment side, but I know that the INSPECT_TALENT_READY event no longer exists and INSPECT_READY fires in its place when inspect data is available. The problem you're having with getting equipment info from other players is either with the delay in the inspection system or the new behavior with the item cache system. The item cache no longer stores items permanently, the cache is only kept for your current session then cleared on logout. If the client is queried for an item not in cache, it'll immediately return nil and forward the query to the server.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
12-03-10, 05:55 AM   #5
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Allright, but practically, what do i need to do to make my code work then ?
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
12-03-10, 03:03 PM   #6
jasje
A Chromatic Dragonspawn
 
jasje's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 150
might be a starter in Lua but i watched your question and found an addon that(i think) does what you want to achieve, addon is called lolthreat and this part might interrest you:
Code:
--detects if a Stance is on a Defensive Level
local function DetectStance(self, event)
	local _, _, active
	if (select(2,UnitClass("player")) == "WARRIOR") then
		_, _, active = GetShapeshiftFormInfo(2)
	elseif (select(2,UnitClass("player")) == "DEATHKNIGHT") then
		_, _, active = GetShapeshiftFormInfo(1)
	elseif (select(2,UnitClass("player")) == "DRUID") then
		_, _, active = GetShapeshiftFormInfo(1)
	end
might help or not just thought i share what i thought
__________________

Tukui | Github
  Reply With Quote
12-03-10, 04:50 PM   #7
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Originally Posted by jasje View Post
might help or not just thought i share what i thought
I don't think that GetShapeshiftFormInfo() works for units other than player, i'll check.
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
12-03-10, 05:00 PM   #8
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,362
You are right it doesn't.

I was struggling with this a few months back for another addon.
I didn't find a reliable way to detect if _other_ warriors are in defensive without addon comm.
(and requiring them to have that addon installed)

The issue is somewhat alleviated at least for group environments with the new role assignments.

It's still not 100% reliable as you're trusting what they chose in the role-poll or what the RL / PL marked them as with no way of checking what stance they're in to verify.
  Reply With Quote
12-03-10, 05:23 PM   #9
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
What about API UnitGroupRolesAssigned?
lua Code:
  1. local function IsTankCheck(unit)
  2.     if UnitGroupRolesAssigned(unit) == "TANK" then
  3.         return true
  4.     end
  5. end
Or did I miss something important?
  Reply With Quote
12-03-10, 05:35 PM   #10
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Originally Posted by Ketho View Post
What about API UnitGroupRolesAssigned?
lua Code:
  1. local function IsTankCheck(unit)
  2.     if UnitGroupRolesAssigned(unit) == "TANK" then
  3.         return true
  4.     end
  5. end
Or did I miss something important?
Of course that would probably work just fine, in random dungeon groups, but if you enter an instance manually, you don't select your role (granted, it doesn't happen often) or also, in raids, there are very few raid leaders doing rolechecks.
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
12-03-10, 10:19 PM   #11
Xinhuan
A Chromatic Dragonspawn
 
Xinhuan's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 174
A somewhat more reliable way to detect if a person is using a shield (and tanking) would be to listen to the combat log and look for damage taken that is reduced by the player having equipped a shield.

Of course, this would only be able to test for positive cases, not negative cases (i.e if the warrior respecs and takes off the shield, your addon wouldn't know).
__________________
Author of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, GatherMate2, Routes and Cartographer_Routes
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Threat addon, help needed


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