Reply
Thread Tools Display Modes
Unread 04-16-12, 01:25 PM   #1
Shugster
A Defias Bandit
Join Date: Apr 2012
Posts: 2
Get name of who invited me?

Hello dear wow programmer community

I am unexperienced in addon programming, but am not an unexperienced programmer overall...so Ive started just testing some stuff today which I want to use in an addon later. SO Ive started with simple macros first.

One of them is a script running in the background which fires when I am invited to a group. This automatically declines any party invites incoming immediately:

Code:
/run local s = StaticPopupDialogs["PARTY_INVITE"] 
s.OnAccept=nil s.OnShow=function() 
StaticPopup_Hide("PARTY_INVITE") DeclineGroup(); end
It works perfectly!! But I wanted to expand it a bit, so that the person who invited me automatically gets a whisper from me. This is how far I got:

Code:
 /run local s = StaticPopupDialogs["PARTY_INVITE"] 
s.OnAccept=nil s.OnShow=function()
StaticPopup_Hide("PARTY_INVITE") DeclineGroup(); 
SendChatMessage("text", "WHISPER", nil, *****); end
So my problem is quite simple, I don't know what to type where * are. There's supposed to be the name of the person who I want to whisper, right? So how can I make it automatically whisper the person who sent me the invite?

Please also feel free to make suggestions to improve my script's performance.
As I said I'm kinda new to this so please be so kind to explain in detail how, and why!
Also feel free to move this thread around as you please
Thank you =))
Shugster is offline   Reply With Quote
Unread 04-16-12, 02:09 PM   #2
AcidWeb
A Wyrmkin Dreamwalker
 
AcidWeb's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 56
Hello,

Read about events.
PARTY_INVITE_REQUEST event cointain name of sender.

Also I recommend you this:
http://www.wowinterface.com/download...3-_DevPad.html
As proper way to edit simple LUA snippets in-game :-)
__________________
Livarax - Karazhan
Vox Rootis, Vox Dei!
AcidWeb is offline   Reply With Quote
Unread 04-16-12, 02:13 PM   #3
Ketho
A Molten Giant
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 565
One of the solutions could be to hook StaticPopup_Show to grab the arguments

Code:
hooksecurefunc("StaticPopup_Show", function(popup, arg1)
	if popup == "PARTY_INVITE" then
		SendChatMessage("text", "WHISPER", nil, arg1)
	end
end)
__________________

Last edited by Ketho : 04-16-12 at 02:16 PM.
Ketho is offline   Reply With Quote
Unread 04-16-12, 02:19 PM   #4
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,136
Lua Code:
  1. hooksecurefunc("StaticPopup_Show", function(which, sender)
  2.     if which == "PARTY_INVITE" then
  3.         print("StaticPopup_Show", which, sender)
  4.         local dialog = StaticPopup_Visible("PARTY_INVITE")
  5.         StaticPopup_OnClick(_G[dialog], 2)
  6.         SendChatMessage("No thanks.", "WHISPER", nil, sender)
  7.     end
  8. end)

1. Catch the actual function that shows the popup, and securely run your own function after the original runs. This ensures that you do not break or taint any parts of the StaticPopup system. Your function gets the same arguments as the original.

2. Check the first argument to see if it's the PARTY_INVITE dialog.

3. Comment out the print line once you're sure it's working.

4. Get the name of the frame being used for this dialog. This function can return nil (if the specified dialog is not being displayed) but in this case, we know it is being displayed since our function is running immediately after the Blizzard function that shows this dialog, so we don't need to check that the dialog variable is non-nil before using it.

5. Use the dialog's own OnClick handler to close it and decline the invite. This is easier and more future-proof than calling the relevant functions yourself.

6. Send a message to the sender (second argument).
Phanx is offline   Reply With Quote
Unread 04-16-12, 03:07 PM   #5
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,233
Lua Code:
  1. local frame = CreateFrame'Frame'
  2. frame:RegisterEvent'PARTY_INVITE_REQUEST'
  3. frame:SetScript('OnEvent', function(self, event, name)
  4.     SendChatMessage('Some message to reply here', 'WHISPER', nil, name)
  5.     StaticPopup1Button2:Click()
  6. end)

No need to hook stuff
p3lim is offline   Reply With Quote
Unread 04-16-12, 04:33 PM   #6
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,136
There is, actually.

In my own testing with my own addon Hydra, as well as reports from users, some people receive the event before the dialog is shown, while others show the dialog before receiving the event. It only ever works one way on my client, but apparently it is not consistent between clients. In Hydra, I use both detection methods (securehook on StaticPopup_Show and register for PARTY_INVITE_REQUEST event), and whenever either one occurs, check if the dialog is visible and run StaticPopup_OnClick if it is.

I experienced a similar issue years ago with guild information loading at login. After working with several users who reported that my addon was not working, I discovered that some clients receive guild information from the server (and fire PLAYER_GUILD_UPDATE) before any addons are loaded, so addons never see this event at login, while other clients (eg. mine) do not have any guild information available at login and must wait for the event.

In this case, though, hooking the dialog show is the optimal solution for the OP, as his goal is to automatically click "Decline" on the dialog (thus hiding the dialog and declining the invite). Since the dialog may not yet be visible when his addon receives the event, registering for the event is not optimal.
Phanx is offline   Reply With Quote
Unread 04-16-12, 07:16 PM   #7
semlar
A Molten Giant
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 517
Is DeclineGroup() somehow functionally different from AcceptGroup(), because my personal auto-accept addon just watches PARTY_INVITE_REQUEST and calls AcceptGroup() and the dialog box never even shows up.

Well, there's one caveat - if you're zoning it won't work so I also temporarily register PLAYER_ENTERING_WORLD for that.

Last edited by semlar : 04-16-12 at 07:23 PM.
semlar is offline   Reply With Quote
Unread 04-16-12, 09:50 PM   #8
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,136
Originally Posted by semlar View Post
Is DeclineGroup() somehow functionally different from AcceptGroup(), because my personal auto-accept addon just watches PARTY_INVITE_REQUEST and calls AcceptGroup() and the dialog box never even shows up.
No, but you cannot rely on the order of race condition outcomes (event received by your addon vs dialog being shown) being consistent in other people's game clients. In this case, it sounds like your client shows the dialog before passing the event to your addon. If the OP's client fires the event first, then declining the group in response to the event will leave the dialog visible.
Phanx is offline   Reply With Quote
Unread 04-17-12, 06:12 AM   #9
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,233
Originally Posted by Phanx View Post
There is, actually.

In my own testing with my own addon Hydra, as well as reports from users, some people receive the event before the dialog is shown, while others show the dialog before receiving the event. It only ever works one way on my client, but apparently it is not consistent between clients. In Hydra, I use both detection methods (securehook on StaticPopup_Show and register for PARTY_INVITE_REQUEST event), and whenever either one occurs, check if the dialog is visible and run StaticPopup_OnClick if it is.
That is very odd, been using my method for auto-accepting group invites from people in my guild, and it has never failed.
p3lim is offline   Reply With Quote
Unread 04-17-12, 07:02 AM   #10
Haleth
This Space For Rent
 
Haleth's Avatar
WoWInterface Super Mod
Featured
Join Date: Sep 2008
Posts: 1,164
Originally Posted by p3lim View Post
That is very odd, been using my method for auto-accepting group invites from people in my guild, and it has never failed.
I use that method, however it fails if it is used shortly after login.
Haleth is offline   Reply With Quote
Unread 04-17-12, 07:30 AM   #11
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 537
As always Phanx is right My MiscHelper has the same "problem".
It works for most ppl alright but for some it will fail. My guess it fails on really fast systems (ssd) but never bothered to look deeper into it

Thats why I link alternatives to MiscHelper on the download site
__________________
The cataclysm broke the world ... and the pandas could not fix it!
Rilgamon is offline   Reply With Quote
Unread 04-17-12, 04:17 PM   #12
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,136
Originally Posted by p3lim View Post
That is very odd, been using my method for auto-accepting group invites from people in my guild, and it has never failed.
That's great, but it's neither relevant nor helpful.

If A and B are two outcomes of a race condition, the order in which A and B occur will probably be consistent in your game client (for example, B will always happen before A for you) but THIS IS NOT CONSISTENT BETWEEN OTHER INSTALLATIONS OF WORLD OF WARCRAFT ON OTHER COMPUTERS (or even on other hard drives on the same computer, and maybe not even between separate installations on the same hard drive). Someone else's game client will always see B happen before A.

If you are writing code for other people to use, then it does not matter whether A or B happens first for you, because the order of outcomes may be different for other people, and what happens in your game client is completely irrelevant.


If you don't understand what "race conditon" means, or how this is one:

A race condition is a situation where, in theory, two (or more) things are supposed to happen at the same time. However, in reality, only one thing can actually happen at a time, so one thing happens before the other.

This is a race condition because both your addon's frame and the default UI's frame are registered for the same event. In theory, they receive the event at the same time, but in reality, one receives it before the other. Since the order in which frames in WoW recieve an event is undefined, you cannot rely on one frame always receiving an event before another.

Without being able to look at WoW's source code, we cannot know what determines the order in a particular game client installation, or why it is consistent between sessions in the same installation, but inconsistent between different installations.

We can only know that it is consistent in the same installation, and that it is not consistent between different installations, and work with that.
Phanx is offline   Reply With Quote
Unread 04-17-12, 10:27 PM   #13
SDPhantom
A Molten Giant
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 999
Originally Posted by p3lim View Post
That is very odd, been using my method for auto-accepting group invites from people in my guild, and it has never failed.
Originally Posted by Haleth View Post
I use that method, however it fails if it is used shortly after login.
I honestly hook into UIParent's OnEvent script handler for the event since it's the one that ends up calling StaticPopup_Show() for a lot of similar events. The following code should cover both normal and LFG invites.

Lua Code:
  1. UIParent:HookScript("OnEvent",function(self,event,sender)
  2.     if event=="PARTY_INVITE_REQUEST" then
  3.         DeclineGroup();
  4.         StaticPopup_Hide("PARTY_INVITE");
  5.         StaticPopupSpecial_Hide(LFGInvitePopup);
  6.         SendChatMessage("Party invite auto-declined.","WHISPER",nil,sender);
  7.     end
  8. end

WoW handles dispatching events to registered frames by random order. Simply creating a frame and registering an event does not guarantee the order in which it receives its event in respect to other frames already registered for it. This is why a hook is required to reliably run this kind of code. UIParent receives the event and calls StaticPopup_Show(). As such, you either have to hook its OnEvent script or the StaticPopup_Show() call.
__________________
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-17-12 at 10:44 PM.
SDPhantom is offline   Reply With Quote
Unread 04-22-12, 12:27 AM   #14
Shugster
A Defias Bandit
Join Date: Apr 2012
Posts: 2
Hey there again!

Thank you all so much for your help, I've tried some stuff out but I am very busy with work and preparing for finals, so I don't have much freetime I want to spend on it.
I remember I made the LUA and TOC file, it was all found and loaded and all. But the problem was that my events never fired thus function was never called (apparently). I also made a player login event frame with a simple hello world message, but it was not helping/working...However, before I post the code here and bother with it more, I will need to bring some finals behind me first

I will get this **** to run alone later, and if not, I know I can count on you guys to help me!

Thanks again and see you!
Shugster is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » General Authoring Discussion » Get name of who invited me?

Thread Tools
Display Modes

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