View Single Post
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: 122
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