Coding My First WoW Addon

5 minute read

So you wanna make your own WoW addon? Let’s walk through the most basic steps to get you started!

During my infinite Twitch browsing I recently came across lelandkwong’s channel where he is developing a game in Lua. Being a long-time (since vanilla) WoW player, I had never thought of Lua being used for anything other than writing addons. So what did I decide to do, learn some Lua and make a WoW addon of course. I immediately knew what I wanted to make since I have been raiding as a Mage and I am always getting nagged for my Arcane Intellect buff. Now on to the fun stuff!

The first thing you need to do is come up with a name for your addon. I felt the only obvious choice for mine was Intellect 4 Dummies. Once you have a name you will want to create a folder under World of Warcraft\Interface\AddOns with the name you have dreamed up. Inside this folder you will need to start by creating a TOC file of the same name, for example: \AddOns\Intellect4Dummies\Intellect4Dummies.toc.

Let’s go ahead and edit our TOC file to include some important information about our addon. The first thing we will need is the interface number which represents the current version of the WoW client. One of the most reliable ways to do this is to launch the game, log in as any character, and execute the following script from your chat window. You could also grab it from the TOC file of any other up-to-date addon.

/dump select(4, GetBuildInfo())

chatInterfaceScript

The interface number should be updated with each release of the WoW client, otherwise your addon will be marked as out-of-date and may not be automatically loaded. Along with the interface number we will want to specify the title of our addon that should show up in the interface, a short description, the version number, and our author name. Finally, will we want to finish with the name\relative path of any code files that we will need to include. In my case I am using a single file named main.lua in the top level of my addon folder that will contain all of my Lua code. Here is an example of what your TOC file should look like when you are done:

## Interface: 80000
## Title: Intellect 4 Dummies
## Notes: Reminds you to cast Intellect if you are a dummy
## Version: 1.0
## Author: MStewGT

main.lua

After our TOC file is complete we can start on our Lua code that will be the meat of our actual addon functionality. If you are just getting started with Lua, you can find the language reference page here. We will also be making use of the WoW API so you will want to keep a reference for it handy as well. A couple great options for this are the WoW Programming website and WoWWiki. Using these resources you will be able to easily look up all of the API functions and events you will need to help you code your addon.

To break down the actual code process for something simple like my buff check addon, you will want to start by defining some variables, creating a function(s) to handle whatever process you want to implement, and finally an event handler to kick off your process. I’m including an excerpt of my code below as an example but you can find the full source for Intellect 4 Dummies on GitHub.

-- Returns a list of members in the player's party or raid and assigns to a variable
local raidMembers = {};
local partyMembers = {};
do...
end

-- Loop through raidMembers and check Arcane Intellect buff/aura
function CheckBuffsGroup()...
end

-- Event handler
local frame = CreateFrame("FRAME", "I4DFrame")
frame:RegisterEvent("READY_CHECK")  -- Listens for a Ready Check
local function eventHandler(self, event, ...)
  CheckBuffsGroup()  -- Runs buff check on event
end
frame:SetScript("OnEvent", eventHandler)

That pretty much sums up the bare minimum of what you will need to get started. The WoW API can be pretty confusing at first so the easiest way to get started will often be to look at other addons for examples of how they are handling different functions. If you do a little digging there are also some great YouTube video series as well as some print books to help jump start your project.

Bonus tip: if you clone a GitHub repository locally as your actual addon folder you can get version control for all your changes and not have to do anything extra to test your changes when you load up the WoW client.

Leave a comment