#Need help creating texture based on target's specialization

1 messages · Page 1 of 1 (latest)

sharp cairn
#

Hi, I have my own images that I want to use for class specializations. But I can't figure out how to make weakauras identify specialization of target and show corresponding image. So, if target spec = devastation, then my devastation texture should be shown. If spec = augmentation, then it's corresponding texture should be shown. Is this possible? Thanks.

Edit: Or if it's somehow possible to get spec text off of tooltip. Not ideal, but it's something - if possible.

loud root
#

In arena or in general?

#

The default triggers won't be able to help you either way sadly for target specs.

#

For arena there's: loop from i = 1 to GetNumArenaOpponentSpecs(), do GetArenaOpponentSpec(i)

#

Which is available during arena prep phase

#

For generic target spec: CanInspect check, if true -> NotifyInspect -> react to the INSPECT_READY event that then fires with GetInspectSpecialization

#

In either of these 2 cases, you can plug the result into GetSpecializationInfoByID, the fourth return is the icon ID of the spec.
But seeing that you have your own icons, you'd just match the specID you got to any of your icons I guess

#

There's also LibSpecialization, which comes bundled with WA, that should probably handle much of the process for you, but I haven't looked into that

sharp cairn
#

In general. I will take a look at these and revert.

sharp cairn
#

@loud root I decided to first just get a print of specialization to keep things simple; with the code below, I am able to print the spec ID correctly, but for some reason, the more targets I select the more times print is being shown. So, when I select one target, print shows their spec ID once. When I change to another target, print now shows twice in chat. If I change again, print is shown 3 times.

The way I've set up aura is Text aura, with trigger as Player/Unit info -> Unit Characteristics -> Target, so that aura is triggered only when I select a target. The text is custom, so the below code is added in custom text box.

I understand I have to unregister the event at some point, just not sure how/where to do that. Code -

function()
local x = CreateFrame("Frame")
if CanInspect("target") then
NotifyInspect("target")
x:RegisterEvent("INSPECT_READY")
x:SetScript("OnEvent", function(self,event, ...)
local spec = GetInspectSpecialization("target")
print("Spec is", spec)
end)
end
end

fierce nova
#

thats not a weakaura.

#

that code will break many things for you.

#

you are creating hundreds of frames and subscribe multiple times to that event.

sharp cairn
#

@fierce nova Can you please point me in the right direction? I'm new to weakauras and Lua.

#

The above code is based on an addon called TipTop, a tooltip addon. I understand creating multiple frames is not good memory-wise. Figured I'll first get the thing working, then optimize.

fierce nova
#

do never create frames in weakauras.

#

this is a thing for a custom trigger. it has nothing to do in a custom text function.
you dont need to listen to events yourself. a trigger can do that for you if you list the event in the event box

#

!starterkit

vocal pagodaBOT
sharp cairn
#

I'll try that, thanks.

sharp cairn
#

So, I tried this. Actually worked for the most part. What I did was, I made two text auras. 1st with trigger for UNIT_TARGET:player event and 2nd with trigger for INSPECT_READY. In 1st aura, I just made UnitExists("target") and CanInspect checks and then usd NotifyInspect to fire off INSPECT_READY. In 2nd aura, custom trigger just checks if UnitExists("target"). In 2nd aura -> Name Info box, I used GetInspectSpecialization("target"). With the Text box in Display tab as %n, I'm now able to show the specID of the target's specialization.

With this method, I can listen to events without having to register frames. So far, so good. Now, my only problem is that 2nd aura text i.e. specID doesn't go away if I deselect a target. It updates when I switch target as INSPECT_READY is fired again. Not sure what to do about this.

#

@fierce nova Would you be able to help?

fierce nova
#

you dont need multiple auras for that.

sharp cairn
#

Oh. Do I use custom function for trigger combination to consolidate?

#

Or maybe use both events in same box. Hmm.

#

But okay I can optimize that later. First, how would I make sure the text goes away once I deselect a target?

#

My untrigger in 2nd aura is not actually working. :/

sharp cairn
#

Finally figured it out. Writing here in case anybody else want to use it -
2 custom triggers in the same icon aura. 1st trigger -> EVENT ->UNIT_TARGET:player, TRIGGER ->
function()
if UnitExists("target") and CanInspect("target") then
NotifyInspect("target")
return false
else return true
end
end
UNTRIGGER -> function()
return true
end
ICON Info -> set some fallback icon. Make sure path has double \ instead of single \

#

2nd trigger -> INSPECT_READY,
TRIGGER -> function()
if InspectFrame and InspectFrame:IsShown() then
return false
else if UnitExists("target") then
return true
end
end
end
UNTRIGGER -> function()
if not UnitExists("target") then
return true
end
end
Icon Info ->
function ()
local t = {
[250] = "Interface\ICONS\Spell_Deathknight_BloodPresence", and so on for every spec
}
local id = GetInspectSpecialization("target")
return t[id]
end

#

Again, make sure icon path string has double backward slash, not single. Discord autocorrected my above text.

The only issue I see with above code in terms of results is that when you deselect a target, any existing icon from a previously selected target will not get cleared. This is because to clear it, the untrigger from 2nd aura needs to be called, which cannot be called as INSPECT_READY won't be fired when deselecting a target. So, the solution to this is by setting up two condition. If Trigger 1 -> Active -> True Then, Alpha = 0%. Else If Trigger 2 -> Active -> True Then, Alpha = 100%. This should hide the fallback icon when a target is not or deselected.

I'm sure there are many improvements that can be made. I'm very new to Lua and WA, so my code is most def suboptimal. But hey, it works!

This thread can be closed, as problem has been solved. Thank you, Spaten & Guffin.

neat shell
#
// In discord turns into / use ///
loud root
#

this is how I'd do it, a single trigger reacting to both events

#

and I don't see any issues

sharp cairn
# loud root https://wago.io/9xAJBgzM6

Yes, this is way better than mine. I didn't know about checking event name within function, and about aura_env.specId. This will help a lot with my future weakauras. Thanks again 🙂 @loud root

copper kettle
#

@loud root I want to do something like https://wago.io/9xAJBgzM6 but basically i want to have an aura that uses the enemy spec per enemy in arena games, so I want to keep the info persisently for each arena enemy during the game.

Thoughts on how to structure this? Keep track in aura_env of the name of arena1, and if the current arena1 name != the one in aura_env, then NotifyInspect / GetInspectSpecialization and store the spec in aura_env? But what events would I use to kick it off?

Wago.io is a database of sharable World of Warcraft addon elements

neat shell
#

you can't notifyinspect an enemy.

#

arena has a specific function to get the spec of your enemy