HowTo: create an AddOn

SwampFae

Super Moderator
Staff member
How Do I Create WoW AddOns?

Creating AddOns isn't for the faint at heart as it involves a whole lot of programming but if you have a basic idea of how to write programs you will probably be able to create AddOns fairly well.

One of the awesome things that Blizzard has done for WoW is to let people create AddOns that enhance the gameplay. They have also released the "World of Warcraft Interface AddOn Kit" which has many nice tools in order to help you out in the process.

I'm not going to go in a huge amount of detail about what it takes to make an AddOn but give you more of a getting started guide that will lead you to a basic understanding of how you can create AddOns.

Here's the most important basic structure of every WoW AddOn.

There are 3 basic types of files you will run across when you look at any AddOn:

.lua files, which contain the program code that explains the nuts and bolts of what everything does in your AddOn.

.toc files, which is the Table of Contents for your AddOn. Just like a table of contents in a book it helps identify your AddOn and tells where and what order the AddOn files should be loaded.

.xml files, which describes the look and feel for your AddOn.

If you compare it to a car, the XML file would be the outside cosmetics of the car (paint job, shape, etc.). The LUA files would be the mechanical part of the car (engine, transmission, etc.) and the TOC file would be, for lack of a better comparison right now, the manual for the car. Hopefully that helps you visualize it a little bit better.

That's the very basics of it but a nice little start. Here are a ton more resources that will come in handy if you like programming and become serious about creating AddOns of your own.

Source: Ask Apadwe

Example:
  1. Step 1: Create a directory in your AddOns folder and name it "HelloWorld".
  2. Step 2: Create three files in your new directory: HelloWorld.toc, HelloWorld.xml, HelloWorld.lua.
  3. Step 3: Write your AddOn!

Creation:
Step 1: HelloWorld.toc
Right. So let's get started.
The .toc file. Open it with notepad.
The .toc file is basically the file that informs WoW about what files there will be in your mod.

Put this into your .toc file:

## Interface: 20000
## Title: Hello World
## Notes: Learning is fun!
## Dependencies:
HelloWorld.lua
HelloWorld.xml


Now save the file and close it.
Step2: HelloWorld.xml
Open the HelloWorld.xml file in Notepad

Put this into your xml file:

<Ui xmlns="http://www.blizzard.com/wow/ui/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\..\FrameXML\UI.xsd">

</Ui>


The first part here is a basic definition of the UI, the specification it's based off of, and where the UI definitions file lives in the game directory. Since there's nothing here, nothing would happen if you loaded the game. In order to make something happen, we need to insert the following into the XML file between the <Ui> and </Ui>:

Please remember that each XML file typically describes one element of UI on the screen.

Ready to move on?
Here it comes.
Enter this into your xml file:

<Frame name="HelloWorldFrame">
<Scripts>
<OnLoad>
HelloWorld();
</OnLoad>
</Scripts>
</Frame>


THis will open a frame in your UI called: Hello World.
When the frame loads, the <OnLoad> element instructs the client to perform the HelloWorld() function. So our next step is to actually write that function.

So. Now the .xml file is done
Save the file and close it.

Step3: HelloWorld.lua
Right. Now it is time for the final part of your mod.
The .lua file
Open it in notepad.
Now. Put the next part into your .lua file.

function HelloWorld()
message("Hello World!");
end


The code above demonstrates the simple format of a Lua function. Note that the function is defined and then named, and is concluded with an "end" after all of the instructions. Also notice we use the message() function. This is a buildt in function that shows a message on the screen in a pre-defined pop-up box.

Now. Save the file and close it.
Congratulations! You have now created an AddOn for World of Warcraft!

Step4: Using the mod.
Start your World of Warcraft client and look at your AddOns list.
Locate a mod(AddOn) called HelloWorld. Make sure that it is active.
Log onto any character to see your message!

Rescources:
Learn more about XML at: http://www.xml.com/
Learn more about LUA at: http://www.lua.org/manual/5.0/
 
Top