View Single Post
02-18-24, 06:04 AM   #26
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 129
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:
  1. local addonName, addon = ...
  2. local Backdrop = {
  3.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  4. }
  5.  
  6. local frame_x = 0    
  7. local frame_y = -200    
  8. f = CreateFrame("Button", "ZAMROTimer", UIParent, "BackdropTemplate")
  9. f:SetWidth(255)                                          
  10. f:SetHeight(30)
  11. f:SetBackdrop(Backdrop)
  12. f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
  13. f.text:SetTextHeight(15)
  14. f.text:SetPoint("CENTER")
  15. f:SetClampedToScreen(true)
  16. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  17. f:EnableMouse(true)
  18. f:SetMovable(true)
  19. f:RegisterForDrag("LeftButton")
  20. f:RegisterForClicks("AnyUp")
  21. f:Show()
  22. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  23. f:SetScript("OnDragStart",function(this)
  24.     this:StartMoving()
  25. end)
  26. f:SetScript("OnDragStop",function(this)  
  27.     this:StopMovingOrSizing()
  28.     frame_x,frame_y = this:GetCenter()
  29.     frame_x = frame_x - GetScreenWidth() / 2
  30.     frame_y = frame_y - GetScreenHeight() / 2
  31.     this:ClearAllPoints()
  32.     this:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  33. end)
  34.  
  35. local Localizations = {
  36.     enUS = {
  37.         Waiting = "|c1C7BCEFFCommunity Feast:\nbefore the start: %s|r",
  38.         Running = "|cFF35BE21Community Feast:\n%s until completion|r",
  39.     },
  40.     deDE = {
  41.         Waiting = "|c1C7BCEFFGemeinschaftliches Festmahl:\nNächste Veranstaltung ist in: %s|r",
  42.         Running = "|cFF35BE21Gemeinschaftliches Festmahl:\n%s bis zum Ende der Veranstaltung|r",
  43.     },
  44. }
  45.  
  46. local locale = GetLocale()
  47. local L = Localizations[locale] or Localizations.enUS -- Default to enUS if locale doesn't exist in the table
  48.  
  49. local function printTime(timetotrun, inevent)
  50.     local hideSeconds = timetotrun >= 120
  51.     local msg = L.Waiting
  52.     if inevent then
  53.         msg = L.Running
  54.     end
  55.     f.text:SetText(format(msg, SecondsToTime(timetotrun, hideSeconds)))
  56. end
  57.  
  58.  
  59. regionEventStartTime = {
  60.     [1] = { -- eu
  61.         starttime = 1670331660,
  62.         eventDuration = 900,
  63.         eventIntervalInSeconds = 5400,
  64.         enable = true,
  65.         datablock = {}
  66.     },
  67. }
  68. local inEvent, timeToRun
  69. local eventTime = regionEventStartTime[1].eventDuration -- Time the event runs in seconds(15 mins)
  70. local waitTime = regionEventStartTime[1].eventIntervalInSeconds -- Time between events in seconds (90 mins)
  71. local startTime = regionEventStartTime[1].starttime -- Start time from the table
  72. local serverTime = GetServerTime()
  73. local timeToEvent = (startTime - serverTime) % waitTime -- Remaining time before next event starts
  74.  
  75. if timeToEvent > (waitTime - eventTime) then -- Is there between 1:15 and 1:30 to go? If so, we're in the event
  76.     inEvent = true
  77.     timeToRun = eventTime - (waitTime - timeToEvent)
  78. else                    -- Otherwise, set the ticker timer to time to next event
  79.     inEvent = false
  80.     timeToRun = timeToEvent
  81. end
  82. local ticker = C_Timer.NewTicker(1, function()
  83.     if timeToRun > 0 then
  84.         timeToRun = timeToRun - 1
  85.         printTime(timeToRun, inEvent)
  86.         return
  87.     end
  88.     if inEvent then -- The event just finished
  89.         inEvent = false
  90.         timeToRun = waitTime - eventTime -- Reset ticker timer to 90 minutes wait time minus 15 mins event time
  91.     else  -- Waiting for the next event just expired
  92.         inEvent = true
  93.         timeToRun = eventTime -- And the event is running
  94.     end
  95.     printTime(timeToRun, inEvent)
  96. end)
  97. printTime(timeToRun, inEvent)


I've written the code here (but it doesn't seem to be quite right)




Lua Code:
  1. local showedTime = startTime and timeToEvent or waitTime
  2.        
  3.         if showedTime < 3600 then
  4.             self.timer:SetText(date("%M:%S", showedTime))
  5.         else
  6.             self.timer:SetText(date("%H", showedTime)-1 .. date("h%M", showedTime))
  7.         end
  8.  
  9. if not startTime then
  10.             if showedTime < 300 then
  11.                 if not self.soundPlayed then
  12.                     PlaySound(32585, "Master")
  13.                     self.glow:SetVertexColor(0, 1, 0)
  14.                     self.soundPlayed = true
  15.                 end
  16.             elseif self.soundPlayed then
  17.                 self.glow:SetVertexColor(0, 0, 0)
  18.                 self.soundPlayed = false
  19.             end
  20.         end
  Reply With Quote