Since It's simple, I'm gonna include the code and then explain what it does under the code:
Code:
local MINING_GLOVES = "Grips of Damnation"
local HERBALISM_GLOVES = "Forager's Gloves"
local COMBAT_GLOVES = "Gorepetal's Gentle Grasp"
local HERBALISM_TEXT = "Herbalism"
local MINING_TEXT = "Mining"
local GameTooltip = GameTooltip
local GameTooltipTextLeft2 = GameTooltipTextLeft2
local EquipItemByName = EquipItemByName
local Fighting = 2
local GGframe = CreateFrame("FRAME");
GGframe:RegisterEvent("LOOT_CLOSED");
local function ScanTooltip()
if GameTooltip:NumLines() ~= 2 then return end
local text = GameTooltipTextLeft2:GetText()
if UnitAffectingCombat("player") then
else
if text:find(MINING_TEXT) then
inFight()
if Fighting == 3 then
elseif Fighting == 4 then
EquipItemByName(MINING_GLOVES)
inFight()
if Fighting == 3 then
elseif Fighting == 4 then
if event == "LOOT_CLOSED" then
EquipItemByName(COMBAT_GLOVES)
else
C_Timer.After(5, CombatGloves)
end
end
end
elseif text:find(HERBALISM_TEXT) then
inFight()
if Fighting == 3 then
elseif Fighting == 4 then
EquipItemByName(HERBALISM_GLOVES)
inFight()
if Fighting == 3 then
elseif Fighting == 4 then
if event == "LOOT_CLOSED" then
EquipItemByName(COMBAT_GLOVES)
else
C_Timer.After(5, CombatGloves)
end
end
end
end
end
end
function CombatGloves()
if UnitAffectingCombat("player")
then C_Timer.After(5, CombatGloves)
else
EquipItemByName(COMBAT_GLOVES)
end
end
function inFight()
if UnitAffectingCombat("player")
then Fighting = 3
else Fighting = 4
end
end
GGframe:SetScript("OnEvent", GGframe.OnEvent);
GameTooltip:HookScript("OnTooltipSetDefaultAnchor", function(self)
self:SetWidth(1)
end)
GameTooltip:HookScript("OnSizeChanged", ScanTooltip)
Okay so... What I'm trying to accomplish is a simple glove switching addon for gathering. I've pieced together what I currently have and been learning how to do this on the fly (sorry if the code is a mess).
What it currently does: When I hover over an herb or ore node, it checks the tooltip to see if it says "Herbalism" or "Mining". If it says herbalism, it checks to see if you are in combat. If you are, it does nothing. If you aren't it equips the gloves typed in for the herbalism slot. Mining does the mining gloves.
It then waits 5 seconds, and checks to see if you are in combat (and goes into a loop, checking the combat every 5 seconds) until you are out of combat so it can equip the Combat Gloves.
What I want it to do: An extra step that equips gloves as the loot window closes. So, you hover over a node, it equips your gloves, you swoop down and grab it, and then once the window closes, instead of waiting the next 2-3 secs, it equips your combat gloves right then.
The problem I'm having: I can make it activate when the loot window closes. I can make it activate on a timer that waits 5 seconds. I can NOT for the life of me figure out how to do both. I'd like it to activate with the timer, and then if the loot window closes before the 5 seconds are up then the timer becomes obsolete and it equips the combat gloves right then.
Right now, with the current code, it completely skips over the loot window closing and equips gloves after 5 seconds.
I've been trying to figure this out on my own without having anyone else write it for me, but this is as far as I've been able to get (after around 10 hours of trial and error testing to even get this far >.<). If anyone knows a solution, I'd really appreciate it =-b