Thread Tools Display Modes
01-31-16, 09:47 AM   #1
itroitnyah
A Murloc Raider
Join Date: Jan 2016
Posts: 7
[WA] Getting unit spec

Like the title says, I'm trying to get unit specs in Weak Auras. I've just created a Text item and just need it to read the unit's spec (I'm not going to use this for targets). I don't know a whole lot about LUA code, but I've managed to shamble together some basics just from observing what other people are doing. Here's where I'm at right now:

Code:
function()
    local spec = GetSpecialization("player")
    return GetSpecializationNameForSpecID(spec)
end
The problem is that it doesn't return anything. My framerates drop to 11. But when I put a number (such as 105) in place of "spec" in the return, I get the name I'm looking for and my fps returns to normal. I need a way to get my variable to return the unit's specID so when the return function runs, it reads the variable and prints out the appropriate response.

I just use wowprogramming to try and figure out what do, and according to the documentation on "GetSpecializationNameForSpecID", it requires a valid SpecID to work. In theory, by declaring a variable that prints out somebody's active spec's ID and placing the variable as an argument for GetSpecializationNameForSpecID, that should print out the unit's spec and I can't figure out why it isn't. I have noticed that running "return GetSpecialization("player")" doesn't print anything out, so I wondering if that may be the issue?
  Reply With Quote
01-31-16, 11:15 AM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
GetSpecialization doesn't take a unitID; by giving it an argument you're actually telling it that you want information about the player you're inspecting, and it's probably returning nil, which will throw an error when you feed it to GetSpecializationNameForSpecID, which I guess is killing your frame rate because you're calling this OnUpdate.

You can try writing it like this..
Lua Code:
  1. function()
  2.     local specID = GetSpecialization()
  3.     return specID and GetSpecializationNameForSpecID(specID)
  4. end
  Reply With Quote
01-31-16, 12:02 PM   #3
itroitnyah
A Murloc Raider
Join Date: Jan 2016
Posts: 7
Awesome, it stopped killing my framerates. My only issue now is that it won't actually print the result out in text. Any ideas?

Here's the WA if you need it:

d0tceaGEQGDPi12OG9PiPttYLOqXSv43aopu51ui5Buk1IOuzNkI9kTBvSFuJcu1FbQXjIESQmukegmKgouEgiofOYXujNdKSqkvTufjwmLswUQ6HuO0tjwgv0Zf1ebIPcXKfPPJCrkfUkqkxw46u1gbfttrTzQ02Pu0hbs(jfQ(SimpGuDys9DkenAkA8uHojO0TaPUgu19OqQvQ0TPKHPsDVksfRkPvslsfxGdjkhIo5cFLuvgBOXHeosvmMhVvE(mbyHeosvC9NhPaoWdhVmkJYOm6a4PhmAglEWccJA0mkOcsWINspuoOjfWbE7WgACX3o44LrzugLr)b5)hgnJfpybHr1NugfubjyXtPhkh0Kc4mrBfWa8fS4bliWNXIhSGahVXjLxE5LxE5LxE5LxE5LxE5LxE5LxE5LxE5LxE5LxE5LxE5LxE5LxE5LxERGZ4UU5GkmqNeYnK5KgUNHCz42W1vDHE2qf1rrGFawyJGI0o5QYpsOaoi4WIku4ivjhdxJaqDOkgRnMGyJPuH(QejIFrQ8g6CUcitb0GfKk(Ca(n05CTvfZqpitWayXxta)ktTcHdlQKjn5Zv85aSzOhKzTVYZNjalWeoSOsM0Kpx55ZeGfytvAuHuwrAfZqpiZk3v85a8rBf1wvE(mbyvX1FEKc4apC8YOmkJYO)G8)dJcQGeS4P0dLdAsbCG3oSHgx8TdoEJtkV8YlV8YBf)jSzCOkpFMaSQ8mJNrvXJLQPOIphG9hfv7lvX9RTcH(As3jqvXivPKzHzg)nedqGmJ)2jeBdfEN1fA8xvuPvWgACXNrZyXRYXBH8vjse)CNCvXrJ76MdQWG3GtOS9nEdq50WmeiotwxOXFxXmujmPctY55zNqsI3aeOUVMNVRl0ZjRma0PfPsQY1v98dcxrQy5hKQiLkv5RFrrQy5hKQiLkv5dmIIuXYpivrkvQcPhXHksfl)GufPuPkU6hPaofPILFqQIuQuPk(d9vjse)IuXNdWMHEqM1(kMHEqMGbWIVMa(va9k(Ca2FuuTVIzOhKzL7k(JIQGn04IFPsvYvCo9103tFLSIn7KRzNxLAba

Last edited by itroitnyah : 01-31-16 at 12:12 PM.
  Reply With Quote
01-31-16, 12:21 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Because you still have GetSpecialization("player") instead of GetSpecialization(), it doesn't take a unit ID as an argument.
  Reply With Quote
01-31-16, 01:09 PM   #5
itroitnyah
A Murloc Raider
Join Date: Jan 2016
Posts: 7
Even without "player" it still prints nothing. I want it to print "Restoration" or whatever spec it gets told to. Furthermore, that just raises the question of "how do I get it to read the spec of a specific unit?"
  Reply With Quote
01-31-16, 04:21 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Did you try this function instead?
http://wowprogramming.com/docs/api/G...zationInfoByID
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-31-16, 04:53 PM   #7
itroitnyah
A Murloc Raider
Join Date: Jan 2016
Posts: 7
I tried it and it doesn't return anything either. Replacing the "specID" argument in the GetSpecializationInfoByID with one of the API specIDs just returns the API specID (104 just prints 104 on the screen).

From my understanding, the problem appears to be that the variable I am putting into the argument for GetSpecializationNameForSpecID isn't appearing as a specID. I don't understand why it doesn't, or how to get it to do that.
  Reply With Quote
01-31-16, 06:21 PM   #8
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
The second argument should be the thing you are looking for:

Lua Code:
  1. local id, name, description, icon, background, role = GetSpecializationInfo(GetSpecialization())

You can reach it with more hassle too, but it's almost an inception, and it's trademarked by DiCaprio:

Lua Code:
  1. local specName = GetSpecializationNameForSpecID(select(1, GetSpecializationInfo(GetSpecialization())))
  2. -- You should leave out the select here, it's only to indicate which argument you should pass

Last edited by Resike : 01-31-16 at 06:47 PM.
  Reply With Quote
01-31-16, 06:58 PM   #9
itroitnyah
A Murloc Raider
Join Date: Jan 2016
Posts: 7
Thanks Resike. Your first suggestion worked. Here's where it's at right now:

Lua Code:
  1. function()
  2.     local specID = GetSpecializationInfo(GetSpecialization())
  3.     return specID and GetSpecializationNameForSpecID(specID)
  4. end

I still need to work on getting it to work with units other than player, but I'm done for the night and will deal with it later. Really appreciate the help!
  Reply With Quote
01-31-16, 07:24 PM   #10
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by itroitnyah View Post
I still need to work on getting it to work with units other than player, but I'm done for the night and will deal with it later. Really appreciate the help!
This may be what you want: http://www.wowace.com/addons/libgroupinspect/
  Reply With Quote
02-01-16, 03:21 AM   #11
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
It looks like GetSpecialization just returns the index of your current spec out of your class's total number of specs (so 1-3 or 4); not to be confused with the "specID" that half of the specialization functions require, which is the result of calling GetSpecializationInfo on the index.
  Reply With Quote
02-01-16, 06:06 AM   #12
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by itroitnyah View Post
Thanks Resike. Your first suggestion worked. Here's where it's at right now:

Lua Code:
  1. function()
  2.     local specID = GetSpecializationInfo(GetSpecialization())
  3.     return specID and GetSpecializationNameForSpecID(specID)
  4. end

I still need to work on getting it to work with units other than player, but I'm done for the night and will deal with it later. Really appreciate the help!
You can refactor the code, to make it more efficient like this:
Lua Code:
  1. function()
  2.     local _, specName = GetSpecializationInfo(GetSpecialization())
  3.     return specName
  4. end
  Reply With Quote
02-01-16, 12:15 PM   #13
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Resike View Post
You can refactor the code, to make it more efficient like this:
Lua Code:
  1. function()
  2.     local _, specName = GetSpecializationInfo(GetSpecialization())
  3.     return specName
  4. end
Like the original script, this will start throwing errors if you don't have an active spec (if your character is too low or you talk to a trainer to respec), so you should check that GetSpecialization isn't nil before you call GetSpecializationInfo on it.

Lua Code:
  1. function()
  2.     local specIndex = GetSpecialization()
  3.     if specIndex then
  4.         local _, specName = GetSpecializationInfo(specIndex)
  5.         return specName
  6.     end
  7. end
  Reply With Quote
02-02-16, 04:20 PM   #14
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by semlar View Post
Like the original script, this will start throwing errors if you don't have an active spec (if your character is too low or you talk to a trainer to respec), so you should check that GetSpecialization isn't nil before you call GetSpecializationInfo on it.

Lua Code:
  1. function()
  2.     local specIndex = GetSpecialization()
  3.     if specIndex then
  4.         local _, specName = GetSpecializationInfo(specIndex)
  5.         return specName
  6.     end
  7. end
Maybe also return a proper value then:

Lua Code:
  1. function()
  2.     local specIndex = GetSpecialization()
  3.     if specIndex then
  4.         local _, specName = GetSpecializationInfo(specIndex)
  5.         return specName
  6.     else
  7.         return "None"
  8.     end
  9. end
  Reply With Quote
02-03-16, 07:40 AM   #15
itroitnyah
A Murloc Raider
Join Date: Jan 2016
Posts: 7
Sorry for not responding, had classes and didn't play yesterday.

Got back today, tried out all of your suggestions and they worked great. Really appreciate the help. I can't seem to figure out how to get the LUA to target a specific unit, such as "party1". I can only ever get it to show the spec that I am, and I would like it to work with other units as well.
  Reply With Quote
02-03-16, 10:43 AM   #16
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by itroitnyah View Post
Sorry for not responding, had classes and didn't play yesterday.

Got back today, tried out all of your suggestions and they worked great. Really appreciate the help. I can't seem to figure out how to get the LUA to target a specific unit, such as "party1". I can only ever get it to show the spec that I am, and I would like it to work with other units as well.
Getting someone elses spec is a bit more tricky, and only works if the player is in range and if you are targeting them:

Lua Code:
  1. local f = CreateFrame("Frame")
  2.  
  3. function InspectSpec()
  4.     if CanInspect("target") then
  5.         f:RegisterEvent("INSPECT_READY")
  6.         NotifyInspect("target")
  7.     else
  8.         --print("Can't inspect target")
  9.     end
  10. end
  11.  
  12. f:SetScript("OnEvent", function(self, event, ...)
  13.     local specID = GetInspectSpecialization("target")
  14.     f:UnregisterEvent("INSPECT_READY")
  15.     ClearInspectPlayer()
  16.     local specName = select(2,GetSpecializationInfoByID(specID))
  17.     print(specName)
  18. end)
  Reply With Quote
02-04-16, 05:46 PM   #17
itroitnyah
A Murloc Raider
Join Date: Jan 2016
Posts: 7
Alright, I'm back again.

After messing around with what I have been given up to yesterday and what you gave me most recently Resike, I've pretty much given up. What you've given me is great, but not exactly what I want for my application. Thanks again for the help. Perhaps some day we can look forward to WA implementing a feature that detects your talents and other player's talents?
  Reply With Quote
02-05-16, 08:13 AM   #18
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by itroitnyah View Post
Alright, I'm back again.

After messing around with what I have been given up to yesterday and what you gave me most recently Resike, I've pretty much given up. What you've given me is great, but not exactly what I want for my application. Thanks again for the help. Perhaps some day we can look forward to WA implementing a feature that detects your talents and other player's talents?
I personally think it's a big flaw in the game, that you can't get such information like unit spec, talents, and spell cooldowns directly from the unitid.

I don't think this inspecting method is even remotely convenient or saves any bandwidth for the servers. I think this calls should be like the latency one, update the values every 30 second (and some relevant events), if called in between then return the last cached value locally from the client. This would be a proper bandwidth saver.

Last edited by Resike : 02-05-16 at 08:18 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » [WA] Getting unit spec


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