PDA

View Full Version : Help parsing CHAT_MSG_SYSTEM


Fatalism
17-11-2006, 07:49 AM
I'm trying to write my first mod, part of which involves getting the name of a guild member who is signing in and then checking to make sure they are a guild member and not just a friend. I'm having a problem getting the name out of the event CHAT_MSG_SYSTEM and the string passed |Hplayer :%s|h[%s]|h has come online.

Sample code:

if (event == "CHAT_MSG_SYSTEM") then
msg = arg1;
if (string.find(string.lower(msg), "online") ~= nil) then
a, b, c, altname = string.find(msg,"[\[].-[\]]");
SendChatMessage("Altname: " .. altname,"SAY");
SendChatMessage(kadyhi().."altname","SAY");
end
end

which is supposed to pull the players name from between the '[' and ']' but it keeps giving me errors taht altname is nil. I have also tried:

a, b, altname = string.find(msg,"[\[].-[\]]");

and other variations without luck. Obviously I'm missing something. Once I have the name I have to figure out how to compare it with a list of guild members somehow. Any suggestions on either problem would be appreciated.

Nihilism - 42 Druid - Draka

Duugu
17-11-2006, 02:03 PM
Try
_, _, _, altname = string.find(msg,"(.+)%[(.+)%](.+)");
See also http://www.lua.org/pil/20.2.html

REgarding your guild members you'll need
http://www.wowwiki.com/API_GetNumGuildMembers
and
http://www.wowwiki.com/API_GetGuildRosterInfo

Fatalism
17-11-2006, 03:45 PM
Thank you :) that worked perfectly and I think I understand the difference and the mistake I was making. Now to try checking if the character is in the guild and I'll be done!

Athame
18-11-2006, 11:37 PM
www.regexp.info (http://www.regexp.info) is a great tutorial and reference for regular expressions. Just remember the lua regex uses the % (percentage) instead of the \ (backslash).