View Single Post
04/25/17, 12:08 AM   #6
manavortex
 
manavortex's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 138
I've tweaked my personal ChatLogger Addon like this:

Lua Code:
  1. local playerInCyro = false
  2.  
  3. local listenInTheseChannels = {
  4.     [CHAT_CHANNEL_EMOTE] = true,
  5.     [CHAT_CHANNEL_GUILD_1] = true,
  6.     [CHAT_CHANNEL_SAY] = true,
  7.     [CHAT_CHANNEL_PARTY] = true,
  8.     [CHAT_CHANNEL_WHISPER] = true,
  9.     [CHAT_CHANNEL_WHISPER_SENT] = true,
  10. }
  11.  
  12. local function toggle(value)
  13.     local saveData = ChatLogger_Data[GetDisplayName()] or {}
  14.     ChatLogger_Data[GetDisplayName()] = saveData
  15.     if saveData.enabled == value then return end
  16.     SetChatLogEnabled(value)
  17.     saveData.enabled = value
  18. end
  19.  
  20. local function enable()
  21.    toggle(true)
  22. end
  23.  
  24. local function disable()
  25.     toggle(false)
  26. end
  27.  
  28. local function ChatLogger_ToggleChatLog(eventCode, channelType, fromName, text, isCustomerService, fromDisplayName)
  29.     if listenInTheseChannels[channelType] then
  30.         if not playerInCyro and (channelType == CHAT_CHANNEL_SAY) then
  31.             enable()
  32.         end
  33.     end
  34. end
  35.  
  36. local function ChatLogger_OnZoneChanged(eventCode, zoneName, subZoneName, newSubzone, zoneId, subZoneId)
  37.     playerInCyro = zoneName == "Cyrodiil"
  38. end
  39.  
  40. EVENT_MANAGER:RegisterForEvent("ChatLogger", EVENT_ZONE_CHANGED, ChatLogger_OnZoneChanged)
  41. EVENT_MANAGER:RegisterForEvent("ChatLogger", EVENT_CHAT_MESSAGE_CHANNEL, ChatLogger_ToggleChatLog)


You can simply run SetChatLogEnabled(true) via binder though. No need for an if-statement.

Also, if you separate the lines by ; you can make inline statements: If (condition) then do this; else do that; end

Hope that helps you
  Reply With Quote