Building an Auto-Dismount WeakAura

A guildie of mine, named Druid, who ironically plays a Demon Hunter, suggested that I build a WeakAura that dismounts you whenever you speak to the Flight Master.

This obviously sounds strange, but it’s actually a great suggestion. The reason is that there is currently a bug in the game where some classes, Demon Hunter’s especially, will get disconnected if we take flight path’s while we are mounted. It’s extremely frustrating and the WeakAura that we’re going to build should help reduce the amount of times we get disconnected.

So let’s dig in and see if we can temporarily solve this frustration until Blizzard is able to put in a hotfix. I’m also going to cover some of the details of building the WeakAura here, to hopefully help others understand some of the details for building their own WeakAuras.

Weak Aura String

Here is the Weak Aura import string as well as the wago.io link.

!WA:2!DrvZUTTrq4O4w0cEj2QPgna5GqkQHDrRGQlIrUkAtfRwzjvkQyx0ciTK7qXnMAxMDxkl5BrN8z9iOZ9KEe8taHqrFa8JGrFa6UlfDskpqS78333m7mtPgLhxgxgFZ3UKeWO9yP8a45pIpTtyOaKL4Z2CyfIgeX4DzeQ0)yN2EoURdySym7kAVRijWWBlU6Ghbr26WnCUKtgnc4I27X3C8MDUlvadq(cg3)mggg6srJbH1QGuHKnEqebdUsYyaBlNLa(5Itk)bVofqXgpVtK6dtaQSxAyiz6QbhxVN3GEE1D9MJt5ijHrpSATFY1yKXpz094zkajbNSXGOcG1OLT7CnoPuICy22jhgMsd0gTVjc)qLQvREGvf1hhKPCALMIZyPujG3)alGITSSwIbFfB8ubJFQtRUn636bA2LdkA62RRtRwZfjqCCtSWkxN4oV6x08S6Dh0PRtBNtS1CWpjgnd4luqKx92nB7hVcteV1WRjWHi6SKDqMZE5MORm)1JUx9obCkk(nQQVkb(J7VeGK6kqdKU68oAHaIdnVNzFUI0cKuxqGOLk26cJu(i((BEAszjmvoqeHupTxSPzi5zgHMFHm(yKYGnhSPmkS4b1V47ejB)rr4ywmJ)lLkvAR7YLwWb76996K8vgHOu1ZHIJbNtWYi76QR3NJfzkGncF)68(XFFdJU1O)TQhss4mv(WzsvU4PeA3UtBNSNWvzL2MLgddm0yl13InjbvMSDdo56k)wkcRQdOkEEFsUxG0AJSRyC85CuY8Z3CiNaticIFmmCto)rZmj70SDBh3b2D886CMBZxFQ36hGUh5A4zBYOl(eC0AnTsD671QzBN)z9Oy2vn4W7sbAWSUFwTQh(Y8StRyL(xreMRVODETFQuYODMaCv70sT4waDKm6Rn2xKzl0xo(HkZTQbHxxijYwRmYGUxej4skieBz8OxakgYp2IOeVJbaBvDb4r(razuK892Xme(nl0ZwbXiHyOVu5fvUR740yjXYw3yUB2FA5AuVNVGqhfdRoX5SoTpTVEDJsPTqvO0wTKBAq1jx2xUw1VOkCDs0dQcRfikzSzY(ixHeXLnUfqcONKBY5Vi7jz1wxSDWm0ZfGAzfwmxBNjM1ShJi0gzHgRZgLfLrYQ5hsOer0)x8kcnV3xfpRL6irYzI91m24sCKzdI4OmyVfy2G8TnQTllpHigR3ES)bzxUxwsu22zVZwbH0APKfmjFW9Bkn4FFbbN88tGXmALt1BB4v(Xk6PIkfrW9dn0UO4Ki0wUxzgtomLGx9Q6tpIpT)V2x03xrVqYiloHQJpeL80I126Hfv8qQ(xC095nJn4QvZ6kIFVJDDCARx9Oxj1ufMhpVWZOvHA7uvy1CZwLfU)C1xwTw5j)9f)3d

Figuring out where to get started

The thing we need when creating a WeakAura is a goal. Our goal right now is to make our character dismount whenever we talk to a flight master. That’s quite a lot to take on right off the bat, so let’s see if we can break it down a bit.

To start … let’s try to find out if there is a way to dismount using the WoW API. Luckily, there is a /dismount command. So we can be fairly confident there will be something in the API that would allow us to dismount programatically as well. Sure enough, a quick Google led me over to wowpedia documentation where we can see the Dismount() function.

Okay … now we’ve got one question answered. The second thing we need to figure out is how to call that function whenever we talk to a flight master. This required me to do a little debugging. But before we get into the debugging let me explain what an event is in World of Warcraft.

What is an Event?

An event is just what it sounds like. They are things that occur in the game that addons and WeakAuras “listen” to and react accordingly. World of Warcraft is filled with events. This is very similar to how events work in the real world. Consider your doorbell, for example. That is an event that happens which causes you to get up from whatever you’re doing and go check the front door. That is essentially what happens in World of Warcraft events. In a nutshell, events allow addons and WeakAuras to do all their magic.

Just like in real life, events fire all the time. And if we want to automate something in the game, we just need to listen for the event we are interested in and act accordingly. In this instance … we have no idea what event we want to listen for. So how are we supposed to perform our action? This brings us to a debugging tool called the Event Log.

Understanding the Event Log

The Event Log is a debugging tool in the game that allows you to monitor all the events that are streaming in the game. We can use this tool to track down the event that we’re interested in. The command to open up the Event Log is /eventtrace. You can read up on some of the nitty gritty details of this command in the wowpedia documentation.

If you recall … there are a lot of events that happen in game. Sometimes the hard part of finding the event that you’re looking for, is swimming through the sea of other events that are being fired around the event you are trying to find.

A quick side note on debugging

Being able to debug and analyze events takes time and letting your brain get used to understanding what it is seeing. As a developer, you start to become more and more accustomed to these things. Whether you’re staring at a compilation error, a debugging error, or a stream of events. Your brain just gets better and better at it the more you see it. So don’t be frustrated if you’re new to this and can’t seem to find what you’re looking for. You’ll get better.

Hunting down our event

In order to hunt down the event we are interested in we need to get setup a bit. So I ran over to the nearest flight master, which just so happened to be in my Night Fae covenant. And I stared longingly into her eyes. She was probably a bit creeped out.

Now we can pull up my event log user interface with the trusty /eventtrace command. It should immediately start tossing events streams at us; which we need to get out of the way. This is where some of the buttons in the tool come in useful. I hit the “Pause” button to stop capturing events for a little bit. And then the “Discard All” button to clear out all the events that had been previously seen.

This left me with a blank slate that I could now work with. I just needed to be quick enough to click the “Play” button, talk to the flight master, and then hit the “Pause” button so I didn’t get inundated with a flood of other events.

Great. This left me with a dozen or so events to dig through. Sure enough … the event I was most interested in was right there towards the end.

The good ol’ TAXIMAP_OPENED event. Now we’re getting somewhere. I had the event that I wanted to react to and the function that I wanted to call whenever I saw it. The only thing left to do was to crack open WeakAura and toss some code together.

Building the WeakAura

The first thing we need to do is open up WeakAuras with the /wa command in your chat bar. Then hit the “New Aura” button. I chose to use the Icon WeakAura, because this specific aura doesn’t need any fancy animations, bars, or text.

Now we need to go over to the “Trigger” tab and specify when we want our WeakAura to execute some code. There are a number of ways you can trigger your code to run. Some are very simple: like monitoring for a buff or debuff. In this scenario we want to monitor for a custom event. Specifically the event we found in the previous step: TAXIMAP_OPENED.

In order to do that we need to select “Custom” option from the “Type” dropdown. And “Event” option from the “Event Type” dropdown. Now that we’ve got those selected we just need to tell WeakAura what event we want to monitor for. We can do this by entering in TAXIMAP_OPENED into the “Event(s)” text field. Be sure to watch out for typos here. After doing all those steps you should end up with a Trigger that looks like this:

Excellent! So far so good. We’re monitoring for the TAXIMAP_OPENED event, but we still need to tell this WeakAura whether or not we want to Trigger an action. This is done by filling out the “Custom Trigger” text area with some custom LUA code. Our code is very straight-forward. We simply want to return the value from an API call from the IsMounted() function. The custom code for this looks like this:

function(event, ...)
    return IsMounted()
end

This simply tells the WeakAura, “Hey, I want you to trigger this WeakAura if the event TAXIMAP_OPENED fires and I am mounted.” Your WeakAura at this point should look like this:

Executing our Action

At this point we have a WeakAura that triggers correctly, but it doesn’t actually do anything. This is where “Actions” come in. Our action is a simple one … we just want to dismount. In order to accomplish this, we need to go over to the “Actions” tab in our WeakAura. Actions, like Triggers, come in a few shapes and sizes. WeakAuras provides you with some common actions, like playing a sound or showing a chat message. In our instance, we want to execute some custom code.

It’s also important to notice that there are three (3) sections to an action. There is a On Init, On Show, and On Hide section. This ultimately allows you to do different things based on whether or not the WeakAura is initializing, showing, or hiding. Right now … we want to execute some code when the WeakAura is “shown.” Or more specifically, when we are mounted and talk to a flight master.

The custom action that we want to take is about as barebones as it gets. We just want to call the Dismount() function that we learned about earlier. So we’ll just need to check the “Custom” check box and plop in the Dismount() call into the “Custom Code” text area. You’ll end up with a custom on show action that looks like this:

Testing this bad boy out …

We’re doing great so far. We’ve got a brand new WeakAura that triggers when we’re mounted and talk to a flight master. It executes some custom code in an action. Now we just need to take it for a spin.

If you mount up and talk to a flight master. You should notice that you automatically get dismounted. Mission accomplished! Well not quite. We’ve got a little bit of a quirk with our implementation right now. Whenever our WeakAura activates, it never deactivates. So we end up with an icon that sits in the middle of our screen forever.

And no one wants to have some random icon sitting on their screen that serves no purpose. So let’s get rid of that thing …

Removing the WeakAura after it triggers

There are a few ways to solve this. I chose the easy way out for this example. If we go back to the “Trigger” you’ll notice there are some options below our custom trigger that allow us to “Hide.”

We have an option to “Hide” the WeakAura based on a Time or even some more custom code. I went with the “Time” option, because its the simplest. After selecting the “Time” option you will notice a “Duration (s)” text field appear. This is just a way of telling your WeakAura, “Hey, WeakAura. After N seconds of this showing up, I want you to remove it.”

We don’t want the WeakAura on our screen at all, so I put a value of 0.01 in this field. This means that when this WeakAura shows itself, .01 seconds later, it will simply hide itself again. Here is what my trigger looks like now:

Seeing the WeakAura in action

We should now have a working WeakAura! If you close down your WeakAura addon, mount up, and talk to the flight master … you should automatically get dismounted and then the Weak Aura will hide itself and wait for the next time it needs to show itself. Here is how it looks for me.

Conclusion

This post will hopefully help some folks ease into WeakAuras. I’m planning to add another post that talks about some of the more complex functions of the WoW API. As well as some of the esoteric parts of WeakAuras. Hopefully some of you find some value in these posts. If you have any suggestions on this post or would like me to cover any other specifics of programming in World of Warcraft, please feel free to hit me up on Discord @ virtual#8494.