Thread Tools Display Modes
04-06-24, 09:25 AM   #1
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
Real time update

Hi all. Currently, the data on questIDs = {70893, 71995} is updated only after an “interface reboot” or if I re-enter the game as a character. How to make the data updated immediately without having to enter “/reload”. ?



Lua Code:
  1. local addonName, addon = ...
  2. local frame = CreateFrame("Frame", "QuestCompletionFrame", UIParent)
  3. frame:SetSize(100, 100)
  4. frame:SetPoint("CENTER")
  5. frame:EnableMouse(true)
  6. frame:SetMovable(true)
  7. frame:RegisterForDrag("LeftButton")
  8. frame:SetScript("OnDragStart", frame.StartMoving)
  9. frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
  10.  
  11. local text = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  12. text:SetPoint("CENTER")
  13.  
  14. local localization = {
  15.     ["enUS"] = {
  16.         ["quest70893"] = "|cFFDEB887Community Feast:|r",
  17.         ["quest71995"] = "|cFFDEB887Trial of the Elements:|r",
  18.         ["yes"] = "|cFF1EFF00Complete|r",
  19.         ["no"] = "|cFFDC143CIncomplete|r"
  20.     }
  21. }
  22.  
  23. local function UpdateQuestCompletion()
  24.     local completedQuests = {}
  25.     local questIDs = {70893, 71995}
  26.  
  27.     for _, questID in ipairs(questIDs) do
  28.         local isCompleted = C_QuestLog.IsQuestFlaggedCompleted(questID)
  29.         completedQuests[questID] = isCompleted
  30.     end
  31.  
  32.     local locale = GetLocale()
  33.     local locStrings = localization[locale] or localization["enUS"]
  34.  
  35.     local questStatus = locStrings["quest70893"] .. " "
  36.     if completedQuests[70893] then
  37.         questStatus = questStatus .. locStrings["yes"]
  38.     else
  39.         questStatus = questStatus .. locStrings["no"]
  40.     end
  41.  
  42.     questStatus = questStatus .. "\n" .. locStrings["quest71995"] .. " "
  43.     if completedQuests[71995] then
  44.         questStatus = questStatus .. locStrings["yes"]
  45.     else
  46.         questStatus = questStatus .. locStrings["no"]
  47.     end
  48.  
  49.     text:SetText(questStatus)
  50. end
  51.  
  52. frame:SetScript("OnEvent", function(self, event, ...)
  53.     if event == "PLAYER_LOGIN" then
  54.         UpdateQuestCompletion()
  55.     end
  56. end)
  57.  
  58. frame:RegisterEvent("PLAYER_LOGIN")
  59.  
  60. SLASH_ZAM1 = "/zam"
  61. SlashCmdList["ZAM"] = function(msg)
  62.     if strupper(strtrim(msg)) == "MT" then -- toggle the shown state of the button if the type /hubb btn
  63.         QuestCompletionFrame:SetShown(not QuestCompletionFrame:IsShown()) -- show the button
  64.         return
  65.     end
  66.     updateData()
  67.     updateList()
  68.     QuestCompletionFrame:Show()
  69. end
  Reply With Quote
04-06-24, 10:29 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
You could use the update function for the frame - you've used that in the past for other projects if memory serves.

I personally identify an event that would trigger for it and use that, and only fall back to the OnUpdate frame function if there are no alternatives.

I notice you aren't using the QUEST_COMPLETE (https://warcraft.wiki.gg/wiki/QUEST_COMPLETE) which triggers when the player presses the complete button.

There is also QUEST_TURNED_IN ( https://warcraft.wiki.gg/wiki/QUEST_TURNED_IN ) which might prove useful as well as QUEST_FINISHED (https://warcraft.wiki.gg/wiki/QUEST_FINISHED).

Give those a go and see if they do what you need. If all else fails, you can do your updates via the OnUpdate routine as mentioned. Assuming you have a frame that handles all this stuff for you.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
04-06-24, 07:01 PM   #3
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
Originally Posted by Hubb777 View Post
Hi all. Currently, the data on questIDs = {70893, 71995} is updated only after an “interface reboot” or if I re-enter the game as a character. How to make the data updated immediately without having to enter “/reload”. ?

The reason for that is, that's how you have it setup.

I would take a look at the events for Quest Log stuff.

https://warcraft.wiki.gg/wiki/Events#C_QuestLog
__________________
AddOns: Tim @ WoWInterface
Battle Tag: Mysterio#11164
Current PC Setup: PCPartPicker List
  Reply With Quote
04-07-24, 04:32 AM   #4
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
I did this, but still the update is not in real time
Lua Code:
  1. local addonName, addon = ...
  2. local frame = CreateFrame("Frame", "QuestCompletionFrame", UIParent)
  3. frame:SetSize(100, 100)
  4. frame:SetPoint("CENTER")
  5. frame:EnableMouse(true)
  6. frame:SetMovable(true)
  7. frame:RegisterForDrag("LeftButton")
  8. frame:SetScript("OnDragStart", frame.StartMoving)
  9. frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
  10.  
  11. local text = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  12. text:SetPoint("CENTER")
  13.  
  14. local localization = {
  15.     ["enUS"] = {
  16.         ["quest70893"] = "|cFFDEB887Community Feast:|r",
  17.         ["quest71995"] = "|cFFDEB887Trial of the Elements:|r",
  18.         ["yes"] = "|cFF1EFF00Complete|r",
  19.         ["no"] = "|cFFDC143CIncomplete|r"
  20.     }
  21. }
  22.  
  23. local function UpdateQuestCompletion()
  24.     local completedQuests = {}
  25.     local questIDs = {70893, 71995}
  26.  
  27.     for _, questID in ipairs(questIDs) do
  28.         local isCompleted = C_QuestLog.IsQuestFlaggedCompleted(questID)
  29.         completedQuests[questID] = isCompleted
  30.     end
  31.  
  32.     local locale = GetLocale()
  33.     local locStrings = localization[locale] or localization["enUS"]
  34.  
  35.     local questStatus = locStrings["quest70893"] .. " "
  36.     if completedQuests[70893] then
  37.         questStatus = questStatus .. locStrings["yes"]
  38.     else
  39.         questStatus = questStatus .. locStrings["no"]
  40.     end
  41.  
  42.     questStatus = questStatus .. "\n" .. locStrings["quest71995"] .. " "
  43.     if completedQuests[71995] then
  44.         questStatus = questStatus .. locStrings["yes"]
  45.     else
  46.         questStatus = questStatus .. locStrings["no"]
  47.     end
  48.  
  49.     text:SetText(questStatus)
  50. end
  51.  
  52. local function OnEvent(self, event, ...)
  53.     if event == "PLAYER_LOGIN" or (event == "QUEST_TURNED_IN" and (... == 70893 or ... == 71995)) then
  54.         UpdateQuestCompletion()
  55.     end
  56. end
  57.  
  58. local function OnUpdate(self, elapsed)
  59.     -- Perform any update logic here
  60. end
  61.  
  62. frame:SetScript("OnEvent", OnEvent)
  63. frame:SetScript("OnUpdate", OnUpdate) -- Add the OnUpdate script
  64. frame:RegisterEvent("PLAYER_LOGIN")
  65. frame:RegisterEvent("QUEST_TURNED_IN")
  66.  
  67. SLASH_ZAM1 = "/zam"
  68. SlashCmdList["ZAM"] = function(msg)
  69.     if strupper(strtrim(msg)) == "MT" then -- toggle the shown state of the button if the type /hubb btn
  70.         QuestCompletionFrame:SetShown(not QuestCompletionFrame:IsShown()) -- show the button
  71.         return
  72.     end
  73.     updateData()
  74.     updateList()
  75.     QuestCompletionFrame:Show()
  76. end
  Reply With Quote
04-07-24, 06:51 AM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
Did you check to make sure that the event triggered when you clicked on the complete button for the quest ?

It is also possible that the IsQuestFlaggedCompleted function doesn't know about the just completed quest yet. If that is the case, the only thing you can do is use the OnUpdate function and put a timed check in there to periodically check if it is marked as complete yet.

Let me check with one of my test toons and see if a simple test works as I expect it to.


Okay.. I just tested with this small piece of code.

Lua Code:
  1. local addonName, addonNS = ...
  2.  
  3. Quests_Completed = Quests_Completed or {}
  4.  
  5. local function QuestTurnedIn(...)    
  6.     local questID, xpReward, moneyReward = ...    
  7.     local isCompleted = C_QuestLog.IsQuestFlaggedCompleted(questID)   -- Returns true    
  8.     print("Quest: ", questID,"XP: ", xpReward,"Money: ", moneyReward,"Completed: ",isCompleted)    
  9.     Quests_Completed[questID].Completed = isCompleted
  10. end
  11.  
  12. local function QuestAccepted(...)
  13.     local questID = ...
  14.     local questLogIndex = C_QuestLog.GetLogIndexForQuestID(questID)
  15.     local info = { C_QuestLog.GetInfo(questLogIndex) }
  16.     print("Accepted Quest: ", questID, info["title"])    
  17.     Quests_Completed[questID] = info                
  18. end
  19.  
  20. local frame = CreateFrame("Frame")
  21. frame:RegisterEvent("QUEST_TURNED_IN")
  22. frame:RegisterEvent("QUEST_ACCEPTED")
  23. frame:SetScript("OnEvent", function(self, event, ...)
  24.     if event == "QUEST_TURNED_IN" then
  25.         -- Triggers when pressing Complete Button
  26.         QuestTurnedIn(...)
  27.     elseif event == "QUEST_ACCEPTED" then
  28.         -- Triggers before Pressing Accept Button
  29.         QuestAccepted(...)
  30.     end
  31. end)

It worked as expected with the addon recognising that a quest had been turned in as it was turned in and marked it as completed immediately. The only slight error on my part was trying to display info.title instead of info["title"] on the screen.

It might be that the quests you are looking into in particular are working differently. Try separating the event tests and see whether the QUEST_TURNED_IN functionality kicks in correctly.


The saved variables show that on QUEST_ACCEPTED all of the information was available and on QUEST_TURNED_IN it knew it had been completed. In this example, the first alliance human quest was completed with the second accepted but not completed.

Lua Code:
  1. Quests_Completed = {
  2.     [28757] = {
  3.         {
  4.             ["difficultyLevel"] = 1,
  5.             ["useMinimalHeader"] = false,
  6.             ["isHeader"] = false,
  7.             ["questLogIndex"] = 2,
  8.             ["level"] = 1,
  9.             ["isOnMap"] = false,
  10.             ["isTask"] = false,
  11.             ["isHidden"] = false,
  12.             ["overridesSortOrder"] = false,
  13.             ["isInternalOnly"] = false,
  14.             ["isCollapsed"] = true,
  15.             ["startEvent"] = false,
  16.             ["questID"] = 28757,
  17.             ["suggestedGroup"] = 0,
  18.             ["isBounty"] = false,
  19.             ["readyForTranslation"] = true,
  20.             ["isLegendarySort"] = false,
  21.             ["title"] = "Beating Them Back!",
  22.             ["isAutoComplete"] = false,
  23.             ["isStory"] = false,
  24.             ["hasLocalPOI"] = false,
  25.             ["isScaling"] = true,
  26.             ["frequency"] = 0,
  27.         }, -- [1]
  28.         ["Completed"] = true,
  29.     },
  30.     [28769] = {
  31.         {
  32.             ["difficultyLevel"] = 2,
  33.             ["useMinimalHeader"] = false,
  34.             ["isHeader"] = false,
  35.             ["questLogIndex"] = 2,
  36.             ["level"] = 2,
  37.             ["isOnMap"] = false,
  38.             ["isTask"] = false,
  39.             ["isHidden"] = false,
  40.             ["overridesSortOrder"] = false,
  41.             ["isInternalOnly"] = false,
  42.             ["isCollapsed"] = true,
  43.             ["startEvent"] = false,
  44.             ["questID"] = 28769,
  45.             ["suggestedGroup"] = 0,
  46.             ["isBounty"] = false,
  47.             ["readyForTranslation"] = true,
  48.             ["isLegendarySort"] = false,
  49.             ["title"] = "Lions for Lambs",
  50.             ["isAutoComplete"] = false,
  51.             ["isStory"] = false,
  52.             ["hasLocalPOI"] = false,
  53.             ["isScaling"] = true,
  54.             ["frequency"] = 0,
  55.         }, -- [1]
  56.     },
  57. }
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 04-07-24 at 07:28 AM.
  Reply With Quote
04-07-24, 07:42 AM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
Also, you could forego on the localization of the quest name as you could use the following :

C_QuestLog.GetTitleForQuestID(questID)

https://warcraft.wiki.gg/wiki/API_C_...itleForQuestID - Includes Example Code


Or a combination of :
C_QuestLog.RequestLoadQuestByID(questID) and monitoring QUEST_DATA_LOAD_RESULT event for quest data access if it wasn't available before.

https://warcraft.wiki.gg/wiki/API_C_...tLoadQuestByID
https://warcraft.wiki.gg/wiki/QUEST_DATA_LOAD_RESULT


Or like I did, use the QUEST_ACCEPTED part to access the quest info at the point it becomes available to you. It all depends on how your addon is supposed to work.

I would suspect that the name of the quest would be automatically localized - similar to spell names and professions etc.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
04-08-24, 04:07 AM   #7
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
I tried combining my code with yours. But it still doesn't work.

Lua Code:
  1. local addonName, addon = ...
  2. local frame = CreateFrame("Frame", "QuestCompletionFrame", UIParent)
  3. frame:SetSize(100, 100)
  4. frame:SetPoint("CENTER")
  5. frame:EnableMouse(true)
  6. frame:SetMovable(true)
  7. frame:RegisterForDrag("LeftButton")
  8. frame:SetScript("OnDragStart", frame.StartMoving)
  9. frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
  10.  
  11. local text = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  12. text:SetPoint("CENTER")
  13.  
  14. local Quests_Completed = Quests_Completed or {}
  15.  
  16. local function QuestTurnedIn(...)
  17.     local questID, xpReward, moneyReward = ...
  18.     local isCompleted = C_QuestLog.IsQuestFlaggedCompleted(questID)   -- Returns true
  19.     print("Quest: ", questID,"XP: ", xpReward,"Money: ", moneyReward,"Completed: ",isCompleted)
  20.     Quests_Completed[questID].Completed = isCompleted
  21. end
  22.  
  23. local function QuestAccepted(...)
  24.     local questID = ...
  25.     local questLogIndex = C_QuestLog.GetLogIndexForQuestID(questID)
  26.     local info = { C_QuestLog.GetInfo(questLogIndex) }
  27.     print("Accepted Quest: ", questID, info["title"])
  28.     Quests_Completed[questID] = info
  29. end
  30.  
  31. frame:SetScript("OnEvent", function(self, event, ...)
  32.     if event == "PLAYER_LOGIN" then
  33.         local completedQuests = {}
  34.         local questIDs = {70893, 71995}
  35.  
  36.         for _, questID in ipairs(questIDs) do
  37.             local isCompleted = C_QuestLog.IsQuestFlaggedCompleted(questID)
  38.             completedQuests[questID] = isCompleted
  39.         end
  40.  
  41.         local localization = {
  42.             ["enUS"] = {
  43.                 ["quest70893"] = "|cFFDEB887Community Feast:|r",
  44.                 ["quest71995"] = "|cFFDEB887Trial of the Elements:|r",
  45.                 ["yes"] = "|cFF1EFF00Complete|r",
  46.                 ["no"] = "|cFFDC143CIncomplete|r"
  47.             }
  48.         }
  49.  
  50.         local locale = GetLocale()
  51.         local locStrings = localization[locale] or localization["enUS"]
  52.  
  53.         local questStatus = locStrings["quest70893"] .. " "
  54.         if completedQuests[70893] then
  55.             questStatus = questStatus .. locStrings["yes"]
  56.         else
  57.             questStatus = questStatus .. locStrings["no"]
  58.         end
  59.  
  60.         questStatus = questStatus .. "\n" .. locStrings["quest71995"] .. " "
  61.         if completedQuests[71995] then
  62.             questStatus = questStatus .. locStrings["yes"]
  63.         else
  64.             questStatus = questStatus .. locStrings["no"]
  65.         end
  66.  
  67.         text:SetText(questStatus)
  68.     elseif event == "QUEST_TURNED_IN" then
  69.         -- Triggers when pressing Complete Button
  70.         QuestTurnedIn(...)
  71.     elseif event == "QUEST_ACCEPTED" then
  72.         -- Triggers before Pressing Accept Button
  73.         QuestAccepted(...)
  74.     end
  75. end)
  76.  
  77. frame:RegisterEvent("PLAYER_LOGIN")
  78. frame:RegisterEvent("QUEST_TURNED_IN")
  79. frame:RegisterEvent("QUEST_ACCEPTED")
  Reply With Quote
04-08-24, 05:12 AM   #8
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
What does it do ?
What did you expect it to do ?

It doesn't work doesn't explain what is happening in your case.

Looking at your code you are still only setting the information on PLAYER_LOGIN. This means it will only show the status ( outside of the printed statements from my code portions) when you first login or reload the UI.

Your updating of the display code needs to be updated on completion too.

Give this code a whirl. It's not perfect but hopefully it will work closer to what you wanted it to do.

Lua Code:
  1. local addonName, addon = ...
  2.  
  3. -- Create Frame
  4. local frame = CreateFrame("Frame", "QuestCompletionFrame", UIParent)
  5. frame:SetSize(100, 100)
  6. frame:SetPoint("CENTER")
  7. frame:EnableMouse(true)
  8. frame:SetMovable(true)
  9. frame:RegisterForDrag("LeftButton")
  10. frame:SetScript("OnDragStart", frame.StartMoving)
  11. frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
  12.  
  13. local text = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  14. text:SetPoint("CENTER")
  15.  
  16. -- Initialise Data used in addon
  17. local completedQuests = {}
  18. local questInfo = {}
  19. local questIDs = {70893, 71995}
  20.  
  21. -- Setup Localization
  22. local localization = {
  23.     ["enUS"] = {
  24.         ["quest70893"] = "|cFFDEB887Community Feast:|r",
  25.         ["quest71995"] = "|cFFDEB887Trial of the Elements:|r",
  26.         ["yes"] = "|cFF1EFF00Complete|r",
  27.         ["no"] = "|cFFDC143CIncomplete|r"
  28.     }
  29. }
  30. local locale = GetLocale()
  31. local locStrings = localization[locale] or localization["enUS"]
  32.  
  33. local function UpdateDisplay(questID, questStatus)
  34.  
  35.     -- Append newline if questStatus contains information
  36.     if questStatus != "" then
  37.         questStatus .. "\n"
  38.     end
  39.    
  40.     -- Convert questID to a string and create a localization key for it
  41.     questStatus = locStrings["quest" .. tostring(questID)] .. " "
  42.    
  43.     -- Add whether it is completed or not
  44.     if completedQuests[questID] then
  45.         questStatus = questStatus .. locStrings["yes"]
  46.     else
  47.         questStatus = questStatus .. locStrings["no"]
  48.     end
  49.  
  50.     -- Update Text Box
  51.     text:SetText(questStatus)
  52.  
  53.     -- Return the current questStatus contents
  54.     return questStatus
  55.  
  56. end
  57.  
  58. -- Handle what to do when you first log in
  59. local function PlayerLogin(...)
  60.     for _, questID in ipairs(questIDs) do
  61.         local isCompleted = C_QuestLog.IsQuestFlaggedCompleted(questID)
  62.         completedQuests[questID] = isCompleted
  63.     end
  64.    
  65.     -- Statu with an empty questStatus and update it
  66.     local questStatus = ""
  67.     questStatus = UpdateDisplay(70893, questStatus)
  68.     questStatus = UpdateDisplay(71995, questStatus)
  69.  
  70. end
  71.  
  72.  
  73. -- Handle what to do when you turn in a quest
  74. local function QuestTurnedIn(...)
  75.     local questID, xpReward, moneyReward = ...
  76.    
  77.     -- Don't bother continuing if we are not watching this quest
  78.     if questID != 70893 then return end
  79.     if questID != 71995 then return end
  80.    
  81.     local isCompleted = C_QuestLog.IsQuestFlaggedCompleted(questID)   -- Returns true
  82.     completedQuests[questID] = isCompleted
  83.    
  84.     -- Debug Text
  85.     print("Quest: ", questID,"XP: ", xpReward,"Money: ", moneyReward,"Completed: ",isCompleted)
  86.    
  87.     -- Get Current Text Display and Update it
  88.     local questStatus = text:GetText()
  89.     questStatus = UpdateDisplay(questID, questStatus)
  90.  
  91. end
  92.  
  93. -- Handle what to do when you accept a quest
  94. local function QuestAccepted(...)
  95.     local questID = ...
  96.     local questLogIndex = C_QuestLog.GetLogIndexForQuestID(questID)
  97.     local info = { C_QuestLog.GetInfo(questLogIndex) }
  98.    
  99.     -- Add Quest Info to table
  100.     questInfo[questID] = info
  101.    
  102.     -- Debug Text
  103.     print("Accepted Quest: ", questID, info["title"])
  104. end
  105.  
  106. -- Handle events being listened to
  107. frame:SetScript("OnEvent", function(self, event, ...)
  108.     if event == "PLAYER_LOGIN" then
  109.         PlayerLogin(...)
  110.     elseif event == "QUEST_TURNED_IN" then
  111.         -- Triggers when pressing Complete Button
  112.         QuestTurnedIn(...)
  113.     elseif event == "QUEST_ACCEPTED" then
  114.         -- Triggers before Pressing Accept Button
  115.         QuestAccepted(...)
  116.     end
  117. end)
  118.  
  119. frame:RegisterEvent("PLAYER_LOGIN")
  120. frame:RegisterEvent("QUEST_TURNED_IN")
  121. frame:RegisterEvent("QUEST_ACCEPTED")
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
04-08-24, 06:53 AM   #9
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
Many thanks for the help. I still managed to do it using your code again + OnUpdate
Lua Code:
  1. local addonName, addon = ...
  2. local frame = CreateFrame("Frame", "QuestCompletionFrame", UIParent)
  3. frame:SetSize(100, 100)
  4. frame:SetPoint("CENTER")
  5. frame:EnableMouse(true)
  6. frame:SetMovable(true)
  7. frame:RegisterForDrag("LeftButton")
  8. frame:SetScript("OnDragStart", frame.StartMoving)
  9. frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
  10.  
  11. local text = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  12. text:SetPoint("CENTER")
  13.  
  14. local Quests_Completed = Quests_Completed or {}
  15.  
  16. local function QuestTurnedIn(...)
  17.     local questID, xpReward, moneyReward = ...
  18.     local isCompleted = C_QuestLog.IsQuestFlaggedCompleted(questID)   -- Returns true
  19.     print("Quest: ", questID,"XP: ", xpReward,"Money: ", moneyReward,"Completed: ",isCompleted)
  20.     Quests_Completed[questID].Completed = isCompleted
  21. end
  22.  
  23. local function QuestAccepted(...)
  24.     local questID = ...
  25.     local questLogIndex = C_QuestLog.GetLogIndexForQuestID(questID)
  26.     local info = { C_QuestLog.GetInfo(questLogIndex) }
  27.     print("Accepted Quest: ", questID, info["title"])
  28.     Quests_Completed[questID] = info
  29. end
  30.  
  31. frame:SetScript("OnEvent", function(self, event, ...)
  32.     if event == "PLAYER_LOGIN" then
  33.         self.elapsed = 0 -- Initialize elapsed time
  34.         self:RegisterEvent("QUEST_TURNED_IN")
  35.         self:RegisterEvent("QUEST_ACCEPTED")
  36.     end
  37. end)
  38.  
  39. frame:SetScript("OnUpdate", function(self, elapsed)
  40.     self.elapsed = self.elapsed + elapsed
  41.     if self.elapsed >= 1 then -- Check every 1 second
  42.         local completedQuests = {}
  43.         local questIDs = {70893, 71995}
  44.  
  45.         for _, questID in ipairs(questIDs) do
  46.             local isCompleted = C_QuestLog.IsQuestFlaggedCompleted(questID)
  47.             completedQuests[questID] = isCompleted
  48.         end
  49.  
  50.         local localization = {
  51.             ["enUS"] = {
  52.                 ["quest70893"] = "|cFFDEB887Community Feast:|r",
  53.                 ["quest71995"] = "|cFFDEB887Trial of the Elements:|r",
  54.                 ["yes"] = "|cFF1EFF00Complete|r",
  55.                 ["no"] = "|cFFDC143CIncomplete|r"
  56.             }
  57.         }
  58.  
  59.         local locale = GetLocale()
  60.         local locStrings = localization[locale] or localization["enUS"]
  61.  
  62.         local questStatus = locStrings["quest70893"] .. " "
  63.         if completedQuests[70893] then
  64.             questStatus = questStatus .. locStrings["yes"]
  65.         else
  66.             questStatus = questStatus .. locStrings["no"]
  67.         end
  68.  
  69.         questStatus = questStatus .. "\n" .. locStrings["quest71995"] .. " "
  70.         if completedQuests[71995] then
  71.             questStatus = questStatus .. locStrings["yes"]
  72.         else
  73.             questStatus = questStatus .. locStrings["no"]
  74.         end
  75.  
  76.         text:SetText(questStatus)
  77.        
  78.         self.elapsed = 0 -- Reset elapsed time
  79.     end
  80. end)
  81.  
  82. frame:RegisterEvent("PLAYER_LOGIN")
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Real time update


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