Thursday, September 24, 2009

Hello World! - Your First AddOn

It's no secret that I'm a UI nut. I redesign my UI constantly, trying out new mods that will help me react faster, make the UI look more streamlined or just reduce the lag my UI imposes on my computer. One thing that may not be as well known is that I run my own personal AddOn that isn't published on it's own anywhere to help accomplish many trivial things that I don't want to download a bloated AddOn to do.

This AddOn is called OobieUtil and it does everything for me from automatically repairing my gear to rewriting my bandage macro to use the highest bandage available and automatically accepting invites from the guild leader during raid times.

OobieUtil does next to nothing graphically speaking, but it keeps my UI running smoothly - like engine oil as it were. I code into this mod many repetitive or convoluted procedures that clutter up the UI, distract me from the game or just plain annoy me.

To me, OobieUtil is as indispensable as DeadlyBossMods or a good action bar AddOn - I can't imagine playing without it. With a little inscturction anybody can accomplish much of what I do in my utility AddOn, it just takes a bit of copy/paste action and the right resources.

In this first tutorial I'll go over the basics of what you need for an AddOn... the basic infrastructure that you'll need to start coding modifications into your UI to streamline it. Here are some examples of things I do with this utility:

  • Provides notifications when my character is running low on ammunition i.e. Hunter ammo pouch or Warlock soul bag is below a certain percent full.
  • Rewrites a bandage macro to use the highest available bandage. All characters share the same macro and it's automatically rewritten on character changes and inventory updates.
  • Rewrites an assist macro via a slash command - more advanced version scans a party and automatically find the tank and rewrites the macro.
  • Automatically watches a faction you've recently gained reputation with.
  • Automatically repairs gear at a vendor using guild funds if the option is available.
  • Rewrites a macro that will equip a lance or the weapon equipped at the time the lance was picked up. Knows which lance you picked up and adjusts the macro accordingly.
My current iteration of the utility does more than the above, but these are examples of some repetitive tasks that can be accomplished with just a little knowledge. And without further adieu here is a step by step guide to creating your first AddOn...

Note: This tutorial is for Windows PCs, though AddOns for Mac follow the same format some specific instructions in terms of how you interact with your OS may not translate properly.


If you already know a bit about programming chances are that you've made a "Hello World" program before. It's generally the first program written when learning a new language - but don't let that intimidate you. There are a small handful of programming techniques that will help accomplishing certain tasks in an AddOn but for the most part the WoW API is very user friendly and a great deal of things can be accomplished without advanced programming techniques.

For this tutorial, however, I won't be talking about any techniques, just the framework needed for an AddOn.

The first step is to create a folder for your AddOn. Whatever name you use for the folder will be the name of the AddOn, but for this tutorial we'll stick with 'HelloWorld'.

Next you'll want to open Notepad or another text editor of your choice. Stay away from Office products when editing AddOn files, though. They tend to add unnecessary formatting tags that could cause your AddOn to not work properly. My own personal favorite is Notepad++.

Type or copy/paste the following into your text editor of choice:
## Interface: 30200
## Title: HelloWorld

Once you have this much typed in save the file with the name 'HelloWorld.toc' inside the folder we made earlier. Before you save make sure to change drop down menu below the file name box to say 'All Files' otherwise you may end up accidentally saving the file with an extra file extension, which WoW will not know what to do with.

Next, open a new text file and type in the following:
print("Hello World!")
Once that's done save the file in the same folder with the name 'HelloWorld.lua'.

That's it! Make sure the AddOn folder is nestled into your AddOns directory along with the other mods you use and log in to the game, the end result is that the words in quotes are printed to the chat window. Generally this is a technique used when a mod author wants to post a message to chat that the AddOn has been loaded.

For the AddOn to do anything really meaningful in the game world you need to get into registering and handling events but that, dear reader, is for another tutorial.

No comments:

Post a Comment