Lua 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(185)
f:SetHeight(30)
f:SetBackdrop(Backdrop)
f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
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 Localizations = {
enUS = {
Waiting = "|c1C7BCEFFCommunity Feast:\nbefore the start: %s%s|r",
Running = "|cFF35BE21Community Feast:\n%s%s until completion|r",
},
deDE = {
Waiting = "|c1C7BCEFFGemeinschaftliches Festmahl:\nvor dem Anfang: %s%s|r",
Running = "|cFF35BE21Gemeinschaftliches Festmahl:\n%s%s bis zur Fertigstellung|r",
},
}
local locale = GetLocale()
local L = Localizations[locale] or Localizations.enUS
local useColor = true
local useSound = true
local alert1 = 600
local alert1Color = "|cffffff00"
local alert2 = 300
local alert2Color = "|cffff0000"
local soundKit = 32585
local function printTime(timetotrun, inevent)
local hideSeconds = timetotrun >= 120
local msg = L.Waiting
local msgColor = "|cffffffff"
if inevent then
msg = L.Running
else
if useColor and timetotrun <= alert2 then
msgColor = alert2Color
elseif timetotrun <= alert1 then
if useSound and not ZAMROTimer.Alerted then
ZAMROTimer.Alerted = true
PlaySound(soundKit, "Master")
end
if useColor then
msgColor = alert1Color
end
end
end
f.text:SetText(format(msg, msgColor, SecondsToTime(timetotrun, hideSeconds)))
end
local regionEventStartTime = {
[1] = { -- eu
starttime = 1670331660,
eventDuration = 900,
eventIntervalInSeconds = 5400,
enable = true,
datablock = {}
},
[2] = { -- america
starttime = 1670338860,
eventDuration = 900,
eventIntervalInSeconds = 5400,
enable = true,
datablock = {}
}
}
local inEvent, timeToRun
local eventTime = regionEventStartTime[1].eventDuration -- Default to EU region for calculations
local waitTime = regionEventStartTime[1].eventIntervalInSeconds
local startTime = regionEventStartTime[1].starttime
local serverTime = GetServerTime()
local timeToEvent = (startTime - serverTime) % waitTime
if timeToEvent > (waitTime - eventTime) then
inEvent = true
timeToRun = eventTime - (waitTime - timeToEvent)
else
inEvent = false
timeToRun = timeToEvent
end
-- Check if in the Americas region, then adjust time calculations
if GetCVar("portal") == "US" then
eventTime = regionEventStartTime[2].eventDuration
waitTime = regionEventStartTime[2].eventIntervalInSeconds
startTime = regionEventStartTime[2].starttime
timeToEvent = (startTime - serverTime) % waitTime
if timeToEvent > (waitTime - eventTime) then
inEvent = true
timeToRun = eventTime - (waitTime - timeToEvent)
else
inEvent = false
timeToRun = timeToEvent
end
end
local ticker = C_Timer.NewTicker(1, function()
if timeToRun > 0 then
timeToRun = timeToRun - 1
printTime(timeToRun, inEvent)
return
end
ZAMROTimer.Alerted = false
if inEvent then
inEvent = false
timeToRun = waitTime - eventTime
else
inEvent = true
timeToRun = eventTime
end
printTime(timeToRun, inEvent)
end)
printTime(timeToRun, inEvent)
Hello. I added support for a second region to the timer (added America), initially there was only Europe. But I can't test. Did I do the right thing? I play on European servers and don't understand how I can test this code. I wanted to test it on the PTR server (it seems to be in America), but it still displays European time.