Go to Page... |
|
Thread Tools | Display Modes |
11-30-09, 11:15 PM | #1 |
How to: Read talents from other players
I've seen an unusually high number of requests for information about this lately, so I thought I'd post a general guide.
A couple of points to start out with: 1. Blizzard will hopefully fix the (poorly designed) talent inspection system at some point (nUI's author has reportedly heard that they plan on doing so ...hopefully that will happen sooner than "soon" but who knows...In any case, when that happens it will hopefully make most of this obsolete. 2. Many people can get the work done for them by using a library instead of doing it yourself. Obviously I'm assuming here that you want to do it yourself, though. 3. You will need to be familiar with events and event handlers. See the wiki if you're not: http://www.wowwiki.com/Handling_events ------------------------------------------------------------------ It's obvious from a quick search on the wowwiki API page that it's possible to read the talents of the player using functions like GetTalentInfo. From that page: Code:
local numTabs = GetNumTalentTabs(); for t=1, numTabs do local numTalents = GetNumTalents(t); for i=1, numTalents do nameTalent, icon, tier, column, currRank, maxRank= GetTalentInfo(t,i); DEFAULT_CHAT_FRAME:AddMessage("- "..nameTalent..": "..currRank.."/"..maxRank); end end Code:
local function DoInspect() local nameTalent = GetTalentInfo(1,1) DEFAULT_CHAT_FRAME:AddMessage(nameTalent) end It looks like we can get the talents from another player by just passing true as the third argument, but note that the player that the talents will be read from is the inspected player, that is the player that was last inspected by the local player. You cannot read the talents of anyone other than the local player, or the most recently inspected player. The good news is that addons can trigger an inspection of the target or any party/raid member without opening the inspection window, or doing anything that the person playing will notice. You do this with NotifyInspect("unit") -- note that you must first make sure the unit to inspect is within range, etc. Assuming we want to get the talents of our current target, this gives us: Code:
--NB: This code will not work as expected! local function DoInspect() if CanInspect("target") then NotifyInspect("target") local nameTalent = GetTalentInfo(1, 1, true) DEFAULT_CHAT_FRAME:AddMessage(nameTalent) end end Code:
--NB: This code will still not work as expected! local f = CreateFrame("frame") f:SetScript("OnEvent", function(self) self:UnregisterEvent("INSPECT_TALENT_READY") --we only care about the first event after we call NotifyInspect local nameTalent = GetTalentInfo(1, 1, true) DEFAULT_CHAT_FRAME:AddMessage(nameTalent) end) local function DoInspect() if CanInspect("target") then NotifyInspect("target") f:RegisterEvent("INSPECT_TALENT_READY") end end To correct for this, we need to make sure that no one has called NotifyInspect since the last time we did. This can be done with hooksecurefunc: http://www.wowwiki.com/API_hooksecurefunc ...briefly, when you call hooksecurefunc, you specify a function to watch. Every time that funciton gets called by anyone, it will trigger a call to a second function that you specify. In this case we want to watch for anyone calling NotifyInspect and, if anyone does, note that it was called so that we can ignore the result and try again. This gives us: Code:
--NB: This code will work most of the time but is not perfect yet. local inspectTainted hooksecurefunc("NotifyInspect", function() inspectTainted = true end) local f = CreateFrame("frame") f:SetScript("OnEvent", function(self) self:UnregisterEvent("INSPECT_TALENT_READY") if inspectTainted then if CanInspect("target") then -- in this case we could just call DoInspect (if it was higher in the file), but i'll write it out for the example self:RegisterEvent("INSPECT_TALENT_READY") NotifyInspect("target") inspectTainted = false end else local nameTalent = GetTalentInfo(1, 1, true) DEFAULT_CHAT_FRAME:AddMessage(nameTalent) end end) local function DoInspect() if CanInspect("target") then NotifyInspect("target") inspectTainted = false f:RegisterEvent("INSPECT_TALENT_READY") end end Last edited by Akryn : 11-30-09 at 11:21 PM. |
|
WoWInterface » Developer Discussions » Tutorials & Other Helpful Info. » How to: Read talents from other players |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Switch to Hybrid Mode |
Threaded Mode |
|
|