Thread Tools Display Modes
07-17-17, 09:14 PM   #1
Cougarkillz
A Kobold Labourer
Join Date: Jul 2017
Posts: 1
Need a bit of help making a simple addon

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
  Reply With Quote
07-17-17, 10:01 PM   #2
d87
A Chromatic Dragonspawn
 
d87's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 163
C_Timer.After(duration, callback) – Calls the callback cafter duration seconds.
timer = C_Timer.NewTimer(duration, callback) – Calls callback after duration seconds. This is more expensive than C_Timer.After, so this only should be used if you need it to be cancellable.
timer:Cancel() – Cancels a timer
C_Timer.NewTimer is what you're asking i guess.
  Reply With Quote
07-18-17, 12:01 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Where is your GGframe.OnEvent function?

In any case, when the loot window closes, check to see if you are in combat. If not, equip your regular gloves. If you are, start a timer. I would use C_Timer.After (with a pre-defined function, not an anonymous one that would get recreated each time a timer is invoked). Every 5 seconds check your combat status. If still in combat, call another C_Timer.After.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need a bit of help making a simple addon


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