Thread Tools Display Modes
Prev Previous Post   Next Post Next
02-24-15, 06:45 AM   #1
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
Enable addon only if glyphe and Class is right

OK I just found this nice MindHarvest AddOn by Alea. Not uploaded on any wow addon side thought. I have optimized the icon and position a bit to fit my nameplates.

Now I have a question, coud someone help me to add a check so that the addon:
1. Is only active if your class is Priest - no icon for other classes
2. Only showing the icon if you have Glyph of Mind Harvest active.

That woud be realy great

Lua Code:
  1. local core = CreateFrame("Frame")
  2. core:SetScript("OnEvent", function(self, event, ...)   
  3.     self[event](self, event, ...)
  4. end)
  5.  
  6. core.CreatedPlates = {}
  7. core.MindHarvest = {}
  8. core.ByBossName = {}
  9. core.ByName = {}
  10.  
  11. local numChildren = -1
  12. local twipe = table.wipe
  13. local tsort = table.sort
  14. local tinsert = table.insert
  15. local band = bit.band
  16. local gsub = string.gsub
  17. local tolower = string.lower
  18. local match = string.match
  19.  
  20. core.RaidTargetReference = {
  21.     ["STAR"] = 0x00000001,
  22.     ["CIRCLE"] = 0x00000002,
  23.     ["DIAMOND"] = 0x00000004,
  24.     ["TRIANGLE"] = 0x00000008,
  25.     ["MOON"] = 0x00000010,
  26.     ["SQUARE"] = 0x00000020,
  27.     ["CROSS"] = 0x00000040,
  28.     ["SKULL"] = 0x00000080,
  29. }
  30.  
  31. core.ByRaidIcon = {}
  32.  
  33. core.RaidIconCoordinate = {
  34.     [0]     = { [0]     = "STAR", [0.25]    = "MOON", },
  35.     [0.25]  = { [0]     = "CIRCLE", [0.25]  = "SQUARE", },
  36.     [0.5]   = { [0]     = "DIAMOND", [0.25] = "CROSS", },
  37.     [0.75]  = { [0]     = "TRIANGLE", [0.25]    = "SKULL", },
  38. }
  39.  
  40. local flagtort = {
  41.    [COMBATLOG_OBJECT_RAIDTARGET8] = "SKULL",
  42.    [COMBATLOG_OBJECT_RAIDTARGET7] = "CROSS",
  43.    [COMBATLOG_OBJECT_RAIDTARGET6] = "SQUARE",
  44.    [COMBATLOG_OBJECT_RAIDTARGET5] = "MOON",
  45.    [COMBATLOG_OBJECT_RAIDTARGET4] = "TRIANGLE",
  46.    [COMBATLOG_OBJECT_RAIDTARGET3] = "DIAMOND",
  47.    [COMBATLOG_OBJECT_RAIDTARGET2] = "CIRCLE",
  48.    [COMBATLOG_OBJECT_RAIDTARGET1] = "STAR",
  49.  }
  50.  
  51. local blacklist = {}
  52.  
  53. function core:CheckFilter(myPlate)
  54.     local name = gsub(self.mindHarvest.name:GetText(), '%s%(%*%)','')
  55.     local db = blacklist[name]
  56.  
  57.     if db and db.enable then
  58.         if db.hide then
  59.             myPlate:Hide()
  60.             return
  61.         else
  62.             if(not myPlate:IsShown()) then
  63.                 myPlate:Show()
  64.             end
  65.         end
  66.     elseif(not myPlate:IsShown()) then
  67.         myPlate:Show()
  68.     end
  69.     return true
  70. end
  71.  
  72. function core:ScanFrames(...)
  73.     for index = 1, select('#', ...) do
  74.         local frame = select(index, ...)
  75.         local name = frame:GetName()
  76.        
  77.         if(not core.CreatedPlates[frame] and (name and name:find("NamePlate%d"))) then
  78.             core:CreatePlate(frame)
  79.         end
  80.     end
  81. end
  82.  
  83. function core:UpdateMindHarvestStatus(frame)
  84.  
  85.  
  86.     if frame.mindHarvest.guid and core.MindHarvest[frame.mindHarvest.guid] then
  87.         frame.mindHarvest:Hide()
  88.     else   
  89.         frame.mindHarvest:Show()
  90.        
  91.         if frame.mindHarvest.guid then
  92.             frame.mindHarvest.status:SetText("|cff66ff00+|r")
  93.         else
  94.             frame.mindHarvest.status:SetText("|cffff0000?|r")
  95.         end
  96.     end
  97.    
  98. end
  99.  
  100. function core:SetUnitInfo(myPlate)
  101.     local plateName = gsub(self.mindHarvest.name:GetText(), '%s%(%*%)','')
  102.     if self:GetAlpha() == 1 and core.targetName and (core.targetName == plateName) then
  103.         self.mindHarvest.guid = UnitGUID("target")
  104.        
  105.         self.mindHarvest.unit = "target"
  106.        
  107.         core:UpdateMindHarvestStatus(self)
  108.        
  109.         self.mindHarvest:SetFrameLevel(2)
  110.        
  111.         if((core.NumTargetChecks > -1) or self.mindHarvest.allowCheck) then
  112.             core.NumTargetChecks = core.NumTargetChecks + 1
  113.             if core.NumTargetChecks > 0 then
  114.                 core.NumTargetChecks = -1
  115.             end
  116.  
  117.             self.mindHarvest.allowCheck = nil
  118.         end
  119.  
  120.     elseif self.mindHarvest.highlight:IsShown() and UnitExists("mouseover") and (UnitName("mouseover") == plateName) then
  121.         self.mindHarvest.guid = UnitGUID("mouseover")
  122.        
  123.         if(self.mindHarvest.unit ~= "mouseover" or self.mindHarvest.allowCheck) then   
  124.             self.mindHarvest.allowCheck = nil
  125.         end
  126.        
  127.        
  128.         core:UpdateMindHarvestStatus(self)
  129.        
  130.         self.mindHarvest:SetFrameLevel(1)
  131.        
  132.         self.mindHarvest.unit = "mouseover"    
  133.     else
  134.         self.mindHarvest.unit = nil
  135.        
  136.         self.mindHarvest:SetFrameLevel(0)
  137.        
  138.         core:UpdateMindHarvestStatus(self)
  139.     end
  140. end
  141.  
  142. function core:OnHide()
  143.     local myPlate = core.CreatedPlates[self]
  144.     self.mindHarvest.unitType = nil
  145.     self.mindHarvest.guid = nil
  146.     self.mindHarvest.unit = nil
  147.     self.mindHarvest.allowCheck = nil
  148.  
  149.     myPlate:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT") --Prevent nameplate being in random location on screen when first shown
  150. end
  151.  
  152. function core:OnShow()
  153.     local myPlate = core.CreatedPlates[self]
  154.     if(not core.CheckFilter(self, myPlate)) then return end
  155.  
  156.     core.ColorizeAndScale(self, myPlate)
  157.     core:CheckRaidIcon(self)
  158.     self.mindHarvest.allowCheck = true
  159. end
  160.  
  161. function core:CreatePlate(frame)
  162.    
  163.     local mindHarvest = CreateFrame("Frame", nil, self.ParentFrame)
  164.     mindHarvest:SetSize(18, 18)
  165.    
  166.     mindHarvest.barFrame, mindHarvest.nameFrame = frame:GetChildren()
  167.     mindHarvest.healthBar = mindHarvest.barFrame:GetChildren()
  168.    
  169.     mindHarvest.threat, _, mindHarvest.highlight, _, mindHarvest.bossIcon, mindHarvest.raidIcon = mindHarvest.barFrame:GetRegions()
  170.     mindHarvest.name = mindHarvest.nameFrame:GetRegions()
  171.    
  172.    
  173.     if not mindHarvest.raidIcon and frame.icon then
  174.         mindHarvest.raidIcon = frame.icon
  175.     end
  176.    
  177.     if(self.viewPort) then
  178.         mindHarvest:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT")
  179.     end
  180.    
  181.     mindHarvest:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT")
  182.    
  183.     mindHarvest:SetFrameStrata("BACKGROUND")
  184.     mindHarvest:SetFrameLevel(0)
  185.     mindHarvest:SetScale(0.7) -- update
  186.    
  187.     mindHarvest.iconf = CreateFrame("Frame", nil, mindHarvest)
  188.     mindHarvest.iconf:SetSize(18, 18)
  189.     mindHarvest.iconf:SetPoint("BOTTOMLEFT", mindHarvest, "TOPLEFT", 0, 20)
  190.    
  191.    
  192.     mindHarvest.icon = mindHarvest.iconf:CreateTexture(nil, 'OVERLAY')
  193.     mindHarvest.icon:SetTexCoord(.1, .9, .2, .8)
  194.     mindHarvest.icon:SetTexture("Interface\\icons\\spell_warlock_harvestoflife")
  195.     mindHarvest.icon:SetAllPoints(mindHarvest.iconf)
  196.    
  197.     mindHarvest.status = mindHarvest.iconf:CreateFontString(nil, 'OVERLAY')
  198.     mindHarvest.status:SetPoint("CENTER", mindHarvest.iconf, "CENTER", 1, -1)
  199.     mindHarvest.status:SetJustifyH("LEFT")
  200.     mindHarvest.status:SetFont(STANDARD_TEXT_FONT, 16, "THICKOUTLINE")
  201.    
  202.     mindHarvest.status:SetText("TEST")
  203.  
  204.     mindHarvest:Show()
  205.    
  206.     frame.mindHarvest = mindHarvest
  207.    
  208.     frame:HookScript("OnShow", core.OnShow)
  209.     frame:HookScript("OnHide", core.OnHide)
  210.    
  211.     self.CreatedPlates[frame] = mindHarvest
  212. end
  213.  
  214. function core:SetAlpha(plate)
  215.     if self:GetAlpha() < 1 then
  216.         plate:SetAlpha(0.7)
  217.     else
  218.         plate:SetAlpha(1)
  219.     end
  220. end
  221.  
  222. function core:OnUpdate(elapsed)
  223.  
  224.     local count = WorldFrame:GetNumChildren()
  225.     if(count ~= numChildren) then
  226.         numChildren = count
  227.         core:ScanFrames(WorldFrame:GetChildren())
  228.     end
  229.    
  230.     core.PlateParent:Hide()
  231.     for blizzPlate, plate in pairs(core.CreatedPlates) do
  232.         if(blizzPlate:IsShown()) then
  233.             if(not self.viewPort) then
  234.                 plate:SetPoint("CENTER", WorldFrame, "BOTTOMLEFT", blizzPlate:GetCenter())
  235.             end
  236.            
  237.             core.SetAlpha(blizzPlate, plate)
  238.            
  239.         else
  240.             plate:Hide()
  241.         end
  242.     end
  243.     core.PlateParent:Show()
  244.    
  245.     if(self.mindharvest and self.mindharvest > 0.2) then
  246.         for blizzPlate, plate in pairs(core.CreatedPlates) do
  247.             if(blizzPlate:IsShown() and plate:IsShown()) then
  248.                 core.SetUnitInfo(blizzPlate, plate)
  249.                 core.ColorizeAndScale(blizzPlate, plate)
  250.             end
  251.         end
  252.  
  253.         self.mindharvest = 0
  254.     else
  255.         self.mindharvest = (self.mindharvest or 0) + elapsed
  256.     end
  257.    
  258. end
  259.  
  260. function core:RoundColors(r, g, b) 
  261.     return floor(r*100+.5)/100, floor(g*100+.5)/100, floor(b*100+.5)/100
  262. end
  263.  
  264. function core:GetReaction(frame)
  265.     local r, g, b = core:RoundColors(frame.mindHarvest.healthBar:GetStatusBarColor())
  266.  
  267.     for class, _ in pairs(RAID_CLASS_COLORS) do
  268.         local bb = b
  269.         if class == 'MONK' then
  270.             bb = bb - 0.01
  271.         end
  272.        
  273.         if RAID_CLASS_COLORS[class].r == r and RAID_CLASS_COLORS[class].g == g and RAID_CLASS_COLORS[class].b == bb then
  274.             return class
  275.         end
  276.     end
  277.  
  278.     if (r + b + b) == 1.59 then
  279.         return 'TAPPED_NPC'
  280.     elseif g + b == 0 then
  281.         return 'HOSTILE_NPC'
  282.     elseif r + b == 0 then
  283.         return 'FRIENDLY_NPC'
  284.     elseif r + g > 1.95 then
  285.         return 'NEUTRAL_NPC'
  286.     elseif r + g == 0 then
  287.         return 'FRIENDLY_PLAYER'
  288.     else
  289.         return 'HOSTILE_PLAYER'
  290.     end
  291. end
  292.  
  293. function core:ColorizeAndScale(myPlate)
  294.     self.mindHarvest.unitType = core:GetReaction(self) 
  295. end
  296.  
  297. core:RegisterEvent("PLAYER_LOGIN") 
  298.  
  299. function core:UPDATE_MOUSEOVER_UNIT()
  300.     WorldFrame.mindharvest = 0.1
  301. end
  302.  
  303.  
  304. function core:PLAYER_TARGET_CHANGED()
  305.     if(UnitExists("target")) then
  306.         self.targetName = UnitName("target")
  307.         WorldFrame.mindharvest = 0.1
  308.         core.NumTargetChecks = 0
  309.     else
  310.         self.targetName = nil
  311.     end
  312. end
  313.  
  314. function core:INSTANCE_ENCOUNTER_ENGAGE_UNIT()
  315.     for i=1, MAX_BOSS_FRAMES do
  316.         local unit = format("boss%d", i)
  317.        
  318.         if UnitExists(unit) then --and UnitClassification(unit) == "worldboss" then
  319.             core.ByBossName[UnitName(unit)] = UnitGUID(unit)
  320.         end
  321.     end
  322. end
  323.  
  324. function core:ARENA_OPPONENT_UPDATE()
  325.     for i=1, 5 do
  326.         local unit = format("arena%d", i)
  327.        
  328.         if UnitExists(unit) then --and UnitClassification(unit) == "worldboss" then
  329.             core.ByName[UnitName(unit)] = UnitGUID(unit)
  330.         end
  331.        
  332.     end
  333. end
  334. local function MindHarvestAssist(destGUID,destName,destFlags,destRaidFlags)
  335.     if destGUID and not core.MindHarvest[destGUID] then
  336.         local name, raidIcon
  337.        
  338.         if band(destFlags, COMBATLOG_OBJECT_CONTROL_PLAYER) > 0 and destName then
  339.             local rawName = strsplit("-", destName)         -- Strip server name from players
  340.             core.ByName[rawName] = destGUID
  341.             name = rawName
  342.         end
  343.        
  344.         if flagtort[destRaidFlags] then
  345.             core.ByRaidIcon[flagtort[destRaidFlags]] = destGUID
  346.             raidIcon = flagtort[destRaidFlags]
  347.         end
  348.        
  349.         if core.ByBossName[destName] and destName then
  350.             name = destName
  351.         end
  352.  
  353.         core.MindHarvest[destGUID] = true
  354.     end
  355. end
  356.  
  357. function core:COMBAT_LOG_EVENT_UNFILTERED(_, _, event, ...)
  358.     local _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellID, spellName, _, auraType, stackCount  = ...
  359.  
  360.     if event == "SPELL_DAMAGE" and sourceGUID == UnitGUID("player") and spellID == 8092 then
  361.         MindHarvestAssist(destGUID,destName,destFlags,destRaidFlags)
  362.     end
  363.    
  364.     if  event == "SPELL_AURA_APPLIED" or
  365.         event == "SPELL_AURA_REFRESH" or
  366.         event == "SPELL_AURA_APPLIED_DOSE" or
  367.         event == "SPELL_AURA_REMOVED_DOSE" or
  368.         event == "SPELL_AURA_BROKEN" or
  369.         event == "SPELL_AURA_BROKEN_SPELL" or
  370.         event == "SPELL_AURA_REMOVED" then 
  371.  
  372.         local name, raidIcon
  373.         if band(destFlags, COMBATLOG_OBJECT_CONTROL_PLAYER) > 0 and destName then
  374.             local rawName = strsplit("-", destName)         -- Strip server name from players
  375.             core.ByName[rawName] = destGUID
  376.         end
  377.  
  378.         if flagtort[destRaidFlags] then
  379.             core.ByRaidIcon[flagtort[destRaidFlags]] = destGUID
  380.             raidIcon = flagtort[destRaidFlags]
  381.         end
  382.     end
  383. end
  384.  
  385. function core:PLAYER_LOGIN()
  386.  
  387.     self.PlateParent = CreateFrame("Frame", nil, WorldFrame)
  388.     self.PlateParent:SetFrameStrata("BACKGROUND")
  389.     self.PlateParent:SetFrameLevel(0)  
  390.     WorldFrame:HookScript('OnUpdate', core.OnUpdate)
  391.    
  392.     self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  393.     self:RegisterEvent("PLAYER_TARGET_CHANGED")
  394.     self:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
  395.     self:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT")
  396.     self:RegisterEvent("ARENA_OPPONENT_UPDATE")
  397. end
  398.  
  399. function core:CheckRaidIcon(frame)
  400.     if frame.mindHarvest.raidIcon:IsShown() then
  401.         local ux, uy = frame.mindHarvest.raidIcon:GetTexCoord()
  402.         frame.mindHarvest.raidIconType = core.RaidIconCoordinate[ux][uy]   
  403.     else
  404.         frame.mindHarvest.raidIconType = nil;
  405.     end
  406. end
  407.  
  408. function core:SearchNameplateByGUID(guid)
  409.     for frame, _ in pairs(core.CreatedPlates) do
  410.         if frame and frame:IsShown() and frame.mindHarvest.guid == guid then
  411.             return frame
  412.         end
  413.     end
  414. end
  415.  
  416. function core:SearchNameplateByName(sourceName)
  417.     if not sourceName then return; end
  418.     local SearchFor = strsplit("-", sourceName)
  419.  
  420.     for frame, myPlate in pairs(core.CreatedPlates) do
  421.         if frame and frame:IsShown() then
  422.             if ( myPlate.mindHarvest.nameText == SearchFor and RAID_CLASS_COLORS[frame.mindHarvest.unitType] ) then
  423.                 return frame
  424.             elseif ( core.ByBossName[sourceName] and frame.mindHarvest.name:GetText() == sourceName ) then         
  425.                 return frame
  426.             end
  427.         end
  428.     end
  429. end
  430.  
  431. function core:SearchNameplateByIconName(raidIcon)
  432.     for frame, _ in pairs(core.CreatedPlates) do
  433.         core:CheckRaidIcon(frame)
  434.         if frame and frame:IsShown() and frame.mindHarvest.raidIcon:IsShown() and (frame.mindHarvest.raidIconType == raidIcon) then
  435.             return frame
  436.         end
  437.     end    
  438. end
  439.  
  440. function core:SearchForFrame(guid, raidIcon, name)
  441.     local frame
  442.  
  443.     if guid then frame = self:SearchNameplateByGUID(guid) end
  444.     if (not frame) and name then frame = self:SearchNameplateByName(name) end
  445.     if (not frame) and raidIcon then frame = self:SearchNameplateByIconName(raidIcon) end
  446.  
  447. end
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Enable addon only if glyphe and Class is right


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off