From 3568b8f760fbe815c23a1a2353a728cadc43bcf3 Mon Sep 17 00:00:00 2001 From: shagu Date: Sun, 3 Mar 2019 20:36:14 +0100 Subject: [PATCH] afkcam: delay afkcam when action is detected * delay on crafting/casting events * delay on auctionhouse events --- modules/afkcam.lua | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/modules/afkcam.lua b/modules/afkcam.lua index 6394b473..4bb4e831 100644 --- a/modules/afkcam.lua +++ b/modules/afkcam.lua @@ -138,19 +138,48 @@ pfUI:RegisterModule("afkcam", function () afkcam._spinning = false end + local delay = CreateFrame("Frame") + delay:Hide() + + delay:RegisterEvent("AUCTION_ITEM_LIST_UPDATE") + delay:SetScript("OnEvent", function() + this.delay = GetTime() + 5 + end) + + delay:SetScript("OnUpdate", function() + if ( this.tick or 0) > GetTime() then return else this.tick = GetTime() + 1 end + + local name = UnitName("player") + local cast = UnitCastingInfo(name) + if not cast then cast = UnitChannelInfo(name) end + if not this.delay then this.delay = 0 end + + if cast then + this.delay = GetTime() + 5 + end + + if this.delay < GetTime() then + afkcam:start() + this:Hide() + end + end) + afkcam:SetScript("OnEvent", function() if event == "CHAT_MSG_SYSTEM" then if (arg1 == _G.MARKED_AFK) or strfind(arg1, MARKED_AFK_CAPTURE) then - this:start() + delay:Show() elseif (arg1 == _G.CLEARED_AFK) then + delay:Hide() this:stop() end else if this._spinning then + delay:Hide() this:stop() end end end) + afkcam:RegisterEvent("CHAT_MSG_SYSTEM") afkcam:RegisterEvent("PLAYER_REGEN_DISABLED") afkcam:RegisterEvent("PLAYER_LEAVING_WORLD") -- reseting cvars on PLAYER_LOGOUT crashes the client ¯\_(ツ)_/¯