Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Trans Faction (modified)
- Version : 2.1.0
- Date : 23/10/2012
- Author : Lenwë
- TODO:
- - Fix long repeating messages
- - Forbid listening other faction's characters.
- ]]
- -- ===========================================
- -- Core
- -- ===========================================
- local TransFaction_OldChatFrame_OnEvent
- -- TransFaction_InitVars()
- --
- -- Init configuration variables
- function TransFaction_InitVars()
- TransFactionVersion = 'v2.1.0'
- TransFactionForward = nil
- TransFactionIncomingMessages = {}
- TransFactionIncomingAddonMessages = {}
- TransFactionLastSentMessage = ''
- TransFactionListenList = {}
- end
- -- (string) TransFaction_Trim( (string) str)
- --
- -- Remove spaces at the beginning and end of the string and turns
- -- multiple spaces into a single one
- function TransFaction_Trim(str)
- if(s == nil) then return "" end
- str = string.gsub(str, "%s+", " ")
- str = string.gsub(str, "^%s", "")
- str = string.gsub(str, "%s$", "")
- return str
- end
- -- TransFaction_OnLoad()
- --
- -- Script initialization.
- function TransFaction_OnLoad()
- TransFaction_InitVars();
- TransFactionFrame:RegisterEvent("VARIABLES_LOADED")
- TransFactionFrame:RegisterEvent("CHAT_MSG_EMOTE")
- TransFactionFrame:RegisterEvent("CHAT_MSG_YELL")
- TransFactionFrame:RegisterEvent("CHAT_MSG_SAY")
- TransFactionFrame:RegisterEvent("CHAT_MSG_BN_WHISPER")
- TransFactionFrame:RegisterEvent("CHAT_MSG_RAID")
- TransFactionFrame:RegisterEvent("CHAT_MSG_RAID_LEADER")
- TransFactionFrame:SetScript("OnEvent", TransFaction_OnEvent)
- TransFaction_OldChatFrame_OnEvent = ChatFrame_MessageEventHandler
- ChatFrame_MessageEventHandler = TransFaction_ChatFrame_OnEvent
- end
- function TransFaction_ChatFrame_OnEvent(event, ... )
- local arg1, arg2 = ...
- if (arg2 ~= nil and string.find(arg2, "^TF¶")) then
- return
- end
- TransFaction_OldChatFrame_OnEvent(event, ...)
- end
- -- TransFaction_EnableForwarding((string) player)
- --
- -- Enable forwarding to player. Disable if player is nil
- function TransFaction_EnableForwarding(player)
- if ((player == '') or (player == nil)) then
- DEFAULT_CHAT_FRAME:AddMessage("Forwarding disabled.", 1, 0, 1)
- TransFactionForward = nil
- return
- end
- player = string.lower(player)
- local i, presenceID, presenceName, battleTag, isBattleTagPresence, toonName, toonID, client
- for i = 1, BNGetNumFriends(), 1 do
- presenceID, presenceName, battleTag, isBattleTagPresence, toonName, toonID, client = BNGetFriendInfo(i)
- if (client == BNET_CLIENT_WOW and toonName ~= nil and player == string.lower(toonName)) then
- DEFAULT_CHAT_FRAME:AddMessage("Forwarding enabled to " .. toonName .. ".", 1, 0, 1)
- TransFactionForward = presenceID
- return
- end
- end
- DEFAULT_CHAT_FRAME:AddMessage("Unknown player",1,0,0)
- PlaySoundFile("Sound\\interface\\Error.wav")
- end
- -- TransFaction_Listen((string) player)
- --
- -- Add player to listen list
- function TransFaction_Listen(player)
- if ((player == '') or (player == nil)) then
- local p, str
- DEFAULT_CHAT_FRAME:AddMessage("Listening to:", 1, 0, 1)
- str = ''
- for p,_ in pairs(TransFactionListenList) do
- str = str..' '..p
- end
- DEFAULT_CHAT_FRAME:AddMessage(str, 1, 0, 1)
- return
- end
- player = string.gsub(player, "-.+", "") -- Remove realm name
- player = TransFaction_UppercaseFirst(player)
- DEFAULT_CHAT_FRAME:AddMessage("Listening to "..player..".", 1, 0, 1)
- TransFactionListenList[player] = player
- end
- -- TransFaction_StopListen((string) player)
- --
- -- Remove player from listen list
- function TransFaction_StopListen(player)
- if ((player == '') or (player == nil)) then
- return
- end
- player = string.gsub(player, "-.+", "") -- Remove realm name
- player = TransFaction_UppercaseFirst(player)
- DEFAULT_CHAT_FRAME:AddMessage("No longer listening to "..player..".", 1, 0, 1)
- TransFactionListenList[player] = nil
- end
- -- TransFaction_ListenNone()
- --
- -- Clear listen list
- function TransFaction_ListenNone()
- DEFAULT_CHAT_FRAME:AddMessage("No longer listening to anyone.", 1, 0, 1)
- TransFactionListenList = {}
- end
- -- TransFaction_SendAddonMessage(message)
- --
- -- Forward chat message to other player
- function TransFaction_SendAddonMessage(message)
- if (TransFactionForward == nil) then
- return
- end
- local chunk, word, space
- message = string.gsub(message, '|', '¦')
- while (message ~= "") do
- chunk = string.sub(message, 1, 240)
- message = string.sub(message, 241)
- if (message == "") then
- chunk = chunk .. '¶'
- end
- BNSendWhisper(TransFactionForward, 'TF¶' .. chunk)
- end
- end
- -- (string) TransFaction_UppercaseFirst( (string) str)
- --
- -- Return the lowercase string str with the first letter capitalized
- -- Multibyte support
- function TransFaction_UppercaseFirst(str)
- local i = 1
- while (string.len(string.upper(string.sub(str, 1, i))..string.lower(string.sub(str, i + 1))) < string.len(str)) do
- i = i + 1
- end
- return string.upper(string.sub(str, 1, i))..string.lower(string.sub(str, i + 1))
- end
- -- TransFaction_OnEvent(this, event, ...)
- --
- -- Event handler
- function TransFaction_OnEvent(this, event, ...)
- local element, chunk, player
- local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 = ...
- -- Init saved variables
- if (event == "VARIABLES_LOADED") then
- local s = string.gsub('TransFaction VERSION loaded.', "VERSION", TransFactionVersion)
- DEFAULT_CHAT_FRAME:AddMessage(s,1,1,1)
- return
- -- AddonMessage
- elseif (event == "CHAT_MSG_BN_WHISPER") then
- chunk = string.match(arg1, "^TF¶(.*)")
- if (chunk == nil) then
- return
- end
- -- Add chunk to message
- if (TransFactionIncomingAddonMessages[arg13] == nil) then
- TransFactionIncomingAddonMessages[arg13] = chunk
- else
- TransFactionIncomingAddonMessages[arg13] = TransFactionIncomingAddonMessages[arg13] .. chunk
- end
- -- Final message received:
- if (string.find(TransFactionIncomingAddonMessages[arg13], "¶$")) then
- local addonMessage = string.gsub(TransFactionIncomingAddonMessages[arg13], '¶', '')
- addonMessage = string.gsub(addonMessage, '¦', '|')
- TransFactionIncomingAddonMessages[arg13] = nil
- TransFaction_ExecuteCommand(addonMessage)
- end
- -- Get an incoming chat message
- else
- -- Forwarding disabled : skip
- if (TransFactionForward == nil) then
- return
- end
- -- Player not in listen list
- player = string.gsub(arg2, "-.+", "") -- Remove realm name
- if (TransFactionListenList[player] == nil) then
- return
- end
- -- I told that !
- if ((arg1 == string.sub(TransFactionLastSentMessage, 1, 255)) and (arg2 == UnitName("player"))) then
- return
- end
- local mode = ''
- local param = ''
- local s1, s2
- local message = arg1
- if (event == "CHAT_MSG_SAY") then
- command = 'S '..arg2..': '..message
- elseif (event == "CHAT_MSG_YELL") then
- command = 'Y '..arg2..': '..message
- elseif (event == "CHAT_MSG_EMOTE") then
- command = 'S ** '..arg2..' '..message..' **'
- elseif ((event == "CHAT_MSG_RAID") or (event == "CHAT_MSG_RAID_LEADER")) then
- command = 'R '..arg2..': '..message
- else
- return
- end
- -- Foward to other character
- TransFaction_SendAddonMessage(command)
- end
- end
- -- TransFaction_ExecuteCommand((string) commandLine)
- --
- -- Execute the given command
- function TransFaction_ExecuteCommand(commandLine)
- local c, a, a1, a2
- local commandName, args, arg1, arg2
- -- Get command and parameters
- commandName = ''
- args = ''
- arg1 = ''
- arg2 = ''
- for c, a in string.gmatch(commandLine, "%s*(%a+)%s*(.*)") do
- if (c == nil) then commandName = '' else commandName = string.lower(c) end
- if (a == nil) then args = '' else args = a end
- for a1, a2 in string.gmatch(args, "%s*([^%s]+)%s*(.*)") do
- if (a1 == nil) then arg1 = '' else arg1 = a1 end
- if (a2 == nil) then arg2 = '' else arg2 = a2 end
- end
- end
- local player = args
- if ((player == nil) or string.find(player, "^%s*$")) then
- player = UnitName("target")
- end
- if (commandName == "forward") then
- TransFaction_EnableForwarding(player)
- elseif (commandName == "listen") then
- TransFaction_Listen(player)
- elseif (commandName == "stoplisten") then
- TransFaction_StopListen(player)
- elseif (commandName == "listennone") then
- TransFaction_ListenNone()
- elseif (commandName == "s") then
- TransFactionLastSentMessage = args
- SendChatMessage(args, 'SAY')
- elseif (commandName == "y") then
- TransFactionLastSentMessage = args
- SendChatMessage(args, 'YELL')
- elseif (commandName == "e") then
- TransFactionLastSentMessage = args
- SendChatMessage(args, 'EMOTE')
- elseif (commandName == "r") then
- TransFactionLastSentMessage = arg2
- SendChatMessage(arg2, 'RAID')
- else
- DEFAULT_CHAT_FRAME:AddMessage("Unknown command",1,0,0)
- PlaySoundFile("Sound\\interface\\Error.wav")
- end
- end
- -- ===========================================
- -- slash commands
- -- ===========================================
- -- /trans option [value [value2]..]
- --
- --
- SlashCmdList["TRANS"] = TransFaction_ExecuteCommand
- SLASH_TRANS1 = "/trans"
- SLASH_TRANS2 = "/tf"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement