Last active
May 1, 2017 05:11
-
-
Save Romain-P/25092ffacc3c43709f11b6da591f3859 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if not defined then | |
| defined = true | |
| ArenaEnemies = { | |
| "arenapet1", | |
| "arenapet2", | |
| "arenapet3", | |
| "arena1", | |
| "arena2", | |
| "arena3", | |
| "arena1pet", | |
| "arena2pet", | |
| "arena3pet" | |
| } | |
| Enemies = { | |
| "target", | |
| "targettarget", | |
| "focustarget", | |
| "focus", | |
| "mouseover" | |
| } | |
| -- Return true if the player is playing in Arena | |
| function IsArena() | |
| return select(1, IsActiveBattlefieldArena()) == 1 | |
| end | |
| -- Return an enemy array depending on the current area of the player | |
| function GetEnemies() | |
| if select(1, IsActiveBattlefieldArena()) == 1 then | |
| return ArenaEnemies | |
| else | |
| return Enemies | |
| end | |
| end | |
| -- Return true if a given type is checked | |
| function ValidUnitType(unitType, unit) | |
| local isEnemyUnit = UnitCanAttack("player", unit) == 1 | |
| return (isEnemyUnit and unitType == "enemy") | |
| or (not isEnemyUnit and unitType == "friend") | |
| end | |
| -- Return if a given unit exists, isn't dead | |
| function ValidUnit(unit, unitType) | |
| return UnitExists(unit)==1 and ValidUnitType(unitType, unit) | |
| end | |
| realTargets = {} | |
| realTimeout = 0 | |
| realLastTarget = nil | |
| activeTarget = nil | |
| -- Return true if a given unit is targeting the player | |
| function IsTargetingPlayer(unit) | |
| local realTarget = realTargets[UnitName(unit)] | |
| return realTarget ~= nil and realTarget["real"] == "done" | |
| end | |
| -- create the frame | |
| local frame = CreateFrame("FRAME", nil, UIParent) | |
| frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") | |
| frame:SetScript("OnEvent", function(self, event, _, type, sourceGUID, sourceNAME, _, destGUID, destNAME, _, spellID) | |
| -- Check if player is the real target | |
| if type == "SPELL_CAST_START" then | |
| for _, unit in ipairs(GetEnemies()) do | |
| if ValidUnit(unit, "enemy") | |
| and select(1, UnitName(unit)) == sourceNAME then | |
| local profile = cancellables[spellID] | |
| if profile ~= nil then | |
| if activeTarget ~= nil then | |
| realLastTarget = activeTarget | |
| end | |
| ClearTarget() | |
| activeTarget = nil | |
| realTimeout = GetTime() | |
| local realTarget = realTargets[sourceNAME] | |
| if realTarget == nil then | |
| realTargets[sourceNAME] = { | |
| ["time"] = GetTime(), | |
| ["real"] = "no" | |
| } | |
| else | |
| realTargets[sourceNAME]["time"] = GetTime() | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| ) | |
| end | |
| -- In the pqr loop, global scope | |
| if UnitExists("target") then | |
| local name = UnitName("target") | |
| if activeTarget == nil then | |
| local realTarget = realTargets[name] | |
| if realTarget ~= nil and realTarget["real"] ~= "done" then | |
| if GetTime() - realTarget["time"] > 0.03 then | |
| realTargets[name] = nil | |
| else | |
| if realLastTarget ~= name then | |
| RunMacroText("/target "..realLastTarget) | |
| end | |
| realTimeout = 0 | |
| realTarget["real"] = "done" | |
| end | |
| end | |
| end | |
| activeTarget = name | |
| elseif realTimeout > 0 and GetTime() - realTimeout > 0.03 then | |
| if activeTarget == nil | |
| and realLastTarget ~= name then | |
| RunMacroText("/target "..realLastTarget) | |
| end | |
| realTimeout = 0 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment