Thread Tools Display Modes
12-29-05, 10:12 AM   #1
MrHumpty
A Kobold Labourer
Join Date: Dec 2005
Posts: 1
First Addon - What am I doing wrong...

Ok I'm stumped. This is my first attempt to program a simple addon and I can't figure out why it won't work : /

I've checked out WoW's Wiki site as well as looked at other addon's code to figure it out. Everything seems simple enough. Below are all my files and code. I've written these files in Notepad.exe on Windows. If anybody can tell me what is wrong I'd greatly appreciate it. I really think it all looks good enough to at least load up and respond to slash commands.

Directory: /DKGuard

File: Bindings.xml
-------------------------------------------
Code:
<Bindings>
	<Binding name="DKGuard Toggle Enabled" header="DKGUARD">
		toggleDKGuard();
	</Binding>	
</Bindings>
-------------------------------------------

File: DKGuard.lua
-------------------------------------------
Code:
--[[
path: /DKGuard/
filename: DKGuard.lua
author: Brian Roberds <[email protected]>
created: 2005-12-27 15:13:00 PM -0600
updated: 2005-12-27 15:13:00 PM -0600

Dishonerable Kill Guard: An addon that keeps you from targeting Civilians.
]]

-- Configuration
DKG_Config = {
	Enabled = 1,
	Alert = 1
};

DKG_VERSION = "v1.0a December 27th, 2005";

function DKGuard_OnLoad()
	SLASH_DKGUARD1 = "/dkguard";
	SLASH_DKGUARD2 = "/dkg";
	SlashCmdList["DKGUARD"] = DKGuard_SlashCmd;

	this:RegisterEvent("PLAYER_TARGET_CHANGED");
	DEFAULT_CHAT_FRAME:AddMessage("|c00bfffffDKGuard|r " .. DKG_VERSION .. " Loaded.", 0.0, .80, 1);
end

function DKGuard_SlashCmd(msg)
	if (msg == "") then
		DEFAULT_CHAT_FRAME:AddMessage("|c00bfffffDKGuard|r " .. DKG_VERSION .. " by Brian Roberds.", 0.0, .80, 1);
		DEFAULT_CHAT_FRAME:AddMessage("|c00bfffff/dkguard enable|r: Enable DKGuard's target clearing functions.", 0.0, .80, 1);
		DEFAULT_CHAT_FRAME:AddMessage("|c00bfffff/dkguard disable|r: Disable DKGuard's target clearing functions.", 0.0, .80, 1);
		DEFAULT_CHAT_FRAME:AddMessage("|c00bfffff/dkguard alertnone|r: Show no warnings.", 0.0, .80, 1);
		DEFAULT_CHAT_FRAME:AddMessage("|c00bfffff/dkguard alertchat|r: Show warnings in Chat Window.", 0.0, .80, 1);
		DEFAULT_CHAT_FRAME:AddMessage("|c00bfffff/dkguard alertscreen|r: Show warnings in Combat.", 0.0, .80, 1);
		return;
	end

	if (msg = "enable") then
		DKG_Config.Enabled = 1;
		DEFAULT_CHAT_FRAME:AddMessage("|c00bfffffDKGuard|r Enabled - Civilian targets WILL be cleared", 0.0, .80, 1);
	end

	if (msg = "disable") then
		DKG_Config.Enabled = 0;
		DEFAULT_CHAT_FRAME:AddMessage("|c00bfffffDKGuard|r Disabled - Civilian targets will NOT be cleared", 0.0, .80, 1);
	end

	if (msg = "alertnone") then
		DKG_Config.Alert = 0;
		DEFAULT_CHAT_FRAME:AddMessage("|c00bfffffDKGuard|r Alerts Disabled - No visible alerts will be provided when a civilian target is cleared", 0.0, .80, 1);	
	end

	if (msg = "alertchat") then
		DKG_Config.Alert = 1;
		DEFAULT_CHAT_FRAME:AddMessage("|c00bfffffDKGuard|r Alerts To Chat - Visible alerts will be provided when a civilian target is cleared via the default chat window", 0.0, .80, 1);	
	end

	if (msg = "alertcombat") then
		DKG_Config.Alert = 1;
		DEFAULT_CHAT_FRAME:AddMessage("|c00bfffffDKGuard|r Alerts Combat UI - (Not Implimented Chat Box Used) Visible alerts will be provided when a civilian target is cleared via the console", 0.0, .80, 1);	
	end

end

function DKGuard_OnEvent(event)
	if (event == "PLAYER_TARGET_CHANGED") then
		DKGuard_CheckTarget();
		return;
	end
end

function DKGuard_CheckTarget()
	if (UnitIsCivilian("target")==1) then
		if(DKG_Config.Alert = 1)
			DEFAULT_CHAT_FRAME:AddMessage("|c00bfffffDKGuard|r -= Civilian Target Cleared =-", 0.0, .80, 1);	
		end
		if(DKG_Config.Alert = 2)
			-- Show Big Message
		end
		ClearTarget();
	end
end

function toggleDKGuard()

	if (DKG_Config.Enabled = 1) then
		DKGuard_SlashCmd("disable");
	else
		DKGuard_SlashCmd("enable");
	end

end
-------------------------------------------

File: DKGuard.toc
-------------------------------------------
Code:
## Interface: 1800
## Title : Dishonerable Kill Guard
## Notes: An addon that keeps you from targeting Civilians.
## Author: Brian Roberds
## eMail: [email protected]
## Version: 1.0a
## DefaultState: enabled
## SavedVariables: DKG_Config
-------------------------------------------

Last edited by MrHumpty : 12-29-05 at 10:13 AM. Reason: Added Code Tags
  Reply With Quote
01-02-06, 09:05 AM   #2
Qiu
A Murloc Raider
Join Date: Mar 2005
Posts: 8
Is that the entirety of all 3 files? If it is you are missing some stuff.

in the .toc you need a line saying Bindings.xml at the very end, with no ##

in the .xml you need a line saying <script file="DKGuard.lua" />

didnt check everything because i just woke up and am too tired
  Reply With Quote
01-02-06, 09:22 AM   #3
fdisk42
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 2
where's your DKGuard.xml file?
  Reply With Quote
01-02-06, 01:09 PM   #4
Qiu
A Murloc Raider
Join Date: Mar 2005
Posts: 8
Originally Posted by fdisk42
where's your DKGuard.xml file?
lol i didnt even notice that
  Reply With Quote
01-02-06, 07:27 PM   #5
Guillotine
A Cobalt Mageweaver
 
Guillotine's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2005
Posts: 206
Originally Posted by fdisk42
where's your DKGuard.xml file?
Yup. That's the problem. Make a .xml file and link it from .toc file. You need this b/c you are working with events.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » First Addon - What am I doing wrong...


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off