View Single Post
02-17-24, 11:20 PM   #20
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,897
Your regionEventStartTime table is broken so I made what I think it might be intended to look like.

EDIT: My math foo is broken. Fixed the calculation if you logged in while the event is in progress.

As in (not very different):
Lua Code:
  1. local Backdrop = {
  2.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  3. }
  4.  
  5. local frame_x = 0    
  6. local frame_y = -200   
  7. f = CreateFrame("Button", "ZAMROTimer", UIParent, "BackdropTemplate")
  8. f:SetWidth(255)                                          
  9. f:SetHeight(20)
  10. f:SetBackdrop(Backdrop)
  11. f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
  12. f.text:SetTextHeight(15)
  13. f.text:SetPoint("CENTER")
  14. f:SetClampedToScreen(true)
  15. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  16. f:EnableMouse(true)
  17. f:SetMovable(true)
  18. f:RegisterForDrag("LeftButton")
  19. f:RegisterForClicks("AnyUp")
  20. f:Show()
  21. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  22. f:SetScript("OnDragStart",function(this)
  23.     this:StartMoving()
  24. end)
  25. f:SetScript("OnDragStop",function(this)  
  26.     this:StopMovingOrSizing()
  27.     frame_x,frame_y = this:GetCenter()
  28.     frame_x = frame_x - GetScreenWidth() / 2
  29.     frame_y = frame_y - GetScreenHeight() / 2
  30.     this:ClearAllPoints()
  31.     this:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  32. end)
  33.  
  34. local function printTime(timetotrun, inevent)
  35.     local hideSeconds = timetotrun >= 120
  36.     local msg = "Next event is in: %s"
  37.     if inevent then
  38.         msg = "%s until event ends"
  39.     end
  40.     f.text:SetText(format(msg, SecondsToTime(timetotrun, hideSeconds)))
  41. end
  42.  
  43.  
  44. regionEventStartTime = {
  45.     [1] = { -- eu
  46.         starttime = 16862400102,
  47.         eventDuration = 900,
  48.         eventIntervalInSeconds = 5400,
  49.         enable = true,
  50.         datablock = {}
  51.     },
  52. }
  53. local inEvent, timeToRun
  54. local eventTime = regionEventStartTime[1].eventDuration -- Time the event runs in seconds(15 mins)
  55. local waitTime = regionEventStartTime[1].eventIntervalInSeconds -- Time between events in seconds (90 mins)
  56. local startTime = regionEventStartTime[1].starttime -- Start time from the table
  57. local serverTime = GetServerTime()
  58. local timeToEvent = (startTime - serverTime) % waitTime -- Remaining time before next event starts
  59.  
  60. if timeToEvent > (waitTime - eventTime) then -- Is there between 1:15 and 1:30 to go? If so, we're in the event
  61.     inEvent = true
  62.     timeToRun = eventTime - (waitTime - timeToEvent)
  63. else                    -- Otherwise, set the ticker timer to time to next event
  64.     inEvent = false
  65.     timeToRun = timeToEvent
  66. end
  67. local ticker = C_Timer.NewTicker(1, function()
  68.     if timeToRun > 0 then
  69.         timeToRun = timeToRun - 1
  70.         printTime(timeToRun, inEvent)
  71.         return
  72.     end
  73.     if inEvent then -- The event just finished
  74.         inEvent = false
  75.         timeToRun = waitTime - eventTime -- Reset ticker timer to 90 minutes wait time minus 15 mins event time
  76.     else  -- Waiting for the next event just expired
  77.         inEvent = true
  78.         timeToRun = eventTime -- And the event is running
  79.     end
  80.     printTime(timeToRun, inEvent)
  81. end)
  82. printTime(timeToRun, inEvent)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-18-24 at 12:28 AM.
  Reply With Quote