此站点大量使用JavaScript。
请在您的浏览器中启用JavaScript。
正式服
PTR
10.2.7
PTR
10.2.6
Beta
Addon Writing Guide: A basic introduction by example
来自 GalacticGlum
[Last Updated]:
2021/02/13
变更日志
补丁:8.2.5
目录
评分:
World of Warcraft Addon Writing Guide: A basic introduction by example
Foreword
This guide has had a tumultous history. I wrote it when I was in wee kid in elementary school---it is only now that I have taken an interest in updating and revising it. This new version of the guide is completely rewritten and is updated for the latest version of World of Warcraft.
1. Introduction
World of Wacraft allows you to extend the functionality of the client through a collection of Lua scripts known as addons. WoW's addon scripting API provides a flexible system for extension through both functionality and interface. This guide will go through the very basics of developing an addon.
A basic understanding of programming/scripting (in any language) is recommend. If you have not used Lua before, refer to the Lua beginner guide before beginning thhis tutorial.
All source code for this guide is available on
GitHub
.
1.1. Prerequisites Tools
A text editor (I recommend
Visual Studio Code
paired with the
Lua extension
)
A World of Wacraft account (for testing purposes).
A beginner knowledge of programming and/or scripting.
1.2. Background
By no means will this guide teach you how to develop a production-ready addon; rather, it simply aims to get you in the right direction. Developing an addon requires a far broader understanding of the World of Warcraft scripting API (refer to the
documentation
).
1.3. Setting Up
Before we can start building our addon, we need some important information for our addon's metadata. Chiefly, we are going to need the current
interface number
which specifies the World of Warcraft version for which the addon is intended to run on. The best way to get the interface number is to run the following command in the chat window of the game:
/run print((select(4, GetBuildInfo())));
With the interface number obtained, we know want to setup the folder structure of our addon. Navigate to the installation folder of your World of Warcraft client and then locate the
"_retail_\Interface\Addons"
subdirectories. Inside this folder, create a new directory with the name of
"HelloWorld"
; this will contain the source code of your first addon.
C:\Program Files\World of Warcraft\_retail_\Interface\Addons\
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\Addons\HelloWorld
2. Writing our first addon
This chapter will go through writing our first addon.
2.1. The Addon Table of Contents File
The table of contents (TOC) file specifies the addon's metadata information. In particular, it contains a list of all the Lua scripts that should be executed. As a result, without the TOC file, an addon is essentially just a collection of source code that is relatively useless. It is the TOC file which empowers the client to run your addon.
Along with listing out the scripts that should be executed, the TOC file aslo contains other information like the name of your addon and version.
In your newly created addon directory (i.e.
"\_retail_\Interface\Addons\HelloWorld"
), create a new file called
"HelloWorld.toc"
and populate it with the following information:
## Interface: (Your interface number)
## Title: (Your addon name)
## Author: (Your name)
## Version: (Your addon version)
For example, this is a sample TOC file:
## Interface: 80200
## Title: Epic Addon!
## Author: John Doe
## Version: 1.0
2.2 Enabling your addon
An addon must be enabled in the addon manager interface for it to execute. By the same token, you can disable specific addons in the same interface.
To access the addon manager, open your World of Wacraft client and on the bottom left hand side of the screen, click on the
AddOns
button.
Locate the name of your addon and make sure that it is enabled. If the name of an addon is displayed in red, it means that the addon is outdated (i.e. the interface number is outdated).
2.3 The Lua script
At this point, we have a fully functional addon; however, it doesn't do anything because we haven't specified any scripts to run in your TOC file. In this section, we will fix this by writing a script to display a message whenever we login to the game.
In your addon directory, create a new file called
"main.lua"
and open it in your text editor of choice. In the file, paste the following code and save:
message('My first addon!')
The
message
function is analgous to the standard output functions in other programming languages (i.e. the
print
function in Python or the
System.println
method in Java). However, there is a key difference in that the
message
function will display a message box in the game rather than printing to the console.
If we try running World of Warcraft now, we will notice that nothing happens. Indeed, our addon is working correctly.
Remember, our TOC file is what specifies that scripts that should be executed.
Since we haven't added
main.lua
to our TOC file, the script won't run. We can fix this by appending
main.lua
to the TOC file. Ensure that it is on a new line:
## Interface: 80200
## Title: Epic Addon!
## Author: John Doe
## Version: 1.0
main.lua
Running the game now, we should see a message box popup with our message:
[Get Wowhead]
高级会员
[$2]
[A Month]
[Enjoy an ad-free experience, unlock premium features, & support the site!]
评论
评论来自
GalacticGlum
Hey Guys its Clozo if you have any suggestions on a Guide I Should write just leave a comment below
评论来自
Aqonomic
Nice guide! Maybe you could write some sort of 'part two' where you would explain more advance stuff like methods and conditionals etc.
8,5/10 - try formatting it, adding a ToC and subcategories.
edit: I also found some grammar mistakes, please look through those to make it look more professional :)
-Aqonomic
评论来自
GalacticGlum
So I just updated the Guide to look and feel better remember if you have any suggestions on a Guide I Should write just leave a comment below
评论来自
Nhome
This guide is really helpful!
Thanks!
评论来自
joker102877
I was able to get the HelloWorld message to work in game, but the congrats script didn't work. First I typed it all out myself, finding it didn't work, I copied and pasted your code from the guide and it still didn't work. Then I downloaded the source code from the link you provdided above, and still no dice.
The addons are placed in the Interface>Addons directory of the game, and the TOC is built correctly and defining the necessary lua files.
评论来自
Tisina
He mate, nice guide. Has a good overview and basic explanation.
I would advice to use sooner dots to close your sentences and make them shorter. To create more suggestion of rest in yr text.
If not possible to use a dot, at least try to use a comma instead of connecting the pieces of one sentence by 'and'.
Some long sentences are hard to grasp the first time, because there are no 'natural breaks or resting points' in those sentences.
Looking forward to yr part 2.
评论来自
440767
Awesome guide clozo. I have a addon idea and just wanted your thoughts. Is it possible to make a addon that when I make the appearance of my ui the smallest possible except for the map in the top right corner being a different size(possibly the largest it can be displayed).
评论来自
Funda
Just a few friendly suggestions...
You are missing an opening quote on this print line:
print(Congratulations on reaching level ' ..arg1.. ', ' .. UnitName("Player").. '! You gained ' ..arg2.. ' HP and ' ..arg3.. ' MP!')
The best way to get the latest official interface number is to use the pre-existing GetBuildInfo() method in game by running the following script:
/run print((select(4, GetBuildInfo())));
Always remember this: No matter what anybody tells you, spelling and grammar count in the long run!
It is often considered good manners to cite your sources:
http://www.dev-hq.net/posts/2--create-world-of-warcraft-addon
I enjoyed the guide and it got the ball rolling for me to do my own research into writing an AddOn since I am a software developer, but new to LUA. For those who enjoy a more structured IDE, I'd suggest Eclipse (
http://www.eclipse.org
) with the LUA Development Tools plug-in from the Eclipse Marketplace as it will keep your project and code organized for you.
There's lots of good additional information at the following URLs:
LUA:
http://www.phailed.me/2011/02/learn-lua-the-hard-way-1/
WoW LUA:
http://www.wowwiki.com/Portal:Interface_customization
http://wowprogramming.com/
http://www.mmo-champion.com/threads/817817-Creating-Your-Own-WoW-Addon
http://www.codeproject.com/Articles/284961/A-Simple-World-of-Warcraft-Addon-using-Lua
If you know anymore, add them below!
Good work and keep them coming. +1
评论来自
GalacticGlum
Hello all, It's Clozo!
So I've been scrambling to find time to write a part two to this guide. Well don't worry because a part two is currently in the works! Right now though I am a couple of days away from releasing a Newbies Guide to World of Warcraft after the guide is released I'm going to take a one week break to play Warlords of Draenor and then I'll be off to continuing with my part two.
On New Years Eve December 31st I'm going to post a comment here explaining what the topic of the part two is. So stay tuned! I hope to get the part two finished around January 8th to 10th and I hope to get it released around January 15th or sonner.
Remember to submit your feedback in the comments section because feedback helps! Also remember to rate this guide via the star rating system.
Happy Holidays from Clozo,
Sincerely,
Clozo the WoWLover123
评论来自
GalacticGlum
Hello all, It's Clozo!
Once again I'm back the topic of the part two is "Creating a GUI and Addon Ideas!".
Happy New Years. Have a Great 2015,
Sincerely,
Clozo the WoWLover123
评论来自
GalacticGlum
20K!
We hit 20k!
评论来自
Akigar
It's not working for me :(
Did exactly as you said and it says ''Incompatible''
评论来自
Tanthok
I was wanting to know what languages can be used in making a program. I would also like to know if Matlab could be used to make and addon?
评论来自
jspiresinc
So when your writing the code in your interface add-on folder will note pad++ recognize wow API calls that are made
评论来自
Gothy
So does this all apply to patch 8.1+ ? I'm debating learning to code better and help maintain some open source addons.
评论来自
altieri43
I’d love to see an update to this. Really want to learn about coding for wow
评论来自
blackjack543
I wasn't able to find an answer for my question. Is there an addon that alerts you to when you hover over an object that doesn't have an interact icon? (gear icon that appears when hovering doesn't show but the magnifying glass, the chat bubble) If not, is this possible to make?
评论来自
Frostybolts
Hey, this was a big help for me just now. You should update it and flesh it out again
I also got a lot out of the API docs on wow.gamepedia (converted it into a non-link so I won't get spam filtered) wow gamepedia com World_of_Warcraft_API
Using the TinyPad addon was a huge help to test stuff out. Big warning, though, I ran into some INSANE errors when trying to use the C_AuctionHouse APIs from TinyPad. Somehow, any structures I allocated in TinyPad code would get my character blacklisted by Blizzard's server when I tried to use them to access the API, but the same exact code worked perfectly when I put it into an app.
Here's some basic game XML for a window with a button:
评论来自
SpaceBarBob
Someone out there has a spare minute or two to post a super basic "when in combat, hide minimap" addon. I have cookies .....
贡献
在发表评论前,请留心以下提示:
您的评论必须为简体中文,否则将会被删除。
不知道如何发评论?参考我们的
格式指南
!
发表前最好先自行校对一次。
有问题可以访问我们的
论坛
来寻求帮助。
发表评论
你没有登录。
请登录
或者
注册账号
来添加你的评论。
使用下面的表格浏览您的截屏。
[Screenshots containing UI elements are generally declined on sight, the same goes for screenshots from the modelviewer or character selection screen.]
质量越高越好!
[Please review our
Screenshot Guidelines
before submitting!]
您没有登录。请
登录
后提交截屏。
将视频URL输入下列表格即可。
URL:
支持:仅限 YouTube
说明:您的视频需通过审核才能在站点上显示。
我们用
Wowhead 客户端
保证数据库的及时更新,向您提供额外的有趣的功能!
两大目的:
它还维护WoW的一个插件
Wowhead Looter
, 在您游戏时采集数据!
它将
采集所得数据
上传至Wowhead,保证数据库时刻掌握最新信息!
您可以用它追踪完成的任务、配方、坐骑、伙伴宠物以及头衔!
您还在等什么?立即
下载客户端
整装待发吧。
我们用 Wowhead 客户端保证数据库的及时更新,向您提供额外的有趣的功能!
两大目的:
您可以用它追踪完成的任务、配方、坐骑、伙伴宠物以及头衔!
您还在等什么?立即 下载客户端 整装待发吧。