how to write a new wow classic addon from beginning

  • classic api is base on V 8.1.0 ,

it full reference is here :

The Classic API is based on the 8.1.0 api but then half stripped down. The changes are available here, including for widgets, events, CVars and enums.





正文部分 :

WoW Addon Writing Guide Part One: How to make your first addon
By GalacticGlum Last updated 2019/05/09 at 3:10 PM View Changelog

WoW Addon Writing Guide Part 1 5.4.2+ : How to make your fist Addon
I make gaming videos and make coding tutorials on my YouTube channel! I’m also going to be making a video version of this guide very soon! My YouTube channel is
In This Guide you will learn how to write a basic “Hello World” addon and a Basic “Level Up” Congratulation addon in the Programming Language LUA at the end of this guide you should have a completely working addon and basic understanding of what you need to write an addon and what you need to know
*If you want to download a Sample version of this addon for the source code there is a link at the bottom of the guide*
What you will need:
1. Notepad ++ (This is a Free code editor) ** There are different programs like Eclipse IDE, but for this tutorial we will be using Notepad ++ **
2. Basic Computer Knowledge (Just Basic Computer Skills, You need to know how to operate a Computer *you managed to get to this guide so you are good to go*)
3. A WoW Account (For testing purposes)
Tips Before we start:
Remember this guide is for people who don’t know Programming

After this guide you might want to go read and watch some basic LUA tutorials and guides
*There will be links for LUA tutorials at the bottom of the guide*

Remember this can be used on different versions you just need to do a couple different stuff which I explain in the guide
Setting Up
So first and for most you are going to want to download Notepad ++ and install it.
You are also going to want to get the current Interface number. There are numerous of ways of doing this.
Here are a couple of ways.The Best Way is to go on WoW and run this script
/run print((select(4, GetBuildInfo())));
**Thank you Funda for telling me about this script**

You could also steal the Interface number from an updated WoW addon in the TOC File but a simpler way would
be to just Google it (EX. Wow 5.4.2 Interface number) and you should find the Interface number one way or another. The version 5.4.2 Interface number is 50400 but this changes from a version to version. After you obtain the interface number and install Notepad ++ you are going to want to locate your WoW installation folder it is either in C:\Program Files or C:\Program Files (X86) and then go to your Interface Folder inside the WoW installation folder and then into your addon folder inside the interface folder. Inside the addon folder you are going to make a new folder called “HelloWorld” this folder will store all of your addon files so before making the folder make sure you are in this file path:

C:\Program Files\World of Warcraft\_retail_\Interface\Addon\

That is the file path you should have now this is how it should look at the top after you make the
HelloWorld Folder:

C:\Program Files\World of Warcraft\_retail_\Interface\Addon\HelloWorld
Writing Our .TOC File (Table of Contents File)
The TOC File is the first file WoW goes to look to find info about your addon so it is very important to not mess the TOC file up.
The first thing you are going to want to do is to create a new text document and name it HelloWorld you are then going to open it in regular notepad and save it as HelloWorld.toc and save it as all file types. You are now going to see a text document and a .toc file in your folder delete the HelloWorld text document but keep your HelloWorld.toc file. Now open the HelloWorld.toc file in Notepad ++ and paste this code:

## Interface: (Your Interface number)
## Title: (Name of your Addon)
## Author: (Your name here)
## Version: (Version of your Addon)
Copy that and change it to your info
This is how my TOC would look like:

## Interface: 50400
## Title: Hello World
## Author: Shon Verch
## Version: 0.1
Click file in the top left hand side of the Notepad ++ tool-bar and click save
Call this file HelloWorld and if it asks you to overwrite HelloWorld.toc file say yes.
Writing the “HelloWorld” Script
Of course we need to write a script because you can’t make a addon do something before you tell it to do something. So you are going to make a new text document called “main” and open it in Notepad ++ you are then going to paste or type this code:

Of course you can make this message bigger for example:

message(‘Hi how are you I am good what up’)
But for the sake of this tutorial we are just going to write in the message HelloWorld
After you write in the code you are going to click file in the left hand side of the tool-bar and click save as
You are going to save it as a LUA file so just name it main.lua and it should automatically recognize the .LUA extension.
Now go to your .toc file and type in the main.lua file under your .toc it should look like this:

## Interface: 50400
## Title: Hello World
## Author: Shon Verch
## Version: 0.1

The reason you need to put the name of the file there is because WoW needs to know what files to run everytime you run the addon
Now open up your WoW and enable the addon to enable addons on your character selection screen in the bottom left hand side of your screen there should be a button that says addon on it. Click on that and you should see HelloWorld on the list if you have no other addons except the addon you just made press enable all at the bottom the window on the addon screen. If you have more addon just go to the HelloWorld Addon and tick the check-box beside the addon name your addon name should be in yellow if it is in red then that means it is outdated and your interface number is not the correct one for the version.
This is how the addon window looks like:

That is how the addon window should look like.
Now select a character and when you log on you should have a box that says HelloWorld like this:

Hooray it worked
Now you made your first addon but we are not done yet!
A Little More Advanced
Now that we made our first addon the Hello world addon its time to add a Level up Congratulatory feature that congratulates you every time you level up
First make a new text document called “lvup” open this file in Notepad ++ and first insert this line of code:

local Congrats_EventFrame = CreateFrame(“Frame”)
What this code is doing is creating a frame it is also using a local variable versus a bigger variable so it does not interfere with other WoW codes. Next up you are going to want to insert this line of code:

What this is doing is registering the event that when you level up something happens
So far your new .LUA file should look like this

local Congrats_EventFrame = CreateFrame(“Frame”)
Now we are going to set the script for the level up congratulation system. To set the script you insert this code:

This is setting the script for the text message it displays when you level up now we are going to make a function to recognize we levelled up to do this insert this code:

function(self, event, …)
Your .LUA file should look like this:

local Congrats_EventFrame = CreateFrame(“Frame”)
function(self, event, …)
Now we are going to use the local variable again we are also going to makeing the level up recognizer that the Addon will run to check if you levelled up just insert this code:

local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 = …
Your code should look like this now:

local Congrats_EventFrame = CreateFrame(“Frame”)
function(self, event, …)
local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 = …
Now we are going to actually right what the message is and who to display to insert this code:

print(Congratulations on reaching level ‘ ..arg1.. ‘, ‘ .. UnitName(“Player”).. ‘! You gained ‘ ..arg2.. ‘ HP and ‘ ..arg3.. ‘ MP!’)
Write a customized message so when you level up you know that the addon worked. Write something WoW Automatically would never say.

your code should now look like this:

local Congrats_EventFrame = CreateFrame(“Frame”)
function(self, event, …)
local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 = …
print(Congratulations on reaching level ‘ ..arg1.. ‘, ‘ .. UnitName(“Player”).. ‘! You gained ‘ ..arg2.. ‘ HP and ‘ ..arg3.. ‘ MP!’)
now go to file and click save as and save it as:


Notepad ++ will automatically make it a .lua file if you add the .lua at the end of your name
go back to your .toc file and add lvup.lua to your .toc it should look like this:

## Interface: 50400
## Title: Hello World
## Author: Shon Verch
## Version: 0.1

your .toc file should look like this but with your name and version and all that.
In this guide I taught you how to make a simple addon that Congratulates you when you level up and that says HelloWorld when you log in if you want to disable the HelloWorld popup every time you log in then go to your .toc file and erase main.lua it should look like this:

## Interface: 50400
## Title: Hello World
## Author: Shon Verch
## Version: 0.1

Thank you for reading and hope you can make a new revolutionary addon
LUA Guide and Video Links:

There are more just search it up on Google
Addon Source Code Download Link
Extra Stuff
Have Fun Coding 😀

Guide by WoWlover123

I wrote this guide when I was 12, I am now 14 as of 4/14/2015

I’m currently working on a 2D ORPG called The Five Heroes and I would love for you guys to support me.
Also check out this video tutorial I made teaching you how to program in VB.NET

Official game website:
Official game forums:



  • api 函数大全


  • 能不能从macro 调用 scripts  ,  或者从 lua script 调用 python  function

因为 script 不允许 condition cast , 因为这会让 blizzard觉得是 AI make decision ,  如果允许, 就会衍生出各种 onekey addon , 最终就是 bot ,

例如 vanilla 版本的  AutoRogue


但是 这样是允许的:

但是如果把 SendChatMessage  改为 cast X   就不行

如何绕过这一点 ?  python有一个库是发送 模拟键盘消息的, 如果能从 lua script 调用 ,并实现按下一个按键 ,  是否就可是实现 cast


  • simple code

Registers which events the object would like to monitor.

success = frame:RegisterEvent(“event”)
string – The name of the event to register the object as monitoring.
boolean – Returns true if the event was successfully registered, false if (already) registered.
The snippet below creates a frame, registers it for the CHAT_MSG_YELL event, and sets an OnEvent handler that would print a message whenever that event fires — whenever you hear someone /yell.

关于 frame register event 的更详细解释

→ API events
← Event API
Events are messages sent by the WoW client to UI code (OnEvent script handlers of Frame derivatives), mostly in reaction to things occurring in the game world. To process events, an addon needs to create an event handler and register it for the events it wishes to receive.

Setting up an event handler Edit
Events are sent to Frame-derived widgets; an add-on needs to create a frame if it does not already own one that can be used for the purpose of handling events. Frames may be created in Lua using the CreateFrame function; or constructed in XML (using the <Frame> tag).

Once a frame has been created, its OnEvent handler must be set to a function that would handle the event on behalf of the addon. The OnEvent script handler may be set using the Lua frame:SetScript() function; or constructed in XML (using <Scripts><OnEvent>function body</OnEvent></Scripts>). The OnEvent handler function receives at least two arguments:

self, a reference to the frame to which the script handler belongs1
event, the name of the event being fired
The remaining event arguments are placed within the vararg exp/ression (…), as well as in the arg1-arg9 variables (the latter mechanic is deprecated and will be removed in Cataclysm[1]). You can extract variables from the vararg expression by simply assigning it to your local variables: local arg1, arg2, arg3 = …;
The addon’s OnEvent script handler function should either handle the event, or call another addon function to handle the event.

In order to receive event notifications, the event handler frame needs to be registered for events the addon needs to handle; use frame:RegisterEvent(“eventName”) to achieve this. The RegisterEvent function can be called at any time after the frame’s creation; the OnLoad script handler is a convenient location to register for the desired events when using XML.

If you no longer wish to receive event notifications for a particular event, use the frame:UnregisterEvent() function. If you wish to disable all event notifications currently delivered to a frame, use the frame:UnregisterAllEvents().

Examples Edit
Hello WorldEdit
The two implementations below are functionally identical: they print “Hello World! Hello PLAYER_ENTERING_WORLD” to the default chat frame when the character zones into the world. Note that the event variable is implicit in the XML OnEvent handler: it is supplied by the OnEvent closure signature.

Using XML

<Frame name=”FooAddonFrame”>
<OnLoad> self:RegisterEvent(“PLAYER_ENTERING_WORLD”); </OnLoad>
<OnEvent> print(“Hello World! Hello ” .. event); </OnEvent>
Using Lua

local frame = CreateFrame(“FRAME”, “FooAddonFrame”);
local function eventHandler(self, event, …)
print(“Hello World! Hello ” .. event);
frame:SetScript(“OnEvent”, eventHandler);
XML-Specific Edit
You may bind an already declared Lua function to the OnEvent handler in XML directly, rather than creating another function by providing a function body within the <OnEvent></OnEvent> tags. Doing so will save you memory:


function FooHandler_OnEvent(self, event, …)
— insert event handling code here

<Script file=”FooAddon.lua”/>
<Frame name=”FooHandler”>
<OnEvent function=”FooHandler_OnEvent”/>
Lua-specific Edit
If your frame registers a large number of events, you could reduce the required number of if clauses, and generally simplify your design by doing:

local frame, events = CreateFrame(“Frame”), {};
function events:PLAYER_ENTERING_WORLD(…)
function events:PLAYER_LEAVING_WORLD(…)
frame:SetScript(“OnEvent”, function(self, event, …)
events[event](self, …); — call one of the functions above
for k, v in pairs(events) do
frame:RegisterEvent(k); — Register all events for which handlers have been defined
Note that in the case of the events:XXX functions above, the variable self, implicitly defined by using the function table:functionName notation, will point to the frame handling the event rather than the events table.

The vararg expression Edit
The vararg expression (…) may contain additional arguments supplied by the event. Arguments contained in … can be read by simply assigning them to other variables, possibly using the select function to skip forward to a specific argument in the list.

Consider the example of handling COMBAT_LOG_EVENT:

function eventHandler(self, event, …)
if event == “COMBAT_LOG_EVENT” then
local timestamp, combatEvent, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags =
…; — Those arguments appear for all combat event variants.
local eventPrefix, eventSuffix = combatEvent:match(“^(.-)_?([^_]*)$”);
if eventSuffix == “DAMAGE” then
— Something dealt damage. The last 9 arguments in … describe how it was dealt.
— To extract those, we can use the select function:
local amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing =
select(select(“#”, …)-8, …); — select(“#”, …) returns number of arguments in the vararg expression
— Do something with the damage details …
if eventPrefix == “RANGE” or eventPrefix:match(“^SPELL”) then
— The first three arguments after destFlags in … describe the spell or ability dealing damage.
— Extract this data using select as well:
local spellId, spellName, spellSchool = select(9, …); — Everything from 9th argument in … onward
— Do something with the spell details …
Notes Edit
The global this, event, and argX variables are being removed in Cataclysm[1]. Instead, use the arguments passed to the OnEvent script handler.
Relevant API Edit
CreateFrame(“widgetType”[, “name”[, parent[, “inherits”]]])
frame:SetScript(“handlerType”, func)
frame:HookScript(“handlerType”, func)
frame:RegisterEvent(“eventName”) (and possibly frame:RegisterAllEvents() )
frame:UnregisterEvent(“eventName”) (and possibly frame:UnregisterAllEvents() )
Events (API), a listing of events you may subscribe to.
References Edit
^ a b Preparing for Cataclysm
Event APIAdd category
Community content is available under CC-BY-SA unless otherwise noted.