WoWInterface - View Single Post - Shadowlands API changes?
View Single Post
08-29-20, 11:43 AM   #11
A Chromatic Dragonspawn
Join Date: Mar 2009
Posts: 181
I've asked about the API changes because my good old lua code seems to have stopped working in 9.x. It's a simple code to print out quest IDs into chat if any quest is accepted or completed. (useful for tracking hidden quests)

    local RealQuestBlacklist = {} -- [questID] = true, Ignore any questIDs in the list
    local QUEST_TIMEOUT = 1
    local function ScrapeQTip(self)
        local tipName = self:GetName()
        local name, description = _G[tipName .. 'TextLeft1']:GetText(), _G[tipName ..'TextLeft3']:GetText()
        if name then
            print(format('Quest Completed: |cffffff00|Hquest:%d|h[%s]|h|r (%d) %s', self.questID, name, self.questID, description or ''))
        elseif self.questID ~= 0 then
            print('Quest Completed: |cffffff00' .. self.questID)
        self:SetScript('OnTooltipSetQuest', nil) -- If it gets to this point we don't want this potentially firing again
        self.questID = nil
    local QTips = {}
    local function GetQTip() -- Recycle old tooltip or create new one if none available
        local now = GetTime()
        for i, tip in ipairs(QTips) do
            if not tip.questID or now - tip.lastUpdate > QUEST_TIMEOUT then -- If it hasn't finished within this time frame then recycle it anyway
                tip.lastUpdate = now
                return tip
        local tip = CreateFrame('GameTooltip',  'SemlarsQTip' .. (#QTips + 1), WorldFrame, 'GameTooltipTemplate')
        tip.lastUpdate = now
        tinsert(QTips, tip)
        return tip
    function FetchQuestInfo(questID)
        local tip = GetQTip()
        tip:SetOwner(WorldFrame, 'ANCHOR_NONE')
        tip.questID = questID or 0
        tip:SetScript('OnTooltipSetQuest', ScrapeQTip)
        tip:SetHyperlink('quest:' .. tip.questID)
    local OldQuests, NewQuests = {}, {}
    local f = CreateFrame('frame')
    f:SetScript('OnEvent', function(self, event, ...) return self[event] and self[event](self, ...) end)
    function f:QUEST_COMPLETED(questID) -- Fake event that fires whenever we complete a quest
    		print('Quest Completed: |cffffff00' .. questID)
    -- QUEST_TURNED_IN first argument is quest ID
    --function f:QUEST_TURNED_IN(questID) -- Blacklist real quests we've completed
        --RealQuestBlacklist[questID] = true
    --end f:RegisterEvent('QUEST_TURNED_IN')
    local eventFired = false
    local throttleRate, timeSince = 0.1, 0
    local function OnUpdate(self, elapsed) -- Limit new quest checks to if CRITERIA_UPDATE has fired within the last x seconds (throttleRate)
        timeSince = timeSince + elapsed
        if timeSince >= throttleRate then
            if eventFired then
                for questID in pairs(NewQuests) do
                    if not OldQuests[questID] then
                        OldQuests[questID] = true
                        if not RealQuestBlacklist[questID] then -- Ignore real questIDs
                eventFired = false
            timeSince = 0
    function f:PLAYER_REGEN_ENABLED() -- Exit combat
        throttleRate = 0.1 -- Out of combat throttle rate
    end f:RegisterEvent('PLAYER_REGEN_ENABLED')
    function f:PLAYER_REGEN_DISABLED() -- Enter combat
        throttleRate = 3 -- In-combat throttle rate
    end f:RegisterEvent('PLAYER_REGEN_DISABLED')
    function f:CRITERIA_UPDATE()
        eventFired = true
    end -- Don't register this until after PLAYER_LOGIN
    function f:PLAYER_LOGIN()
        local hasQuests = false
        for questID in pairs(OldQuests) do
            hasQuests = true
        if not hasQuests then print('Failed to load completed quests, api function is bugged |cffff00ff(RELOG)|r.') end
        self:SetScript('OnUpdate', OnUpdate)
    end f:RegisterEvent('PLAYER_LOGIN')
    function f:QUEST_ACCEPTED(index, questID)
        print('QUEST_ACCEPTED', questID)
        -- FetchQuestInfo(questID) -- uncomment if you want it to do the same thing as completed quests
    end f:RegisterEvent('QUEST_ACCEPTED')

It's a part of an old, never released rare scanner addon, I just cut this part for myself so there may be some leftovers here and there (since I don't speak the lua language at all.) On retail this code prints out every accepted and completed quest but on Beta/PTR it says "QUEST_ACCEPTED nil" for the accepted quests and nothing for completed ones.

The error log is:
Message: Interface\AddOns\raredar\code.lua:94: attempt to call global 'GetQuestsCompleted' (a nil value)
Time: Sat Aug 29 19:23:28 2020
Count: 1
Stack: Interface\AddOns\raredar\code.lua:94: attempt to call global 'GetQuestsCompleted' (a nil value)
[string "@Interface\AddOns\raredar\code.lua"]:94: in function `?'
[string "@Interface\AddOns\raredar\code.lua"]:44: in function <Interface\AddOns\raredar\code.lua:44>

Locals: self = <unnamed> {
 0 = <userdata>
 QUEST_COMPLETED = <function> defined @Interface\AddOns\raredar\code.lua:47
 PLAYER_REGEN_ENABLED = <function> defined @Interface\AddOns\raredar\code.lua:79
 PLAYER_LOGIN = <function> defined @Interface\AddOns\raredar\code.lua:93
 CRITERIA_UPDATE = <function> defined @Interface\AddOns\raredar\code.lua:89
 PLAYER_REGEN_DISABLED = <function> defined @Interface\AddOns\raredar\code.lua:84
 QUEST_ACCEPTED = <function> defined @Interface\AddOns\raredar\code.lua:104
(*temporary) = nil
(*temporary) = <table> {
(*temporary) = "attempt to call global 'GetQuestsCompleted' (a nil value)"
OldQuests = <table> {
OnUpdate = <function> defined @Interface\AddOns\raredar\code.lua:60
I see they've removed the 'GetQuestsCompleted' command but could you please help me if this is replaced with something rather than just deleted?

Also, if no replacements, do you know any addon that does the same thing? Or do you have any idea how to change this code chunk to print IDs for accepted and completed quests in 9.x?

Thank you very much in advance.
  Reply With Quote