I think the hardest part to writing an addon is starting it. So Here is an addon that does not alot, but you can add too it to create a useful addon.
Start by creating a folder in the addons folder called "MyAddon", or whatever you want to call it, but be consistent, ie change "MyAddon" throughout to the same name.
Now there are 3 basic files you need (all addons have these). I suggest you use something like wordpad to open up a blank document and copy the following in. It is even better if you use a program that tells you line numbers on the side (for debugging later...). Copy each of these into a blank file and save the file name appropriately.
Save the following as MyAddon.toc in the MyAddon folder:
Code:
## Interface: 20010
## Title: MyAddon
## Notes: MyAddon doesn't do much right now
## Author: Your Name
## SavedVariables:
## OptionalDeps:
## Dependencies:
MyAddon.xml
Now save the following as MyAddon.xml in the MyAddon folder:
Code:
<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">
<Script file="MyAddon.lua"/>
</Ui>
Now save the following as MyAddon.lua in the MyAddon folder:
Code:
--------------------------------------------------
-- MyAddon - by Your Name
--------------------------------------------------
-- Pretty Colour Codes
local BLUE = "|cff6666ff";
local GREY = "|cff999999";
local GREEN = "|cff66cc33";
local RED = "|cffcc6666";
local ORANGE = "|cffcc9933";
local PURPLE = "|cff9900ff";
-- Variables
MyAddon={
["Version"] = "1.0"; -- version
["MaxDebug"] = 20; -- debug messages above this don't show
}
-- Debug function
function MyAddon:Debug(Message,DebugLevel)
if (DebugLevel<=MyAddon.MaxDebug) then
ChatFrame1:AddMessage(RED.."MyAddon Debug"..DebugLevel..": "..Message);
end
end
-- Slash Command Handler
function MyAddonSlashHandler(arg)
MyAddon:Debug("Function MyAddonSlashHandler:"..arg,10);
ChatFrame1:AddMessage(GREEN .. "MyAddon " .. MyAddon.Version .. " by Your Name");
ChatFrame1:AddMessage(GREEN .. "/myaddon something - displays something");
MyAddon:Debug("This debug message won't show up as it's above 20:"..arg,100);
--ChatFrame1:AddMessage(GREEN .. "/myaddon somethingelse - does something else");
MyAddon:SomethingNotVeryUseful(arg);
end
SLASH_MyAddon1 = "/MyAddon";
SLASH_MyAddon2 = "/ma";
SlashCmdList["MyAddon"] = MyAddonSlashHandler;
-- A basic function
function MyAddon:SomethingNotVeryUseful(sometext)
MyAddon:Debug("Function SomethingNotVeryUseful:"..sometext,10);
ChatFrame1:AddMessage(ORANGE..sometext);
end
Now load up wow and see if you can spot some new text at start up.
Try typing /MyAddon hello
PS - I haven't checked this actually works...