View Single Post
02-17-24, 01:22 AM   #17
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 131
Originally Posted by Fizzlemizz View Post
Try:
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. local communityFeastTime = { -- Known region start time(s)
  43.     ["EU"] = 75600, -- 21:00 in seconds ie. (21 * 60 * 60)
  44. }
  45. local eventTime = 15 * 60 -- Time the event runs in seconds(15 mins)
  46. local waitTime = 90 * 60 -- Time between events in seconds (90 mins)
  47. local inEvent, timeToRun
  48.  
  49. local startTime = communityFeastTime.EU -- Start time from the table
  50. local timeNow = date("*t", time()) -- The time at login
  51. local timeToSeconds = ((timeNow.hour * 60) * 60) + (timeNow.min * 60) + timeNow.sec -- Convert time now to seconds
  52. local timeToEvent = (startTime - timeToSeconds) % waitTime -- Remaining time before next event starts
  53. if timeToEvent > (waitTime - eventTime) then -- Is there between 1:15 and 1:30 to go? If so, we're in the event
  54.     inEvent = true
  55.     timeToRun = waitTime - timeToEvent
  56. else                    -- Otherwise, set the ticker timer to time to next event
  57.     inEvent = false
  58.     timeToRun = timeToEvent
  59. end
  60. local ticker = C_Timer.NewTicker(1, function()
  61.    if timeToRun > 0 then
  62.       timeToRun = timeToRun - 1
  63.       printTime(timeToRun, inEvent)
  64.       return
  65.    end
  66.    if inEvent then -- The event is in progress
  67.     inEvent = false
  68.     timeToRun = waitTime -- Reset ticker timer to 90 mins
  69.    else  -- Waiting for the next event
  70.     inEvent = true
  71.     timeToRun = eventTime
  72.    end
  73.    printTime(timeToRun, inEvent)
  74. end)
  75. printTime(timeToRun, inEvent)
Hi. Yes, it worked. You've been very helpful. I will recommend this forum to everyone. Everyone here is very friendly.

UPD: I edited the code and replaced 120 with 0. The problem is that after completing the 15 minute timer, it started counting down 1.5 hours to the next event. Although there should be 1 hour and 15 minutes left.
The interval between events is 1 hour and 15 minutes.
The event lasts for 15 minutes.
For example: the event started at 10:00, ended at 10:15, after that the timer should show that the next event is at 11:30, and this code shows that the event will be at 11:45 (and it needs to be at 11:30)

This is fixed by the command /reload - as I understand it, the timer time is not reset every time. Is that why you have to prescribe?

Code:
local addonName, addon = ...
local Backdrop = {
    bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
}
 
local frame_x = 0      
local frame_y = -200    
f = CreateFrame("Button", "ZAMROTimer", UIParent, "BackdropTemplate")
f:SetWidth(255)                                             
f:SetHeight(20)
f:SetBackdrop(Backdrop)
f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
f.text:SetTextHeight(15)
f.text:SetPoint("CENTER")
f:SetClampedToScreen(true)
f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
f:EnableMouse(true)
f:SetMovable(true)
f:RegisterForDrag("LeftButton")
f:RegisterForClicks("AnyUp")
f:Show()
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnDragStart",function(this) 
   this:StartMoving()
end)
f:SetScript("OnDragStop",function(this)  
   this:StopMovingOrSizing()
   frame_x,frame_y = this:GetCenter()
   frame_x = frame_x - GetScreenWidth() / 2
   frame_y = frame_y - GetScreenHeight() / 2
   this:ClearAllPoints()
   this:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
end)
 
local function printTime(timetotrun, inevent)
    local hideSeconds = timetotrun >= 0
    local msg = "Next event is in: %s"
    if inevent then
        msg = "%s until event ends"
    end
    f.text:SetText(format(msg, SecondsToTime(timetotrun, hideSeconds)))
end
local communityFeastTime = { -- Known region start time(s)
    ["EU"] = 46800, -- 21:00 in seconds ie. (21 * 60 * 60)
}
local eventTime = 15 * 60 -- Time the event runs in seconds(15 mins)
local waitTime = 90 * 60 -- Time between events in seconds (90 mins)
local inEvent, timeToRun
 
local startTime = communityFeastTime.EU -- Start time from the table
local timeNow = date("*t", time()) -- The time at login
local timeToSeconds = ((timeNow.hour * 60) * 60) + (timeNow.min * 60) + timeNow.sec -- Convert time now to seconds
local timeToEvent = (startTime - timeToSeconds) % waitTime -- Remaining time before next event starts
if timeToEvent > (waitTime - eventTime) then -- Is there between 1:15 and 1:30 to go? If so, we're in the event
    inEvent = true
    timeToRun = waitTime - timeToEvent
else                    -- Otherwise, set the ticker timer to time to next event
    inEvent = false
    timeToRun = timeToEvent
end
local ticker = C_Timer.NewTicker(1, function() 
   if timeToRun > 0 then
      timeToRun = timeToRun - 1
      printTime(timeToRun, inEvent)
      return
   end
   if inEvent then -- The event is in progress
    inEvent = false
    timeToRun = waitTime -- Reset ticker timer to 90 mins
   else  -- Waiting for the next event
    inEvent = true
    timeToRun = eventTime
   end
   printTime(timeToRun, inEvent)
end)
printTime(timeToRun, inEvent)

Last edited by Hubb777 : 02-17-24 at 04:23 AM.
  Reply With Quote