Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local onlyBossAlert = true;
- local deadGUIDs, pulledGUIDs, petOwners = {}, {}, {};
- local msgColor, npcColor = "FF6600", "B30000";
- local classColors = {
- ["DEATHKNIGHT"] = "C41F3B",
- ["DEMONHUNTER"] = "A330C9",
- ["DRUID"] = "FF7D0A",
- ["HUNTER"] = "ABD473",
- ["MAGE"] = "69CCF0",
- ["MONK"] = "00FF96",
- ["PALADIN"] = "F58CBA",
- ["PRIEST"] = "FFFFFF",
- ["ROGUE"] = "FFF569",
- ["SHAMAN"] = "0070DE",
- ["WARLOCK"] = "9482C9",
- ["WARRIOR"] = "C79C6E"
- };
- local ignoredSpells = {
- "Death Grip",
- "Imprison",
- "Hunter's Mark",
- "Beast Lore",
- "Flare",
- "Soothe",
- "Marked for Death",
- "Shadowstep",
- "Blind",
- "Sap",
- "Hex"
- };
- local function isIgnoredSpell(spellName)
- for _, ignoredSpellName in pairs(ignoredSpells) do
- if ignoredSpellName == spellName then
- return true;
- end
- end
- return false;
- end
- local function getClassColor(guid)
- local _, engClass = GetPlayerInfoByGUID(guid);
- if engClass then
- return classColors[engClass];
- end
- return nil;
- end
- local function isDead(guid)
- if deadGUIDs[guid] then
- return true;
- end
- return false;
- end
- local function isAlreadyPulled(guid)
- if pulledGUIDs[guid] then
- return true;
- end
- return false;
- end
- local function isBoss(guid)
- local _, _, _, _, _, mobID = strsplit("-", guid)
- if LibStub("LibBossIDs-1.0").BossIDs[tonumber(mobID)] then
- return true;
- end
- return false;
- end
- local function isInPVEInstance()
- local inInstance, instanceType = IsInInstance();
- if inInstance and (instanceType == "party" or instanceType == "raid") then
- return true;
- end
- return false;
- end
- local function isInPartyOrRaid()
- if GetNumGroupMembers(LE_PARTY_CATEGORY_HOME) > 0 or GetNumGroupMembers(LE_PARTY_CATEGORY_INSTANCE) > 0 then
- return true;
- end
- return false;
- end
- local function getPetOwner(petGUID)
- if petGUID then
- if petOwners[petGUID] then
- return petOwners[petGUID][1], petOwners[petGUID][2];
- end
- if UnitInRaid("player") then
- for i = 1, 40 do
- if UnitGUID("raidpet" .. i) == petGUID then
- return UnitGUID("raid" .. i), UnitName("raid" .. i);
- end
- end
- else -- player is alone or in party.
- if UnitGUID("pet") == petGUID then -- access to player's pet if alone or in a party the same way.
- return UnitGUID("player"), UnitName("player");
- end
- for i = 1, 4 do -- 4 members of the group.
- if UnitGUID("partypet" .. i) == petGUID then
- return UnitGUID("party" .. i), UnitName("party" .. i);
- end
- end
- end
- end
- return nil;
- end
- local function setColor(msg, color)
- return string.format("|cFF" .. color .. "%s|r", msg);
- end
- local function buildPullAlertMessage(event, isBodyPull, isPet, unitGUID, unitName, npcGUID, npcName, spellID, spellName)
- if (onlyBossAlert and not isBoss(npcGUID)) or isDead(npcGUID) then
- return nil;
- end
- local msg, classColor;
- npcName = setColor(npcName, npcColor);
- if string.find(event, "SWING") then
- spellLink = GetSpellLink("Auto Attack");
- else
- spellLink = GetSpellLink(spellID) or spellName;
- end
- if isPet then -- unitName == petName
- local petOwnerGUID, petOwnerName = getPetOwner(unitGUID);
- if petOwnerName then
- classColor = getClassColor(petOwnerGUID);
- petOwnerName = setColor(petOwnerName, classColor);
- if isBodyPull then
- msg = string.format("%s's %s body pulled %s.", petOwnerName, unitName, npcName);
- else
- msg = string.format("%s's %s pulled %s with " .. spellLink .. ".", petOwnerName, unitName, npcName);
- end
- else
- if isBodyPull then
- msg = string.format("%s (pet) body pulled %s.", unitName, npcName);
- else
- msg = string.format("%s (pet) pulled %s with " .. spellLink .. ".", unitName, npcName);
- end
- end
- else -- unitName == playerName
- classColor = getClassColor(unitGUID);
- unitName = setColor(unitName, classColor);
- if isBodyPull then
- msg = string.format("%s body pulled %s.", unitName, npcName);
- else
- msg = string.format("%s pulled %s with " .. spellLink .. ".", unitName, npcName);
- end
- end
- return msg;
- end
- function convertHexToRgb(hex)
- local hex = hex:gsub("#", "");
- if hex:len() == 3 then
- return (tonumber("0x" .. hex:sub(1, 1)) * 17) / 255, (tonumber("0x" .. hex:sub(2, 2)) * 17) / 255, (tonumber("0x" .. hex:sub(3, 3)) * 17) / 255;
- else
- return tonumber("0x" .. hex:sub(1, 2)) / 255, tonumber("0x" .. hex:sub(3, 4)) / 255, tonumber("0x" .. hex:sub(5, 6)) / 255;
- end
- end
- local function printAllChatFrames(msg, color)
- if msg then
- local r, g, b = convertHexToRgb(color);
- for i = 1, 20 do
- _G["ChatFrame" .. i]:AddMessage(msg, r, g, b);
- end
- end
- end
- local function whoTFPulled(...)
- local _, event, _, srcGUID, srcName, srcFlags, _, destGUID, destName, destFlags, _, spellID, spellName = select(1, ...);
- if event == "UNIT_DIED" then
- deadGUIDs[destGUID] = true;
- return;
- end
- if destName and srcName and destName ~= srcName and not string.find(event, "_RESURRECT") and not string.find(event, "_CREATE") and (string.find(event, "SWING") or string.find(event, "RANGE") or string.find(event, "SPELL")) then
- -- Register owners of special pets like Army of the Dead or Totems.
- if string.find(event, "_SUMMON") then
- petOwners[destGUID] = {srcGUID, srcName};
- return;
- end
- local isBodyPull, isPet;
- -- A player is attacking a mob.
- if bit.band(srcFlags, COMBATLOG_OBJECT_TYPE_PLAYER) ~= 0 and bit.band(destFlags, COMBATLOG_OBJECT_TYPE_NPC) ~= 0 then
- if not isAlreadyPulled(destGUID) and not isIgnoredSpell(spellName) then
- pulledGUIDs[destGUID] = true;
- isBodyPull = false;
- isPet = false;
- printAllChatFrames(buildPullAlertMessage(event, isBodyPull, isPet, srcGUID, srcName, destGUID, destName, spellID, spellName), msgColor);
- end
- -- A mob is attacking a player.
- elseif bit.band(destFlags, COMBATLOG_OBJECT_TYPE_PLAYER) ~= 0 and bit.band(srcFlags, COMBATLOG_OBJECT_TYPE_NPC) ~= 0 then
- if not isAlreadyPulled(srcGUID) then
- pulledGUIDs[srcGUID] = true;
- isBodyPull = true;
- isPet = false;
- printAllChatFrames(buildPullAlertMessage(event, isBodyPull, isPet, destGUID, destName, srcGUID, srcName, spellID, spellName), msgColor);
- end
- -- A player's pet attacks a mob.
- elseif bit.band(srcFlags, COMBATLOG_OBJECT_CONTROL_PLAYER) ~= 0 and bit.band(destFlags, COMBATLOG_OBJECT_TYPE_NPC) ~= 0 then
- if not isAlreadyPulled(destGUID) then
- pulledGUIDs[destGUID] = true;
- isBodyPull = false;
- isPet = true;
- printAllChatFrames(buildPullAlertMessage(event, isBodyPull, isPet, srcGUID, srcName, destGUID, destName, spellID, spellName), msgColor);
- end
- -- A mob attacks a player's pet.
- elseif bit.band(destFlags, COMBATLOG_OBJECT_CONTROL_PLAYER) ~= 0 and bit.band(srcFlags, COMBATLOG_OBJECT_TYPE_NPC) ~= 0 then
- if not isAlreadyPulled(srcGUID) then
- pulledGUIDs[srcGUID] = true;
- isBodyPull = true;
- isPet = true;
- printAllChatFrames(buildPullAlertMessage(event, isBodyPull, isPet, destGUID, destName, srcGUID, srcName, spellID, spellName), msgColor);
- end
- end
- end
- end
- local function eventHandler(self, event, ...)
- if event == "COMBAT_LOG_EVENT_UNFILTERED" then
- if isInPVEInstance() and isInPartyOrRaid() then
- whoTFPulled(...);
- else
- wipe(deadGUIDs);
- end
- elseif event == "PLAYER_REGEN_ENABLED" then
- -- print("PLAYER_REGEN_ENABLED");
- if not UnitIsDeadOrGhost("player") and not UnitIsFeignDeath("player") and not UnitAffectingCombat("pet") then
- -- print("PLAYER_REGEN_ENABLED: wipe pulledGUIDs");
- wipe(pulledGUIDs);
- wipe(petOwners);
- end
- elseif event == "PLAYER_ALIVE" then
- -- print("PLAYER_ALIVE");
- if not IsEncounterInProgress() and not UnitAffectingCombat("player") then
- -- print("PLAYER_ALIVE: wipe pulledGUIDs");
- wipe(pulledGUIDs);
- wipe(petOwners);
- end
- end
- end
- local frame = CreateFrame("Frame");
- frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
- frame:RegisterEvent("PLAYER_REGEN_ENABLED");
- frame:RegisterEvent("PLAYER_ALIVE");
- frame:SetScript("OnEvent", eventHandler);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement