Thread Tools Display Modes
02-13-10, 12:30 AM   #1
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
simple function quest

thx to WoWI community i've become alot more adept @ Lua.

Code:
local function LFG_COMPLETION_REWARD()
	SendChatMessage("Random Dungeon Reward Received! Thanks for Group.", "PARTY", nil, nil);
	print("Random Dungeon Completed.");
	LeaveParty();
end
automatically leaves a dungeon (as you can see). My question is SendChatMesage doesn't manage to (lets use the word) execute before i LeaveParty() how do I make sure it does?, and its so minor and retarded, but I feel sooo rude leaving right the second a boss dies.
  Reply With Quote
02-13-10, 01:02 AM   #2
Shadowed
...
Premium Member
Featured
Join Date: Feb 2006
Posts: 387
You'd have to wait until the message is actually sent. Something like the below will send the message and once it sees that you sent the message it'll drop group.


Code:
	local finishedMsg = "Random Dungeon Reward Received! Thanks for Group."
	local function CHAT_MSG_PARTY(msg, author)
		if( msg == finishedMsg and author == UnitName("player") ) then
			LeaveParty()
		end
	end

	local function LFG_COMPLETION_REWARD)
		SendChatMessage(finishedMsg, "PARTY")
		print("Random Dungeon Completed.")
	end
  Reply With Quote
02-14-10, 06:08 AM   #3
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
thank you for the reply Shadowed, really appreciate it

and thanks everyone for being patient with me i know i ask alot of easy to answer questions
  Reply With Quote
02-14-10, 08:58 AM   #4
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by Shadowed View Post
You'd have to wait until the message is actually sent. Something like the below will send the message and once it sees that you sent the message it'll drop group.


Code:
	local finishedMsg = "Random Dungeon Reward Received! Thanks for Group."
	local function CHAT_MSG_PARTY(msg, author)
		if( msg == finishedMsg and author == UnitName("player") ) then
			LeaveParty()
		end
	end

	local function LFG_COMPLETION_REWARD)
		SendChatMessage(finishedMsg, "PARTY")
		print("Random Dungeon Completed.")
	end
For that to work, you will of course have to register that event and set your local function as an OnEvent handler.
  Reply With Quote
02-14-10, 09:45 AM   #5
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by Akryn View Post
For that to work, you will of course have to register that event and set your local function as an OnEvent handler.
or, register for the event CHAT_MSG_PARTY within the LFG_COMPLETION_REWARD function even. In the CHAT_MSG_PARTY function you can then unregister it.
  Reply With Quote
02-14-10, 09:14 PM   #6
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
Code:
local function LFG_COMPLETION_REWARD()
	AddOn:RegisterEvent("CHAT_MSG_PARTY")
	AddOn:SetScript("OnEvent", function(self, CHAT_MSG_PARTY, msg, author)
		if( msg == finishedMsg and author == UnitName("player") ) then
			LeaveParty()
                        AddOn:UnregisterEvent("CHAT_MSG_PARTY")
		end
	end)
	SendChatMessage(finishedMsg, "PARTY")	
	aMessage("Random Dungeon Completed.")
end
This is what I ended up using, thx alot for the help I'm still getting familiar with the WoW API and Events.

thx much once again really appreciate the communities help and patience.

Last edited by alimjocox : 02-14-10 at 09:25 PM.
  Reply With Quote
02-14-10, 09:42 PM   #7
Shadowed
...
Premium Member
Featured
Join Date: Feb 2006
Posts: 387
Originally Posted by alimjocox View Post
Code:
local function LFG_COMPLETION_REWARD()
	AddOn:RegisterEvent("CHAT_MSG_PARTY")
	AddOn:SetScript("OnEvent", function(self, CHAT_MSG_PARTY, msg, author)
		if( msg == finishedMsg and author == UnitName("player") ) then
			LeaveParty()
                        AddOn:UnregisterEvent("CHAT_MSG_PARTY")
		end
	end)
	SendChatMessage(finishedMsg, "PARTY")	
	aMessage("Random Dungeon Completed.")
end
This is what I ended up using, thx alot for the help I'm still getting familiar with the WoW API and Events.

thx much once again really appreciate the communities help and patience.
While that works, a more correct way of doing it is the below. That way you are creating the function only once, instead of every time you finish a dungeon.
Code:
AddOn:SetScript("OnEvent", function(self, CHAT_MSG_PARTY, msg, author)
	if( msg == finishedMsg and author == UnitName("player") ) then
		LeaveParty()
		AddOn:UnregisterEvent("CHAT_MSG_PARTY")
	end
end)
local function LFG_COMPLETION_REWARD()
	AddOn:RegisterEvent("CHAT_MSG_PARTY")
	SendChatMessage(finishedMsg, "PARTY")	
	aMessage("Random Dungeon Completed.")
end
  Reply With Quote
02-14-10, 10:32 PM   #8
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
thx for the advice
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » simple function quest


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