Thread Tools Display Modes
05-05-11, 06:12 AM   #1
apocalipsus
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 5
How can i get the name of the player that left the group

Hello all.
I've just recently start creating addons for the game, and therefor im still a newb.
I was wondering how i can get the name of the player that just left the group (party or raid) I was messing with the "PARTY_MEMBERS_CHANGED" event but no luck so far

Thanks in advance
  Reply With Quote
05-05-11, 06:43 AM   #2
Malsis
Premium Member
 
Malsis's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 29
A common requirement of several software projects I've worked on is 'What was here before but isn't now?'

The easiest way, if the API doesn't actually give you a hook, is to keep a state table - in this case, all party members - then you can check that to see if one or more are no longer there.

Withoutlooking it up, I'd guess there's a PARTY_CHANGED type event, which you could use to trigger the check.
  Reply With Quote
05-05-11, 08:00 AM   #3
apocalipsus
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 5
Originally Posted by Malsis View Post
A common requirement of several software projects I've worked on is 'What was here before but isn't now?'

The easiest way, if the API doesn't actually give you a hook, is to keep a state table - in this case, all party members - then you can check that to see if one or more are no longer there.

Withoutlooking it up, I'd guess there's a PARTY_CHANGED type event, which you could use to trigger the check.
Hey there.
Thanks for the reply. That was exactly my idea atm, but im not sure if it is too practical, or if it's consuming unnecessary resources.

Im saving a table with all the raid members, and im watching the event i mentioned before ("PARTY_MEMBERS_CHANGED") so if the new number of members is less then the table size i know someone just left, and im comparing both tables to check who left, then do stuff (including removing that player from the table)

Wonder if this is a bad thing :/
  Reply With Quote
05-05-11, 08:10 AM   #4
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Another solution is to register for CHAT_MSG_SYSTEM and look for this GlobalString
Code:
LEFT_PARTY = "%s leaves the party."
Although I don't know myself how exactly it should be done with format or strfind, I still don't understand that part
  Reply With Quote
05-05-11, 10:21 AM   #5
NitraMo
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 24
Originally Posted by apocalipsus View Post
Hey there.
Thanks for the reply. That was exactly my idea atm, but im not sure if it is too practical, or if it's consuming unnecessary resources.

Im saving a table with all the raid members, and im watching the event i mentioned before ("PARTY_MEMBERS_CHANGED") so if the new number of members is less then the table size i know someone just left, and im comparing both tables to check who left, then do stuff (including removing that player from the table)

Wonder if this is a bad thing :/
Sounds like a legitimate way to solve it.
__________________
  Reply With Quote
05-05-11, 02:42 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by Ketho View Post
Another solution is to register for CHAT_MSG_SYSTEM and look for this GlobalString
Code:
LEFT_PARTY = "%s leaves the party."
Although I don't know myself how exactly it should be done with format or strfind, I still don't understand that part
I've worked on this kind of function a few times, although during my recent remake of it, I abandoned it during a debug phase. The purpose was to recompile a format string into a pattern string for use with string.match(). The design of it was to give it the format string and the result string of the format and it would return the argument list, acting in reverse of string.format().

This function was to make localizations easier by providing a method in which it wasn't necessary to add different patterns for different locales. Also to cut down on CPU load from repetitive use, the function would remember what format strings it had already recompiled. Calling it with the same format string, it would only recompile it once, then just keep returning the same pattern string.



To provide a solution to the OP right now, this should do the trick.
lua Code:
  1. local frame=CreateFrame("Frame");
  2. frame:RegisterEvent("CHAT_MSG_SYSTEM");
  3. frame:SetScript("OnEvent",function(self,event,...)
  4.     if event=="CHAT_MSG_SYSTEM" then
  5.         local name=(...):match("(.+) leaves the party.");
  6.         if name then--  Will be nil for any other message
  7. --          Do stuff here
  8.         end
  9.     end
  10. end);
__________________
WoWInterface AddOns
"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 : 05-05-11 at 02:56 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How can i get the name of the player that left the group


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