Page 1 of 1

Don't play sound for my own messages.

Posted: Wed Feb 02, 2011 5:50 am
by mike
Hi guys

I have the following code in the onEvent() function of a RoM addon. It plays a sound whenever someone tries to talk to me:

Code: Select all

if (event == "CHAT_MSG_WHISPER") then
			PlaySoundByPath("Interface/AddOns/MsgNotify/Sounds/game.wav");
		end;
		if (event == "CHAT_MSG_GUILD") then
				PlaySoundByPath("Interface/Addons/MsgNotify/Sounds/bell.wav");
		end;
		if (event == "CHAT_MSG_PARTY") then
				PlaySoundByPath("Interface/Addons/MsgNotify/Sounds/bell.wav");
		end;
		if (event == "CHAT_MSG_SAY") then
			PlaySoundByPath("Interface/AddOns/MsgNotify/Sounds/guitar.wav");
		end;
The only problem is that it plays the sound whenever I post a message as well. For instance in Miller's Farm it will play the guitar.wav file everytime I cheer the chickens on.

Is there a way to check by whom the message is being posted? It might also be useful to exclude messages posted by NPCs or any users one might like to exclude for whatever reason.

All advice is appreciated in advance.

Regards
Mike

Re: Don't play sound for my own messages.

Posted: Wed Feb 02, 2011 8:16 am
by rock5
Events return more than 1 argument. In this case 1 of them should be the sender.

Re: Don't play sound for my own messages.

Posted: Wed Feb 02, 2011 9:53 am
by mike
Ah! arg4 works nicely! I altered my code as follows:

Code: Select all

                if (event == "CHAT_MSG_WHISPER") then
			PlaySoundByPath("Interface/AddOns/MsgNotify/Sounds/game.wav");
		end;
		if (event == "CHAT_MSG_GUILD") then
				PlaySoundByPath("Interface/Addons/MsgNotify/Sounds/bell.wav");
		end;
		if (event == "CHAT_MSG_PARTY") then
				PlaySoundByPath("Interface/Addons/MsgNotify/Sounds/bell.wav");
		end;
		if (event == "CHAT_MSG_SAY") then
			if (arg4 ~= UnitName("player")) then
				PlaySoundByPath("Interface/AddOns/MsgNotify/Sounds/guitar.wav");
			end;
		end;
Thanks for the advice Rock5.