Compare with Previous | Blame | View Log
local LW_Ver = 2.1 local LW_Compat = 2.1 function Initialise_LastWord_Options() lastwords_options = {} lastwords_options = { ["debug"] = false, ["collect"] = true, ["critters"] = {}, ["version"] = LW_Ver, ["startdate"] = date("%H:%M:%S, %a %b %d %Y"), } end function LastWords_OnEvent(event, ...) if (event=="COMBAT_LOG_EVENT_UNFILTERED") then local timestamp, combatevent, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags = ... if (combatevent=="PARTY_KILL") and (sourceGUID==UnitGUID("player")) then if lastwords_options["critters"][destName]~=nil or lastwords_critters[destGUID] then local iFLW = random(#(LastWords_FLW)); local LW_Message = LastWords_FLW[iFLW] LW_Message = gsub(LW_Message, "#n", (UnitName("player"))) LW_Message = gsub(LW_Message, "#c", (UnitClass("player"))) DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800"..destName.." said:|r "..LW_Message); if lastwords_options["critters"][destName] == nil then lastwords_options["critters"][destName] = 1 else lastwords_options["critters"][destName] = lastwords_options["critters"][destName] + 1 end end end elseif (event=="UPDATE_MOUSEOVER_UNIT") then LW_AddCreature("mouseover") elseif (event=="PLAYER_FOCUS_CHANGED") then LW_AddCreature("focus") elseif (event=="UNIT_TARGET") then local unitname = ... LW_AddCreature(unitname.."target") elseif (event=="VARIABLES_LOADED") then if lastwords_options == nil then Initialise_LastWord_Options(); end if lastwords_options["version"] == nil or lastwords_options["version"] < LW_Compat then Initialise_LastWord_Options(); end LWFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED"); if lastwords_options["collect"] == true then LWFrame:RegisterEvent("UPDATE_MOUSEOVER_UNIT"); LWFrame:RegisterEvent("UNIT_TARGET"); lastwords_critters = {} end SLASH_LASTWORDS1 = "/lastwords" SLASH_LASTWORDS2 = "/lw" SlashCmdList["LASTWORDS"] = LastWords_Command; DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800Last Words Loaded Successfully!|r"); end end function LW_AddCreature(creature) if UnitCreatureType(creature) == "Critter" and lastwords_options["critters"][(UnitName(creature))] == nil then local lwguid = UnitGUID(creature) lastwords_critters[lwguid] = true end end function LastWords_Command(cmd) local tbl = {} for v in string.gmatch(cmd, "[^ ]+") do tinsert(tbl, v) end if tbl[1] == "reset" then Initialise_LastWord_Options(); DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800Last Words Reset Successfully!|r"); --elseif tbl[1] == "add" then -- if (UnitName("target")) ~=nil then -- lastwords_options[(UnitName("target"))] = 0; -- DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800"..(UnitName("target")).." added.|r"); -- else -- DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800".."You need to target the critter you wish to add!|r"); -- end elseif tbl[1] == "report" then if tbl[2] == "r" or tbl[2] == "raid" then if GetNumRaidMembers > 0 then LW_Report("RAID") else DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800".."You are not in a raid!|r") end elseif tbl[2] == "g" or tbl[2] == "guild" then LW_Report("GUILD") elseif tbl[2] == "p" or tbl[2] == "party" then if GetNumPartyMembers() > 0 then LW_Report("PARTY") else DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800".."You are not in a party!|r") end elseif tbl[2] == "t" or tbl[2] == "test" then LW_Report("WHISPER") else local output output = "" for index,value in pairs(lastwords_options["critters"]) do if value ~= 0 then if value ==1 then output = output..value.." "..index..", "; else local CName if strsub(index, -1) == "y" then CName = strsub(index,1, -1).."ies" elseif strsub(index, -2) == "ch" then CName = index.."es" else CName = strsub(index,1, -1).."s" output = output..value.." "..CName..", "; end end end end if strlen(output)==0 then output = "|cFFFF8800So far you have mercilessly slaughtered:|r Nothing! Hoorah!"; else output = strsub(output, 1, -3) output = "|cFFFF8800So far you have slaughtered:|r "..output..". You Rotter!"; end DEFAULT_CHAT_FRAME:AddMessage(output); end else DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800Last Words accepts the following commands:|r") DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800reset:|r Resets all options to their default values.") --DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800add:|r Adds your current target to the list of critters.") DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800report:|r Sends a list of the critters you have slaughtered to the chat frame.") end end function LW_Report(channel) local index, value local total = 0 for index,value in pairs(lastwords_options["critters"]) do total = total + value end if total == 0 then SendChatMessage("Since "..lastwords_options["startdate"].." "..(UnitName("player")).." has not slaughtered a single critter! Hoorah!", channel, nil, (UnitName("player"))) else SendChatMessage("Since "..lastwords_options["startdate"].." "..(UnitName("player")).." has mercilessly slaughtered no less than "..total.." poor, innocent critters.", channel, nil, (UnitName("player"))) end end local frame = CreateFrame("Frame", "LWFrame"); frame:SetScript("OnEvent", function(self, event, ...) LastWords_OnEvent(event, ...) end); frame:RegisterEvent("VARIABLES_LOADED");