Beginning Lua with World of Warcraft Addons

Book description

If you play World of Warcraft, chances are you know what Deadly Boss Mods is: it's the most widely downloaded modification available for World of Warcraft, considered required software for many professional raid guilds, and arguably the most popular modern video game mod in history.

Paul Emmerich, the author of Deadly Boss Mods, will take you from novice to elite with his approachable, up-to-date guide to building add-ons for the most popular video game in history. Using the powerful Lua scripting language and XML, you'll learn how to build and update powerful mods that can fundamentally remake your World of Warcraft experience and introduce you to the field of professional software development.

Beginning Lua with World of Warcraft Add-ons teaches you the essentials of Lua and XML using exciting code examples that you can run and apply immediately. You'll gain competence in Lua specifics like tables and metatables and the imperative nature of Lua as a scripting language. More advanced techniques like file persistence, error handling, and script debugging are made clear as you learn everything within the familiar, exciting context of making tools that work in Azeroth.

You'll not only learn all about the World of Warcraft application programming interface and programming, and gain coding skills that will make all your online friends think you're a coding god, but also gain hands-on Lua scripting experience that could translate into an exciting job in the video game industry!

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. Acknowledgments
  9. Introduction
  10. CHAPTER 1: Getting Started
    1. What Is Lua?
    2. What Are WoW Addons?
    3. Useful Programs, Tools, and Web Sites
      1. Web Sites
      2. In-Game Tools
      3. Programs
      4. IDEs
  11. CHAPTER 2: Lua Basics
    1. Using Lua
    2. Basics
    3. Variables and Data Types
      1. Data Types
      2. Dynamic Typing
    4. Expressions
      1. Arithmetic Operators
      2. Relational Operators
      3. Logical Operations
      4. Precedence
      5. Tables and Functions as Expressions
    5. Statements
      1. Function Calls
      2. Control Structures
      3. break
      4. return
      5. Assignments
    6. Local Variables
    7. Variable Arguments
    8. Lua Standard Libraries
      1. The Math Library
      2. String Library Basics
      3. The Table Library
      4. The Debug Library
      5. The Operating System Library
    9. Summary
  12. CHAPTER 3: Using the WoW API to Create a “Hello, World” Mod
    1. Running a “Hello, World” in WoW
    2. Our First WoW Addon
      1. Folder Structure
      2. The TOC File Format
      3. Using the WoW API
    3. Creating Slash Commands
    4. Persistence
    5. Extracting the Default UI
    6. Summary
  13. CHAPTER 4: Working with Game Events
    1. Using Frames as Event Listeners
    2. Creating ChatlinkTooltips
      1. Chat Frames and Their Script Handlers
      2. Item Links
      3. Using Tooltips
    3. OnEvent
      1. Event Handler Basics
      2. Event Handlers for Multiple Events
    4. Using OnUpdate to Build a Timing Library
      1. The Scheduler
      2. The Unscheduler
      3. OnUpdate and Performance
    5. Using the Timing Library for a DKP Mod
      1. Variables and Options
      2. Local Functions and Their Scope
      3. Starting Auctions
      4. Ending Auctions
      5. Placing Bids
      6. Creating Slash Commands
      7. Canceling Auctions
      8. Remote Control
      9. Hiding Chat Messages
    6. Summary
  14. CHAPTER 5: Using XML and Frames
    1. XML Basics
      1. XML Terminology
      2. Elements in World of Warcraft XML
    2. Validating and Debugging XML
      1. Validating XML in SciTE
      2. Debugging XML
    3. Frame Basics
      1. Making It Visible
      2. Layers and Textures
      3. Movable Frames
    4. Inheritance
      1. The Frame Type Button
      2. Buttons in XML
      3. Using a Button Template
    5. Designing the Table Browser
      1. Simple Buttons
    6. Building a List Element
      1. Creating a Border
      2. Creating a Template for the Headers
      3. Using the Template
      4. A Short Overview of Our XML
      5. Creating a Template for the Entries
      6. Creating the Buttons
      7. Sorting the List
      8. Selecting Elements in the List
      9. Scroll Frames for Lists
    7. More Buttons and Static Popup Dialogs
      1. More Buttons
      2. Static Popup Dialogs
    8. More Frame Types
      1. Another Normal Frame
      2. Edit Boxes
      3. Sliders
      4. Check Buttons
      5. OK and Cancel Buttons
    9. An Overview of the Whole XML File
    10. Summary
  15. CHAPTER 6: Advanced Lua
    1. More About Functions
      1. Static Scoping
      2. Closures
      3. Recursion, Part 1: Tail Calls
      4. Recursion, Part 2: Recursive Table Functions
      5. Hooking
    2. More About the Generic for Loop
    3. Using Tables to Build Data Structures
      1. Arrays
      2. Stacks
      3. Doubly Linked Lists
      4. Graphs
    4. Metatables and Metamethods
      1. Overloading Operators
      2. Available Metamethods
    5. Object Orientation
      1. The Colon Operator
      2. The __index Metamethod and Constructors
      3. Inheritance
      4. Multiple Inheritance
      5. Object Orientation and Data Structures
    6. Handling Errors
      1. Catching Errors
      2. Throwing Errors
      3. The Environment
    7. The Garbage Collector
      1. The Old Lua 5.0 Garbage Collector
      2. Incremental Garbage Collection
      3. Weak References
      4. Controlling the Garbage Collector
      5. Testing the Garbage Collector
    8. More About Lua Libraries
      1. The Bit Library
      2. The String Library: Part 2
    9. Summary
  16. CHAPTER 7: Using Advanced Lua to Extend the Texas Hold'em Poker Addon
    1. Building Auxiliary Functions
      1. Creating Cards
      2. Getting Cards
      3. Extracting and Rating the Best Hand
      4. Calculating a Rating
      5. Finding and Rating the Hand
    2. Building the Server
      1. Creating a Player Object
      2. Creating a Server Object
      3. Finite-State Machines
      4. Joining a Game
      5. Starting Betting Rounds
      6. Shuffling and Drawing Cards
      7. Player Cards and Community Cards
      8. Moving the Dealer Button
      9. The Showdown
      10. Waiting for Bets
    3. Simple Timing Library 2.0
      1. Object-Oriented Timing Library
      2. Supporting the Old Timing Library
      3. Using Another Data Structure?
    4. Saved Variables and Metatables
      1. The Problem: Saving Tables
      2. The Solution: Metatables
    5. Summary
  17. CHAPTER 8: Building a Poker Game Client with Addon Communication
    1. Addon Communication Basics
      1. Sending Messages
      2. Receiving Messages
      3. Playing Around with Addon Messages
    2. Security and Addon Messages
    3. Building the Poker Client
      1. The Different Message Types We Need
      2. Sending Game Announcements
      3. Receiving Game Announcements
      4. Joining Games
      5. Receiving Status Updates
    4. Summary
  18. CHAPTER 9: Using the Combat Log to Build a Cooldown Monitor
    1. Working with Combat Log Events
      1. Combat Log Arguments
      2. Building an Event Handler
    2. Working with GUIDs and Units
      1. NPC and Vehicle GUIDs
      2. Player and Pet GUIDs
      3. GUID Examples
      4. Unit IDs
    3. Unit Flags and Spell Schools
      1. Bit Fields
      2. Spell Schools
      3. Unit Flags
    4. Building a Cooldown Monitor
      1. Detecting Spells
      2. Using Escape Sequences in Chat Frames
      3. Building Status Bar Timers
    5. Summary
  19. CHAPTER 10: Using Libraries
    1. Embedded Libraries
      1. Versioning Libraries
      2. Problems with Embedded Libraries
      3. Using LibStub
      4. Creating Our Own Embedded Library
    2. The Ace Framework
      1. A Simple Hello, World Addon with Ace3
      2. Advanced “Hello, World” with Ace3
      3. Slash Commands with AceConsole
    3. Creating FuBar Plugins
      1. Embedding LibFuBarPlugin-3.0
      2. Using LibFuBarPlugin-3.0
    4. Improving CooldownMonitor with Deadly Bar Timers
      1. Getting Started
      2. First Steps with DBT
      3. Integrating DBT in CooldownMonitor
      4. Adding Options
    5. Deadly Boss Mods
      1. Introduction to DBM
      2. DBM TOC Files
      3. Boss Mods
      4. Localizing Boss Mods
    6. Summary
  20. CHAPTER 11: Working with Secure Templates
    1. Secure and Tainted Code
      1. Restricted Functions
      2. Hooking Secure Functions
      3. How Taint Spreads
    2. Using Secure Templates for a Unit Frame Mod
      1. Restrictions on Protected Frames
      2. Available Secure Templates
      3. Building Unit Frames with Attributes
      4. Using Group Header Templates
    3. Using Secure Action Button Templates
      1. A Simple Secure Action Button
      2. An Advanced Secure Action Button
    4. Summary
  21. CHAPTER 12: Macros
    1. Available Commands
      1. Secure and Normal Slash Commands
      2. The Target Option
      3. List of Secure Commands
      4. Cast Sequences
      5. Item Slot IDs
    2. Conditions
      1. Available Conditions
      2. Combining Conditions
      3. Simple Control Structures
      4. Macro Feedback
    3. Circumventing the 255-Character Limit
    4. Using Lua in Macros
      1. Sending Chat Messages
      2. Timers in Macros
      3. Suppressing Errors
      4. Tuning Options
      5. Circumventing the [flyable] Bug
    5. Summary
  22. CHAPTER 13: Tips, Tricks, and Optimization
    1. Measuring Performance
      1. Measuring Performance in Lua
      2. Profiling Addons in World of Warcraft
      3. Some Conventions
    2. The Main Rules of Optimization
    3. Strings
      1. Understanding Strings
      2. Example: Concatenation in Addon Communication
      3. Optimizing string.format
    4. Local Variables
      1. Global Variables vs. Local Variables
      2. What Does It Mean?
    5. Tables
      1. Understanding Arrays
      2. Understanding Hash Tables
      3. Basic Table Optimizations
    6. Optimizing SimpleTimingLib
      1. Using Another Data Structure
      2. Building SimpleTimingLib-1.1
      3. Recycling Tables?
    7. Utilizing Userdata
      1. Using Userdata as a Proxy
      2. Userdata Metamethods
    8. The Coroutine Library
      1. Coroutine Basics
      2. A Coroutine Example
    9. Summary
  23. CHAPTER 14: Other Uses for Lua
    1. Customizing SciTE with Lua
      1. Hello, World with SciTE
      2. Event Handlers
      3. SciTE Documentation
    2. Lua in Warhammer Online
      1. Hello, World in Warhammer Online
      2. Documentation
    3. Lua and Lugre
      1. Setting Up Lugre
      2. Creating a Simple 3D Application
      3. Documentation
    4. Summary
  24. APPENDIX A: Frame Reference
    1. Object
      1. XML Attributes
      2. Lua Methods
    2. Font
      1. XML Attributes
      2. XML Elements
      3. Lua Methods
    3. Region
      1. XML Attributes
      2. XML Elements
      3. Lua Methods
    4. Frame
      1. XML Attributes
      2. XML Elements
      3. Lua Methods
      4. Script Handlers
    5. FontString
      1. XML Attribute
      2. Lua Methods
    6. Texture
      1. XML Attributes
      2. XML Elements
      3. Lua Methods
    7. Button
      1. XML Attributes
      2. XML Elements
      3. Lua Methods
      4. Script Handlers
    8. CheckButton
      1. XML Attributes
      2. XML Elements
      3. Lua Methods
    9. Cooldown
      1. XML Attributes
      2. Lua Methods
    10. ColorSelect
      1. XML Elements
      2. Lua Methods
      3. Script Handlers
    11. EditBox
      1. XML Attributes
      2. XML Elements
      3. Lua Methods
      4. Script Handlers
    12. GameTooltip
      1. Lua Methods
    13. MessageFrame
      1. XML Attributes
      2. XML Elements
      3. Lua Methods
    14. Model
      1. XML Attributes
      2. XML Elements
      3. Lua Methods
    15. PlayerModel
      1. Lua Methods
    16. DressUpModel
      1. Lua Methods
    17. TabardModel
      1. Lua Methods
    18. ScrollFrame
      1. XML Elements
      2. Lua Methods
      3. Script Handlers
    19. ScrollingMessageFrame
      1. XML Attributes
      2. Lua Methods
    20. SimpleHTML
      1. XML Attributes
      2. XML Elements
      3. Lua Methods
    21. Slider
      1. XML Attributes
      2. XML Elements
      3. Lua Methods
      4. Script Handlers
    22. StatusBar
      1. XML Attributes
      2. XML Elements
      3. Lua Methods
  25. APPENDIX B: Combat Log and Unit Reference
    1. Combat Log Events
      1. Standard Arguments
      2. Additional Arguments for the Prefixes SPELL_ and RANGE_
      3. Additional Argument for the Prefix ENVIRONMENTAL_
      4. Additional Arguments for the Suffix _DAMAGE
      5. Additional Arguments for the Suffix _HEAL
      6. Additional Arguments for the Suffix _MISSED
      7. Additional Argument for the Suffix _FAILED
      8. Additional Argument for the Suffix _EXTRA_ATTACKS
      9. Additional Arguments for the Suffixes _ENERGIZE, _DRAIN, and _LEECH
      10. Additional Arguments for Dispels and Interrupts
      11. Additional Arguments for Buff Events
      12. Additional Arguments for Damage Shield Events
      13. Additional Arguments for Enchant Events
      14. The Spell School Bit Field
      15. The Unit Flags Bit Field
    2. Unit IDs
    3. Unit Functions
  26. Index

Product information

  • Title: Beginning Lua with World of Warcraft Addons
  • Author(s): Paul Emmerich
  • Release date: July 2009
  • Publisher(s): Apress
  • ISBN: 9781430223719