Thread Tools Display Modes
10-06-07, 09:51 PM   #1
JJohnson1988
A Deviate Faerie Dragon
 
JJohnson1988's Avatar
Join Date: Jun 2007
Posts: 10
Simple Plug 'n Play Duel Decline Script

I'm working on a simple addon in which you can automatically decline duel requests. Also, this is my first ever addon, mainly for testing purposes, so be nice

Here's what I have so far:
Code:
function DamnDuelDecline_OnLoad()
	this:RegisterEvent("DUEL_REQUESTED");
end

function DamnDuelDecline_OnEvent(event)
	-- Determine what faction the player is
	local p = UnitFactionGroup("player");

	if event == "DUEL_REQUESTED" then
		CancelDuel();
		
		if UnitFactionGroup(arg1) ~= p then
			-- If your challenger is of the opposing faction
			DoEmote("NO", arg1);
		else
			SendChatMessage("Uh-uh-uh! You didn't say the magic word!", "SAY");
		end
	end
end
My question is, would this actually work correctly? I already have my .toc and .xml file already set up correctly.
  Reply With Quote
10-06-07, 10:37 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I don't believe you need an xml file for this.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-06-07, 10:54 PM   #3
JJohnson1988
A Deviate Faerie Dragon
 
JJohnson1988's Avatar
Join Date: Jun 2007
Posts: 10
How would I go about making this work without an .xml file then? I know you can create a frame inside the .lua script but that's about it.

Thanks for the response.
  Reply With Quote
10-06-07, 11:14 PM   #4
Tekkub
A Molten Giant
 
Tekkub's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 960
http://tekkub-wow.googlecode.com/svn.../tekNoDuel.lua

Much more enjoyable reply too... pisses people off to no end.

"What the hell is your problem?"
  Reply With Quote
10-06-07, 11:34 PM   #5
JJohnson1988
A Deviate Faerie Dragon
 
JJohnson1988's Avatar
Join Date: Jun 2007
Posts: 10
Originally Posted by Tekkub
http://tekkub-wow.googlecode.com/svn.../tekNoDuel.lua

Much more enjoyable reply too... pisses people off to no end.

"What the hell is your problem?"
Thanks, that helps =)
  Reply With Quote
10-07-07, 12:48 AM   #6
JJohnson1988
A Deviate Faerie Dragon
 
JJohnson1988's Avatar
Join Date: Jun 2007
Posts: 10
Ok, this is what I have now:
Code:
local frame = CreateFrame("Frame", nil, UIParent);
local rechallenge = {};

frame:RegisterEvent("DUEL_REQUESTED");

frame:SetScript("OnEvent", function(self, event, name)
	local message = "Uh-uh-uh!";
	
	if UnitFactionGroup("player") == UnitFactionGroup(name) then
		if not rechallenge[name] then
			message = message .. " You didn't say the magic word!";
		end
	else
		DoEmote("NO", name);
	end
	
	HideUIPanel(StaticPopup1);
	CancelDuel();

	SendChatMessage(message);
	
	rechallenge[name] = true;
end);
It works well except it repeats the message 3 times for some reason. So when someone first duels me it will say "Uh-uh-uh! You didn't say the magic word" thrice, then when that same person duels me again it will say "Uh-uh-uh!" thrice as well.

Any ideas on how to just say the message once?
  Reply With Quote
10-07-07, 01:34 AM   #7
Tekkub
A Molten Giant
 
Tekkub's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 960
Add a 5-second failsafe so the event handler will only trigger once per barrage of events.

Code:
local lasttime = 0
frame:SetScript("OnEvent", function(self, event, name)
	if GetTime() < (lasttime + 5) then return end 

	-- Do crap

	lasttime = GetTime()
end);
  Reply With Quote
10-07-07, 02:15 AM   #8
JJohnson1988
A Deviate Faerie Dragon
 
JJohnson1988's Avatar
Join Date: Jun 2007
Posts: 10
Thanks, but it appears this code seems to have fixed it... I used a different function to determine if the challenger is an enemy or not:
Code:
local DDD = CreateFrame("Frame", "DamnDuelDecline", UIParent);
local Rechallenge = {};

DDD:RegisterEvent("DUEL_REQUESTED");

DDD:SetScript("OnEvent", function(self, event, challenger)
	local Out = "Uh-uh-uh!";
	
	if not UnitIsEnemy("player", challenger) then
		if not Rechallenge[challenger] then
			Out = Out .. " You didn't say the magic word!";
		end
	else
		Out = "";
		DoEmote("NO", challenger);
	end
	
	HideUIPanel(StaticPopup1);
	CancelDuel();

	SendChatMessage(Out, "SAY");
	
	Rechallenge[challenger] = true;
end);
Now I can release it

Last edited by JJohnson1988 : 10-07-07 at 02:29 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Simple Plug 'n Play Duel Decline Script


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