Thread Tools Display Modes
02-18-24, 01:04 AM   #21
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Fizzlemizz View Post
Your regionEventStartTime table is broken so I made what I think it might be intended to look like.

EDIT: My math foo is broken. Fixed the calculation if you logged in while the event is in progress.

As in (not very different):
I just wanted to write about this bug. But you got ahead of the curve and fixed it. Everything works. And the last question on this topic -
How do I add localization of Next event is in and until event ends labels to other languages?

Code:
            enUS = "Next event is in: %s",
	    zhCN = "下一个活动在: %s",
            deDE = "Nächste Veranstaltung ist in: %s",
Code:
            enUS = "%s until event ends",
	    zhCN = "%s 直到事件结束",
            deDE = "bis zum Ende der Veranstaltung",
I am very grateful to you for your help. I'm just on disability and can't afford a IT education. Therefore, I began to study LUA, because I found my place and friends in the world of warcraft.
  Reply With Quote
02-18-24, 01:38 AM   #22
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Lots of way to go about localisation but probably for something small like this the easiest would be something like:

Lua Code:
  1. local Localizations = {
  2.     enUS = {
  3.         Waiting = "Next event is in: %s",
  4.         Running = "%s until event ends",
  5.     },
  6.     zhCN = {
  7.         Waiting = "下一个活动在: %s",
  8.         Running = "%s 直到事件结束",
  9.     },
  10.     deDE = {
  11.         Waiting = "Nächste Veranstaltung ist in: %s",
  12.         Running = "bis zum Ende der Veranstaltung: %s",
  13.     },
  14. }
  15.  
  16. local locale = GetLocale()
  17. local L = Localizations[locale] or Localizations.enUS -- Default to enUS if locale doesn't exist in the table

Then you can replace "Next event is in: %s" with L.Waiting and "%s until event ends" with L.Running

The usual scoping rules apply.

Your example didn't have a %s for the German "Until the event ends" so I just stuck one at the end (my German foo is also broken ).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-18-24 at 01:43 AM.
  Reply With Quote
02-18-24, 01:46 AM   #23
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Fizzlemizz View Post
Lots of way to go about localisation but probably for something small like this the easiest would be something like:

Lua Code:
  1. local Localizations = {
  2.     enUS = {
  3.         Waiting = "Next event is in: %s",
  4.         Running = "%s until event ends",
  5.     },
  6.     zhCN = {
  7.         Waiting = "下一个活动在: %s",
  8.         Running = "%s 直到事件结束",
  9.     },
  10.     deDE = {
  11.         Waiting = "Nächste Veranstaltung ist in: %s",
  12.         Running = "bis zum Ende der Veranstaltung: %s",
  13.     },
  14. }
  15.  
  16. local locale = GetLocale()
  17. local L = Localizations[locale] or Localizations.enUS -- Default to enUS if locale doesn't exist in the table

Then you can replace "Next event is in: %s" with L.Waiting and "%s until event ends" with L.Running

The usual scoping rules apply.

Your example didn't have a %s for the German "Until the event ends" so I just stuck one at the end (my German foo is also broken ).

Look, did I do everything right?


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 Localizations = {
    enUS = {
        Waiting = "Next event is in: %s",
        Running = "%s until event ends",
    },
    zhCN = {
        Waiting = "下一个活动在: %s",
        Running = "%s 直到事件结束",
    },
    deDE = {
        Waiting = "Nächste Veranstaltung ist in: %s",
        Running = "bis zum Ende der Veranstaltung: %s",
    },
}
 
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)
  Reply With Quote
02-18-24, 01:52 AM   #24
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Remove the quotes from around "L.Waiting" and "L.Running"

Lua Code:
  1. local msg = L.Waiting
  2. if inevent then
  3.     msg = L.Running
  4. end

You can test by using
Code:
local locale = "deDE"
-- or
local locale = "zhCN"
instead of
Code:
local locale = GetLocale()
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-18-24 at 01:57 AM.
  Reply With Quote
02-18-24, 03:51 AM   #25
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Fizzlemizz View Post
Remove the quotes from around "L.Waiting" and "L.Running"

Lua Code:
  1. local msg = L.Waiting
  2. if inevent then
  3.     msg = L.Running
  4. end

You can test by using
Code:
local locale = "deDE"
-- or
local locale = "zhCN"
instead of
Code:
local locale = GetLocale()
Yes, it all worked. I'm not that good at LUA code yet, but I read a lot on this topic.
In one of the forum topics, I found your advice on how to make a window that can be moved around the screen. And I was able to apply this to my "button" and now it can be moved

I am very happy that I found this great forum.
  Reply With Quote
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: 112
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
02-18-24, 08:17 AM   #27
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
I've modified the message texts to allow for colouring of the time portion.
(my editor seems to have swallowed the chinese characters)

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(20)
  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. -- first %s is replaced by the color. The second is replaced by the time. |r resets the color back to default
  35. local Localizations = {
  36.     enUS = {
  37.         Waiting = "Next event is in: %s%s|r",
  38.         Running = "%s%s|r until event ends",
  39.     },
  40.     zhCN = {
  41.         Waiting = "??????: %s%s|r",
  42.         Running = "%s%s|r ??????",
  43.     },
  44.     deDE = {
  45.         Waiting = "Nächste Veranstaltung ist in: %s%s|r",
  46.         Running = "bis zum Ende der Veranstaltung: %s%s|r",
  47.     },
  48. }
  49.  
  50. local locale = GetLocale()
  51. local L = Localizations[locale] or Localizations.enUS -- Default to enUS if locale doesn't exist in the table
  52.  
  53. ------------------------------------------------------------------------------------------------------
  54. -- These might be converted to Saved Variables so each character can determine
  55. -- wether or not to play a sound, the alert times and colors and sound to play.
  56. -- If so then most of the code below will have to move into an event handler for
  57. -- the PLAYER_LOGIN or PLAYER_ENTERING_WORLD event.
  58. local useColor = true
  59. local useSound = true
  60. local alert1 = 600 -- Alarm 1 set to 5 minutes before event
  61. local alert1Color = "|cffffff00" -- Yellow
  62. local alert2 = 30 -- Alarm 2 set to 30 seconds before event
  63. local alert2Color = "|cffff0000" -- Red
  64. local soundKit = 32585 -- Alarm sound
  65. ------------------------------------------------------------------------------------------------------
  66.  
  67. local function printTime(timetotrun, inevent)
  68.     local hideSeconds = timetotrun >= 120
  69.     local msg = L.Waiting
  70.     local msgColor = "|cffffffff"
  71.     if inevent then
  72.         msg = L.Running
  73.     else
  74.         if useColor and timetotrun <= alert2 then
  75.             msgColor = alert2Color
  76.         elseif timetotrun <= alert1 then
  77.             if useSound and not ZAMROTimer.Alerted then
  78.                 ZAMROTimer.Alerted = true
  79.                 PlaySound(soundKit, "Master")
  80.             end
  81.             if useColor then
  82.                 msgColor = alert1Color
  83.             end
  84.         end
  85.     end
  86.     f.text:SetText(format(msg, msgColor, SecondsToTime(timetotrun, hideSeconds)))
  87. end
  88.  
  89. regionEventStartTime = {
  90.     [1] = { -- eu
  91.         starttime = 1670331660,
  92.         eventDuration = 900,
  93.         eventIntervalInSeconds = 5400,
  94.         enable = true,
  95.         datablock = {}
  96.     },
  97. }
  98.  
  99. local inEvent, timeToRun
  100. local eventTime = regionEventStartTime[1].eventDuration -- Time the event runs in seconds(15 mins)
  101. local waitTime = regionEventStartTime[1].eventIntervalInSeconds -- Time between events in seconds (90 mins)
  102. local startTime = regionEventStartTime[1].starttime -- Start time from the table
  103. local serverTime = GetServerTime()
  104. local timeToEvent = (startTime - serverTime) % waitTime -- Remaining time before next event starts
  105.  
  106. if timeToEvent > (waitTime - eventTime) then -- Is there between 1:15 and 1:30 to go? If so, we're in the event
  107.     inEvent = true
  108.     timeToRun = eventTime - (waitTime - timeToEvent)
  109. else                    -- Otherwise, set the ticker timer to time to next event
  110.     inEvent = false
  111.     timeToRun = timeToEvent
  112. end
  113. local ticker = C_Timer.NewTicker(1, function()
  114.     if timeToRun > 0 then
  115.         timeToRun = timeToRun - 1
  116.         printTime(timeToRun, inEvent)
  117.         return
  118.     end
  119.     ZAMROTimer.Alerted = false
  120.     if inEvent then -- The event just finished
  121.         inEvent = false
  122.         timeToRun = waitTime - eventTime -- Reset ticker timer to 90 minutes wait time minus 15 mins event time
  123.     else  -- Waiting for the next event just expired
  124.         inEvent = true
  125.         timeToRun = eventTime -- And the event is running
  126.     end
  127.     printTime(timeToRun, inEvent)
  128. end)
  129. printTime(timeToRun, inEvent)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-18-24 at 08:21 AM.
  Reply With Quote
02-18-24, 10:35 PM   #28
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Fizzlemizz View Post
I've modified the message texts to allow for colouring of the time portion.
(my editor seems to have swallowed the chinese characters)

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(20)
  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. -- first %s is replaced by the color. The second is replaced by the time. |r resets the color back to default
  35. local Localizations = {
  36.     enUS = {
  37.         Waiting = "Next event is in: %s%s|r",
  38.         Running = "%s%s|r until event ends",
  39.     },
  40.     zhCN = {
  41.         Waiting = "??????: %s%s|r",
  42.         Running = "%s%s|r ??????",
  43.     },
  44.     deDE = {
  45.         Waiting = "Nächste Veranstaltung ist in: %s%s|r",
  46.         Running = "bis zum Ende der Veranstaltung: %s%s|r",
  47.     },
  48. }
  49.  
  50. local locale = GetLocale()
  51. local L = Localizations[locale] or Localizations.enUS -- Default to enUS if locale doesn't exist in the table
  52.  
  53. ------------------------------------------------------------------------------------------------------
  54. -- These might be converted to Saved Variables so each character can determine
  55. -- wether or not to play a sound, the alert times and colors and sound to play.
  56. -- If so then most of the code below will have to move into an event handler for
  57. -- the PLAYER_LOGIN or PLAYER_ENTERING_WORLD event.
  58. local useColor = true
  59. local useSound = true
  60. local alert1 = 600 -- Alarm 1 set to 5 minutes before event
  61. local alert1Color = "|cffffff00" -- Yellow
  62. local alert2 = 30 -- Alarm 2 set to 30 seconds before event
  63. local alert2Color = "|cffff0000" -- Red
  64. local soundKit = 32585 -- Alarm sound
  65. ------------------------------------------------------------------------------------------------------
  66.  
  67. local function printTime(timetotrun, inevent)
  68.     local hideSeconds = timetotrun >= 120
  69.     local msg = L.Waiting
  70.     local msgColor = "|cffffffff"
  71.     if inevent then
  72.         msg = L.Running
  73.     else
  74.         if useColor and timetotrun <= alert2 then
  75.             msgColor = alert2Color
  76.         elseif timetotrun <= alert1 then
  77.             if useSound and not ZAMROTimer.Alerted then
  78.                 ZAMROTimer.Alerted = true
  79.                 PlaySound(soundKit, "Master")
  80.             end
  81.             if useColor then
  82.                 msgColor = alert1Color
  83.             end
  84.         end
  85.     end
  86.     f.text:SetText(format(msg, msgColor, SecondsToTime(timetotrun, hideSeconds)))
  87. end
  88.  
  89. regionEventStartTime = {
  90.     [1] = { -- eu
  91.         starttime = 1670331660,
  92.         eventDuration = 900,
  93.         eventIntervalInSeconds = 5400,
  94.         enable = true,
  95.         datablock = {}
  96.     },
  97. }
  98.  
  99. local inEvent, timeToRun
  100. local eventTime = regionEventStartTime[1].eventDuration -- Time the event runs in seconds(15 mins)
  101. local waitTime = regionEventStartTime[1].eventIntervalInSeconds -- Time between events in seconds (90 mins)
  102. local startTime = regionEventStartTime[1].starttime -- Start time from the table
  103. local serverTime = GetServerTime()
  104. local timeToEvent = (startTime - serverTime) % waitTime -- Remaining time before next event starts
  105.  
  106. if timeToEvent > (waitTime - eventTime) then -- Is there between 1:15 and 1:30 to go? If so, we're in the event
  107.     inEvent = true
  108.     timeToRun = eventTime - (waitTime - timeToEvent)
  109. else                    -- Otherwise, set the ticker timer to time to next event
  110.     inEvent = false
  111.     timeToRun = timeToEvent
  112. end
  113. local ticker = C_Timer.NewTicker(1, function()
  114.     if timeToRun > 0 then
  115.         timeToRun = timeToRun - 1
  116.         printTime(timeToRun, inEvent)
  117.         return
  118.     end
  119.     ZAMROTimer.Alerted = false
  120.     if inEvent then -- The event just finished
  121.         inEvent = false
  122.         timeToRun = waitTime - eventTime -- Reset ticker timer to 90 minutes wait time minus 15 mins event time
  123.     else  -- Waiting for the next event just expired
  124.         inEvent = true
  125.         timeToRun = eventTime -- And the event is running
  126.     end
  127.     printTime(timeToRun, inEvent)
  128. end)
  129. printTime(timeToRun, inEvent)
Hi. Thank you very much. I haven't fully tested it yet, but it seems to be working.
(I copied incorrectly and forgot to copy one character, but now everything is ok)

Last edited by Hubb777 : 02-18-24 at 10:42 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Timer with an interval of 1 hour and 30 minutes


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off