This adds a button next to the quest "Accept" button labeled "Accept Track". When pressed the quest is accepted and quest tracking is turned on. It seems to be working ok, but thought I would put it here for review and see if there was something different I should have done.
AcceptAndTrack.toc
Lua Code:
## Interface: 100206
## Title: Accept And Track
## Notes: Adds an 'Accept and Track' button to quest frames.
## Author: Codger
## Version: 10.2.6
AcceptAndTrack.lua
AcceptAndTrack.lua
Lua Code:
local function AcceptAndTrackQuest()
AcceptQuest();
C_Timer.After(1, function() -- Delay to ensure the quest log is updated
local questID = GetQuestID();
if questID and not C_QuestLog.GetQuestWatchType(questID) then
C_QuestLog.AddQuestWatch(questID, Enum.QuestWatchType.Automatic);
-- No need to manually update the objective tracker anymore,
-- as the quest watch system handles it.
end
end)
end
local function CreateButton()
if not QuestFrameAcceptButton then return end -- Ensures the Accept button is loaded
local trackButton = CreateFrame("Button", "AcceptAndTrackButton", QuestFrame, "UIPanelButtonTemplate")
trackButton:SetSize(120, 22) -- Button size
trackButton:SetText("Accept And Track")
trackButton:SetPoint("TOPRIGHT", QuestFrameAcceptButton, "TOPRIGHT", 150, 0) -- Adjusted positioning
trackButton:SetScript("OnClick", AcceptAndTrackQuest)
trackButton:SetShown(QuestFrame:IsShown())
-- Debug print to chat to confirm the button was created
print("AcceptAndTrack button created.")
end
-- Delay button creation to ensure the QuestFrame is fully loaded
C_Timer.After(2, CreateButton)
QuestFrame:HookScript("OnShow", function() if AcceptAndTrackButton then AcceptAndTrackButton:SetShown(true) end end)
QuestFrame:HookScript("OnHide", function() if AcceptAndTrackButton then AcceptAndTrackButton:SetShown(false) end end)