Looks like another question. How do I add a sound signal about the start of an event that notifies 5 minutes before the start of the event?
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(255)
f:SetHeight(30)
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 Localizations = {
enUS = {
Waiting = "|c1C7BCEFFCommunity Feast:\nbefore the start: %s|r",
Running = "|cFF35BE21Community Feast:\n%s until completion|r",
},
deDE = {
Waiting = "|c1C7BCEFFGemeinschaftliches Festmahl:\nNächste Veranstaltung ist in: %s|r",
Running = "|cFF35BE21Gemeinschaftliches Festmahl:\n%s bis zum Ende der Veranstaltung|r",
},
}
local locale = GetLocale()
local L = Localizations[locale] or Localizations.enUS -- Default to enUS if locale doesn't exist in the table
local function printTime(timetotrun, inevent)
local hideSeconds = timetotrun >= 120
local msg = L.Waiting
if inevent then
msg = L.Running
end
f.text:SetText(format(msg, SecondsToTime(timetotrun, hideSeconds)))
end
regionEventStartTime = {
[1] = { -- eu
starttime = 1670331660,
eventDuration = 900,
eventIntervalInSeconds = 5400,
enable = true,
datablock = {}
},
}
local inEvent, timeToRun
local eventTime = regionEventStartTime[1].eventDuration -- Time the event runs in seconds(15 mins)
local waitTime = regionEventStartTime[1].eventIntervalInSeconds -- Time between events in seconds (90 mins)
local startTime = regionEventStartTime[1].starttime -- Start time from the table
local serverTime = GetServerTime()
local timeToEvent = (startTime - serverTime) % 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 = eventTime - (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)
I've written the code here (but it doesn't seem to be quite right)
Lua Code:
local showedTime = startTime and timeToEvent or waitTime
if showedTime < 3600 then
self.timer:SetText(date("%M:%S", showedTime))
else
self.timer:SetText(date("%H", showedTime)-1 .. date("h%M", showedTime))
end
if not startTime then
if showedTime < 300 then
if not self.soundPlayed then
PlaySound(32585, "Master")
self.glow:SetVertexColor(0, 1, 0)
self.soundPlayed = true
end
elseif self.soundPlayed then
self.glow:SetVertexColor(0, 0, 0)
self.soundPlayed = false
end
end