Try:
Lua Code:
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 >= 120
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"] = 75600, -- 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 just finished
inEvent = false
timeToRun = waitTime - eventTime -- Reset ticker timer to 90 minutes wait time minus 15 mins event time
else -- Waiting for the next event just expired
inEvent = true
timeToRun = eventTime -- And the event is running
end
printTime(timeToRun, inEvent)
end)
printTime(timeToRun, inEvent)