Thread Tools Display Modes
09/30/14, 10:04 PM   #1
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
EVENT_CHAT_MESSAGE_CHANNEL Question

hello,

i'm using the EVENT_CHAT_MESSAGE_CHANNEL event to see if a friend is whispering me, it seems to be working properly but i'm friend that the message display even when its not a direct whisper and its even a "group chat" message to the group we are in. I'd only like to catch when someone whispers me directly rather than seeing the debug statement when the message is in group chat. any ideas?

Code:
function ChatMessageChannel(eventCode, messageType, fromName, text)

local pstPerson = zo_strformat(SI_UNIT_NAME, fromName)

if messageType == CHAT_CATEGORY_WHISPER_INCOMING and then
	d(pstPerson)
	if (IsFriend(pstPerson)) then
		d("A friend just whispered you")
	end 
end


end
  Reply With Quote
10/01/14, 04:28 AM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Lua Code:
  1. local function ChatMessageChannel(messageType, fromName, text)
  2.    
  3.     if messageType == CHAT_CHANNEL_WHISPER then
  4.    
  5.         -- Don't zo_strformat UserId's
  6.         local pstPerson
  7.         if string.find(from, "@") == nil then
  8.             pstPerson = zo_strformat(SI_UNIT_NAME, fromName)
  9.         end
  10.        
  11.         d(pstPerson)
  12.        
  13.         if (IsFriend(pstPerson)) then
  14.             d("A friend just whispered you")
  15.         end
  16.        
  17.     end
  18.    
  19. end
  20.  
  21. ZO_ChatSystem_AddEventHandler(EVENT_CHAT_MESSAGE_CHANNEL, ChatMessageChannel)

I didn't checked it, but it should work as intended, no?

Last edited by Ayantir : 10/01/14 at 04:37 AM.
  Reply With Quote
10/01/14, 04:54 AM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Ayantir View Post
Lua Code:
  1. local function ChatMessageChannel(messageType, fromName, text)
  2.    
  3.     if messageType == CHAT_CHANNEL_WHISPER then
  4.    
  5.         -- Don't zo_strformat UserId's
  6.         local pstPerson
  7.         if string.find(from, "@") == nil then
  8.             pstPerson = zo_strformat(SI_UNIT_NAME, fromName)
  9.         end
  10.        
  11.         d(pstPerson)
  12.        
  13.         if (IsFriend(pstPerson)) then
  14.             d("A friend just whispered you")
  15.         end
  16.        
  17.     end
  18.    
  19. end
  20.  
  21. ZO_ChatSystem_AddEventHandler(EVENT_CHAT_MESSAGE_CHANNEL, ChatMessageChannel)

I didn't checked it, but it should work as intended, no?
This function will replace existing event handler, so it can cause conflicts between this and other addons. I'd recommend hooking of the existing event handler.
Lua Code:
  1. local function ChatMessageChannel(messageType, fromName, ...)
  2.     if messageType == CHAT_CHANNEL_WHISPER then
  3.         if IsFriend(fromName) then
  4.             d("A friend just whispered you")
  5.         end
  6.     end
  7. end
  8.  
  9. ZO_PreHook(ZO_ChatSystem_GetEventHandlers(), EVENT_CHAT_MESSAGE_CHANNEL, ChatMessageChannel)
  Reply With Quote
10/01/14, 05:37 PM   #4
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Excellent, thank you both for the help. I'm a newb, wasn't aware of the ZO_Chat Event Handlers.. those seem to be magic. can't find a lot of docs on them.
  Reply With Quote
10/01/14, 06:15 PM   #5
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 231
Main event manager works fine too. I use that in AutoInvite:
Lua Code:
  1. AutoInvite.callback = function(_, messageType, from, message)
  2.     -- ...
  3. end
  4.  
  5. EVENT_MANAGER:RegisterForEvent(AutoInvite.AddonId, EVENT_CHAT_MESSAGE_CHANNEL, AutoInvite.callback)
  Reply With Quote
10/01/14, 07:41 PM   #6
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Sasky View Post
Main event manager works fine too. I use that in AutoInvite:
Lua Code:
  1. AutoInvite.callback = function(_, messageType, from, message)
  2.     -- ...
  3. end
  4.  
  5. EVENT_MANAGER:RegisterForEvent(AutoInvite.AddonId, EVENT_CHAT_MESSAGE_CHANNEL, AutoInvite.callback)
This solution is probably the best one as it is completely independent on chat handlers, so it should always work.
If you don't need to modify chat output, this is what you are looking for.

Last edited by Garkin : 10/01/14 at 07:47 PM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » EVENT_CHAT_MESSAGE_CHANNEL Question


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