I've tweaked my personal ChatLogger Addon like this:
Lua Code:
local playerInCyro = false
local listenInTheseChannels = {
[CHAT_CHANNEL_EMOTE] = true,
[CHAT_CHANNEL_GUILD_1] = true,
[CHAT_CHANNEL_SAY] = true,
[CHAT_CHANNEL_PARTY] = true,
[CHAT_CHANNEL_WHISPER] = true,
[CHAT_CHANNEL_WHISPER_SENT] = true,
}
local function toggle(value)
local saveData = ChatLogger_Data[GetDisplayName()] or {}
ChatLogger_Data[GetDisplayName()] = saveData
if saveData.enabled == value then return end
SetChatLogEnabled(value)
saveData.enabled = value
end
local function enable()
toggle(true)
end
local function disable()
toggle(false)
end
local function ChatLogger_ToggleChatLog(eventCode, channelType, fromName, text, isCustomerService, fromDisplayName)
if listenInTheseChannels[channelType] then
if not playerInCyro and (channelType == CHAT_CHANNEL_SAY) then
enable()
end
end
end
local function ChatLogger_OnZoneChanged(eventCode, zoneName, subZoneName, newSubzone, zoneId, subZoneId)
playerInCyro = zoneName == "Cyrodiil"
end
EVENT_MANAGER:RegisterForEvent("ChatLogger", EVENT_ZONE_CHANGED, ChatLogger_OnZoneChanged)
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