Tag: addon

  • Create Your First Slash Command in WoW Classic (/hello)

    Create Your First Slash Command in WoW Classic (/hello)

    In the first part of this series, we built a tiny addon that prints a message when you log in. Now we’ll make it a bit more interactive by adding your first slash command: /hello.

    When you type /hello in chat, the addon will greet you by name. This is often the next step for new addon authors because slash commands are a simple way to trigger your code on demand.

    What Is a Slash Command?

    Slash commands are those chat commands that start with /:

    • /reload
    • /dance
    • /who
    • …and of course, custom ones like /hello.

    Addons can register their own commands and link them to Lua functions. When you type the command in chat, WoW calls the function you defined.

    Reusing the Same Addon Folder

    We’ll continue using the same addon from part 1:

    World of Warcraft\_classic_\Interface\AddOns\MyFirstAddon\

    You should already have:

    • MyFirstAddon.toc
    • main.lua

    We don’t need to change the TOC file for this step. All the magic will happen inside main.lua.

    Adding a /hello Command

    Open main.lua and start from what we had before:

    local frame = CreateFrame("FRAME")
    frame:RegisterEvent("PLAYER_LOGIN")
    
    frame:SetScript("OnEvent", function()
        print("|cfff4b034MyFirstAddon loaded successfully!|r")
    end)

    Now we’ll add a simple function and register a slash command.

    1. Write the Hello Function

    Add this below the existing code:

    local function MyFirstAddon_SayHello(msg)
        local playerName = UnitName("player")
    
        if msg and msg ~= "" then
            print("|cfff4b034[MyFirstAddon]|r Hello, " .. playerName .. "! You said: " .. msg)
        else
            print("|cfff4b034[MyFirstAddon]|r Hello, " .. playerName .. "!")
        end
    end

    What it does:

    • Gets your character name with UnitName("player").
    • If you type extra text after /hello, it prints that too. Example: /hello nice UI → “You said: nice UI”.

    2. Register the Slash Command

    WoW uses a global table called SLASH_<NAME><number> to connect slash commands with a handler function named SlashCmdList["NAME"].

    Add this under the function you just created:

    SLASH_MYFIRSTADDON1 = "/hello"
    
    SlashCmdList["MYFIRSTADDON"] = function(msg)
        MyFirstAddon_SayHello(msg)
    end

    This means:

    • /hello is now a valid command.
    • Whenever you type /hello, WoW calls the function registered in SlashCmdList["MYFIRSTADDON"].
    • We forward the message (msg) to MyFirstAddon_SayHello.

    Final main.lua Example

    Here’s the complete file so you can compare:

    -- Create a frame to listen to events
    local frame = CreateFrame("FRAME")
    frame:RegisterEvent("PLAYER_LOGIN")
    
    -- When the player logs in, print a message
    frame:SetScript("OnEvent", function()
        print("|cfff4b034MyFirstAddon loaded successfully! Type /hello to test it.|r")
    end)
    
    -- Our hello function
    local function MyFirstAddon_SayHello(msg)
        local playerName = UnitName("player")
    
        if msg and msg ~= "" then
            print("|cfff4b034[MyFirstAddon]|r Hello, " .. playerName .. "! You said: " .. msg)
        else
            print("|cfff4b034[MyFirstAddon]|r Hello, " .. playerName .. "!")
        end
    end
    
    -- Register the /hello slash command
    SLASH_MYFIRSTADDON1 = "/hello"
    
    SlashCmdList["MYFIRSTADDON"] = function(msg)
        MyFirstAddon_SayHello(msg)
    end

    Testing Your /hello Command In-Game

    1. Save main.lua.
    2. (Re)start WoW Classic or type /reload in-game.
    3. On login, you should see:

    MyFirstAddon loaded successfully! Type /hello to test it.

    4. In the chat window, type:

    • /hello
    • /hello this is my first addon

    You should see your greeting messages printed back to you.

    Troubleshooting

    • “Interface action failed because of an AddOn”
      There’s likely a syntax error. Check missing quotes, commas, or end.
    • /hello does nothing
      Make sure MyFirstAddon is enabled in the AddOns menu, and check that the slash name matches exactly: SLASH_MYFIRSTADDON1 and SlashCmdList["MYFIRSTADDON"].

    Where We Go From Here

    You now have:

    • A loading message on PLAYER_LOGIN
    • Your first custom slash command
    • A small reusable function (MyFirstAddon_SayHello)

    Next possible steps:

    • Add /hello help with a small help text
    • Register multiple commands (/hello and /hi)
    • Start creating a simple UI frame to display options instead of only using chat

    Stay tuned — your addon is starting to become interactive, and this is just the beginning of what you can build for your own WoW Classic UI!

  • How to Create Your First WoW Classic Addon: A Beginner-Friendly Introduction

    How to Create Your First WoW Classic Addon: A Beginner-Friendly Introduction

    So you want to create your first addon for WoW Classic? Great choice! Whether you’re looking to add a personal tweak to your UI, build a small quality-of-life feature, or one day release a fully-fledged addon to the community, the whole process is much simpler than it looks.

    This guide is a gentle introduction to the basics — no coding experience required. By the end, you’ll understand how addons are structured, where files go, what the essential components are, and how to prepare your very first working addon.

    What Exactly Is a WoW Addon?

    Addons are small modules written in Lua (a lightweight scripting language) and XML. They allow you to customize WoW’s interface, automate UI behaviors (not gameplay!), display additional information, improve usability, and more.

    They cannot perform rotation automation, botting, or anything that interacts with combat actions — but they can deeply enhance your interface and your overall experience.

    How Addons Are Structured

    Every addon is just a folder placed inside:

    World of Warcraft\_classic_\Interface\AddOns\

    Inside that folder, you typically have:

    • A .toc file — your addon’s “manifest” that tells WoW what files to load.
    • One or more .lua files — your code and logic.
    • (Optional) .xml files — frames, UI definitions, templates.
    • (Optional) Assets — icons, textures, images, sounds.

    A minimal addon contains only a folder + a .toc file + one Lua file.

    Creating Your First Addon (Step-by-Step)

    Let’s start with the simplest addon possible: something that prints a message when you log in.

    1. Create the Addon Folder

    Go to:

    World of Warcraft\_classic_\Interface\AddOns\

    Create a new folder called:

    MyFirstAddon

    (You can replace the name with anything — just avoid spaces.)

    2. Create the TOC File

    Inside the folder, create a file named:

    MyFirstAddon.toc

    Add this content:

    ## Interface: 11502
    ## Title: My First Addon
    ## Notes: A simple test addon for WoW Classic
    ## Author: YourName
    ## Version: 1.0
    
    main.lua

    Important: Update the Interface number for your version of WoW Classic (it changes every major patch). You can check it by looking at any other addon’s .toc file.

    3. Create Your First Lua File

    Now create the file referenced in the toc:

    main.lua

    Put this inside:

    local frame = CreateFrame("FRAME")
    frame:RegisterEvent("PLAYER_LOGIN")
    
    frame:SetScript("OnEvent", function()
        print("|cfff4b034MyFirstAddon loaded successfully!|r")
    end)

    Congratulations — you’ve just created an addon that loads and displays a message when the player logs in.

    Where to See (and Enable) Your Addon

    Start WoW Classic and go to the Character Select screen, then click AddOns in the lower-left corner.

    You should see My First Addon in the list. Make sure it’s enabled, then enter the game. After login, you should see your custom message in the chat frame.

    What You Just Accomplished

    You now understand:

    • Where addons are stored
    • How the .toc file works
    • How Lua code is loaded
    • How to respond to events (like PLAYER_LOGIN)
    • How to print and test basic behavior

    This is the foundation for everything else — frames, slash commands, data storage, UI widgets, and more.

    What’s Next?

    This introduction is the first part of a series. In the next guides, we’ll cover:

    • Adding slash commands (like /hello)
    • Creating your first frame with XML or Lua
    • Saving data between sessions (SavedVariables)
    • Debugging and structuring your addon project
    • Packaging your addon for CurseForge or Wago

    Stay tuned — your first tiny addon is just the beginning of what you can build for your own WoW Classic UI!