WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Timer with an interval of 1 hour and 30 minutes (https://www.wowinterface.com/forums/showthread.php?t=59795)

Hubb777 02-15-24 05:41 AM

Timer with an interval of 1 hour and 30 minutes
 
Hi. I was able to make a timer. But I can't figure out how to make it with an interval of 1 hour and 30 minutes.
Code:

local frame_x = 0     
local frame_y = -200   
f = CreateFrame("Button", "ZAMROTimer", UIParent, "UIDropDownMenuTemplate")
f:SetWidth(255)                                           
f:SetHeight(20)
f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
f.text:SetTextHeight(15)
f.text:SetAllPoints(f)
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)
----------------------------------------------------------------
if (not Region) then Region={} end
----------------------------------------------------------------
local w = "|cffffffff"
local o = "|cff00ff00"
----------------------------------------------------------------
local M, H, D, S, ZAM, ZAMROlasts, reg, reg2, info, unkForm, ZAMROUnc, ZAMROlastsUnc
if GetLocale() == "ruRU" then
M = "м "
H = "ч "
D = "д "
S = "с"
ZAM = "|cffFFFF33Большое Пиршество: "
ZAMROUnc = ""
ZAMROlastsUnc = ""
reg = ""
reg2 = ""
info = ""
unkForm = ""
relDate = ""
else
M = "m "
H = "h "
D = "d "
S = "s"
ZAM = "|cffFFFF33Community Feast: "
ZAMROUnc = ""
ZAMROlastsUnc = ""
reg = ""
reg2 = ""
info = ""
unkForm = ""
relDate = ""
end
----------------------------------------------------------------
local function ZAMROTimerCOMMAND(msg, editbox)
msg = msg:lower()
if msg == "eu" then
DEFAULT_CHAT_FRAME:AddMessage("|cffff8a00ZAMROTimer|r: "..reg.." |cff00ff00EU |cffdcdcdc(CET)")
Region = {"EU"}
else
DEFAULT_CHAT_FRAME:AddMessage("|cffff8a00ZAMROTimer|r: "..unkForm)
end
end
SlashCmdList["ZAMROTimer"] = ZAMROTimerCOMMAND
----------------------------------------------------------------
local menu = {
    { text = reg2, notCheckable = true, isTitle = true},
    { text = "|cff00ff00EU |cffdcdcdc(CET)", notCheckable = true, func = function()
        DEFAULT_CHAT_FRAME:AddMessage("|cffff8a00ZAMROTimer|r: "..reg.." |cff00ff00EU |cffdcdcdc(CET)")
        Region = {"EU"} end },
    { text = info, notCheckable = true, func = function() ZAMTimeInfoMSG() end },
}
----------------------------------------------------------------
f:SetScript("OnUpdate",function(this)
local ZAMRO_release = 1707996600
if Region[1] == "EU"
then
ZAMRO_release = 1707996600
end
----------------------------------------------------------------
local MP_D, MP_Hr, MP_M, MP_S, ZAMROTime_MP

if time() <= ZAMRO_release then
MP_D = floor((ZAMRO_release-time())/86400)
MP_H = floor(((ZAMRO_release-time())-(MP_D*86400))/1440)
MP_M = floor(((ZAMRO_release-time())-((MP_D*86400)+(MP_H*1440)))/60)
MP_S = floor((ZAMRO_release-time())-((MP_D*86400)+(MP_H*1440)+(MP_M*60)))
ZAMROTime_MP = ZAM..o..MP_D..w..D..o..MP_H..w..H..o..MP_M..w..M..o..MP_S..w..S
ZAMROTime_MP_Report = ZAMROUnc..MP_D..D..MP_H..H..MP_M..M..MP_S..S
else
MP_D = floor((time()-ZAMRO_release)/85500)
MP_H = floor(((time()-ZAMRO_release)-(MP_D*85500))/1440)
MP_M = floor(((time()-ZAMRO_release)-((MP_D*85500)+(MP_H*1440)))/60)
MP_S = floor((time()-ZAMRO_release)-((MP_D*85500)+(MP_H*1440)+(MP_M*60)))
ZAMROTime_MP = ZAM..o..MP_D..w..D..o..MP_H..w..H..o..MP_M..w..M..o..MP_S..w..S
ZAMROTime_MP_Report = ZAMROlastsUnc..MP_D..D..MP_H..H..MP_M..M..MP_S..S
end

function ZAMTimeInfoMSG()
DEFAULT_CHAT_FRAME:AddMessage("|cffff8a00ZAMROTimer|r: "..ZAMROTime_MP)
DEFAULT_CHAT_FRAME:AddMessage("|cffff8a00ZAMROTimer|r: "..reg2.." |cff00ff00"..Region[1])   
DEFAULT_CHAT_FRAME:AddMessage("|cffff8a00ZAMROTimer|r: "..relDate.."|cff00ff00"..date("%X %d.%m.%Y",ZAMRO_release))
end
----------------------------------------------------------------
this.text:SetText(ZAMROTime_MP)
end)
----------------------------------------------------------------
f:SetScript("OnClick",function(self,button,down)
if button == "RightButton" then
EasyMenu(menu, f, "cursor", 0,0, "MENU")
end
if ((button == "LeftButton") and (IsAltKeyDown() or IsControlKeyDown() or IsShiftKeyDown())) then
 if ChatEdit_GetActiveWindow() then ChatEdit_GetActiveWindow():Insert(ZAMROTime_MP_Report) end end
end)

f:Click("RightButton")


Xrystal 02-15-24 06:52 AM

There is a Timer system in wow.

https://warcraft.wiki.gg/wiki/API_C_Timer.After

With 2 other options depending on requirements.

There are some code examples in there so hopefully you will see how it can work for your task.

Hubb777 02-15-24 07:30 AM

Quote:

Originally Posted by Xrystal (Post 343324)
There is a Timer system in wow.

https://warcraft.wiki.gg/wiki/API_C_Timer.After

With 2 other options depending on requirements.

There are some code examples in there so hopefully you will see how it can work for your task.

Hi. Can I have a more detailed example?

Xrystal 02-15-24 07:57 AM

I've never used it myself. But I would have thought the example they gave was informative enough.


Lua Code:
  1. local function bootlegRepeatingTimer()
  2.  
  3.     print(GetTime())                                    >>> Code executed
  4.  
  5.     C_Timer.After(1, bootlegRepeatingTimer)     >>> Causes the function to occur again after 1 second
  6. end
  7. bootlegRepeatingTimer()                 >>> Start the cycle

This example is a timer of 1 second that calls itself making it a repeating timer.

Inside that function you could have it do what you want so that every 1 second ( in this example ) it will redo them. This can even be another function where you do all the functionality.

Hubb777 02-15-24 08:33 AM

Quote:

Originally Posted by Xrystal (Post 343326)
I've never used it myself. But I would have thought the example they gave was informative enough.


Lua Code:
  1. local function bootlegRepeatingTimer()
  2.  
  3.     print(GetTime())                                    >>> Code executed
  4.  
  5.     C_Timer.After(1, bootlegRepeatingTimer)     >>> Causes the function to occur again after 1 second
  6. end
  7. bootlegRepeatingTimer()                 >>> Start the cycle

This example is a timer of 1 second that calls itself making it a repeating timer.

Inside that function you could have it do what you want so that every 1 second ( in this example ) it will redo them. This can even be another function where you do all the functionality.


I don't understand how to insert this code into mine so that the time is displayed. I've tried different ways, but the timer doesn't show up if I change the code.

Xrystal 02-15-24 10:28 AM

What exactly were you hoping to do ?

Maybe knowing what you wanted to happen when the timer triggers every 1 hr 30 minutes would let us know what part of your code is and isn't necessary with access to the timer functions.

Hubb777 02-15-24 10:29 PM

Quote:

Originally Posted by Xrystal (Post 343328)
What exactly were you hoping to do ?

Maybe knowing what you wanted to happen when the timer triggers every 1 hr 30 minutes would let us know what part of your code is and isn't necessary with access to the timer functions.

Code:

if time() <= ZAMRO_release then
MP_D = floor((ZAMRO_release-time())/86400)
MP_H = floor(((ZAMRO_release-time())-(MP_D*86400))/1440)
MP_M = floor(((ZAMRO_release-time())-((MP_D*86400)+(MP_H*1440)))/60)
MP_S = floor((ZAMRO_release-time())-((MP_D*86400)+(MP_H*1440)+(MP_M*60)))
ZAMROTime_MP = ZAM..o..MP_D..w..D..o..MP_H..w..H..o..MP_M..w..M..o..MP_S..w..S
ZAMROTime_MP_Report = ZAMROUnc..MP_D..D..MP_H..H..MP_M..M..MP_S..S
else
MP_D = floor((time()-ZAMRO_release)/85500)
MP_H = floor(((time()-ZAMRO_release)-(MP_D*85500))/1440)
MP_M = floor(((time()-ZAMRO_release)-((MP_D*85500)+(MP_H*1440)))/60)
MP_S = floor((time()-ZAMRO_release)-((MP_D*85500)+(MP_H*1440)+(MP_M*60)))
ZAMROTime_MP = ZAM..o..MP_D..w..D..o..MP_H..w..H..o..MP_M..w..M..o..MP_S..w..S
ZAMROTime_MP_Report = ZAMROlastsUnc..MP_D..D..MP_H..H..MP_M..M..MP_S..S
end

I understand that this part of the code is responsible for time. But it's just a countdown to a certain time. How do I change this code so that it is reset to zero every 1 hour and 30 minutes?

Fizzlemizz 02-15-24 11:55 PM

At 2 minutes remaining it starts adding the seconds to the diplsayd text (local hideSeconds = timetotrun >= 120).

Lua Code:
  1. local Backdrop = {
  2.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  3. }
  4.  
  5. local frame_x = 0      
  6. local frame_y = -200    
  7. f = CreateFrame("Button", "ZAMROTimer", UIParent, "BackdropTemplate")
  8. f:SetWidth(255)                                            
  9. f:SetHeight(20)
  10. f:SetBackdrop(Backdrop)
  11. f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
  12. f.text:SetTextHeight(15)
  13. f.text:SetPoint("CENTER")
  14. f:SetClampedToScreen(true)
  15. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  16. f:EnableMouse(true)
  17. f:SetMovable(true)
  18. f:RegisterForDrag("LeftButton")
  19. f:RegisterForClicks("AnyUp")
  20. f:Show()
  21. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  22. f:SetScript("OnDragStart",function(this)
  23.    this:StartMoving()
  24. end)
  25. f:SetScript("OnDragStop",function(this)  
  26.    this:StopMovingOrSizing()
  27.    frame_x,frame_y = this:GetCenter()
  28.    frame_x = frame_x - GetScreenWidth() / 2
  29.    frame_y = frame_y - GetScreenHeight() / 2
  30.    this:ClearAllPoints()
  31.    this:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  32. end)
  33. local timeToRun = 5400
  34. local function printTime(timetotrun)
  35.     local hideSeconds = timetotrun >= 120
  36.     f.text:SetText(format("Next update in: %s", SecondsToTime(timetotrun, hideSeconds)))
  37. end
  38. local ticker = C_Timer.NewTicker(1, function()
  39.    if timeToRun > 0 then
  40.       timeToRun = timeToRun - 1
  41.       printTime(timeToRun)
  42.       return
  43.    end
  44.    timeToRun = 5400 -- reset timer to 90 mins
  45.    printTime(timeToRun)
  46.    -- do whatever after 1 hour 30
  47. end)
  48. printTime(timeToRun)

Hubb777 02-16-24 12:46 AM

Quote:

Originally Posted by Fizzlemizz (Post 343339)
At 2 minutes remaining it starts adding the seconds to the diplsayd text (local hideSeconds = timetotrun >= 120).

Lua Code:
  1. local Backdrop = {
  2.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  3. }
  4.  
  5. local frame_x = 0      
  6. local frame_y = -200    
  7. f = CreateFrame("Button", "ZAMROTimer", UIParent, "BackdropTemplate")
  8. f:SetWidth(255)                                            
  9. f:SetHeight(20)
  10. f:SetBackdrop(Backdrop)
  11. f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
  12. f.text:SetTextHeight(15)
  13. f.text:SetPoint("CENTER")
  14. f:SetClampedToScreen(true)
  15. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  16. f:EnableMouse(true)
  17. f:SetMovable(true)
  18. f:RegisterForDrag("LeftButton")
  19. f:RegisterForClicks("AnyUp")
  20. f:Show()
  21. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  22. f:SetScript("OnDragStart",function(this)
  23.    this:StartMoving()
  24. end)
  25. f:SetScript("OnDragStop",function(this)  
  26.    this:StopMovingOrSizing()
  27.    frame_x,frame_y = this:GetCenter()
  28.    frame_x = frame_x - GetScreenWidth() / 2
  29.    frame_y = frame_y - GetScreenHeight() / 2
  30.    this:ClearAllPoints()
  31.    this:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  32. end)
  33. local timeToRun = 5400
  34. local function printTime(timetotrun)
  35.     local hideSeconds = timetotrun >= 120
  36.     f.text:SetText(format("Next update in: %s", SecondsToTime(timetotrun, hideSeconds)))
  37. end
  38. local ticker = C_Timer.NewTicker(1, function()
  39.    if timeToRun > 0 then
  40.       timeToRun = timeToRun - 1
  41.       printTime(timeToRun)
  42.       return
  43.    end
  44.    timeToRun = 5400 -- reset timer to 90 mins
  45.    printTime(timeToRun)
  46.    -- do whatever after 1 hour 30
  47. end)
  48. printTime(timeToRun)

I need the event to start at a certain time
Code:

local communityFeastTime = {
        ["EU"] = 1679749200, -- 21:00
}

The event itself starts every 1.5 hours. Lasts 15 minutes
Code:

local feastTime = communityFeastTime[region]
        if feastTime then
                local currentTime = time()
                local duration = 5400 -- 1.5hrs
                local elapsed = mod(currentTime - feastTime, duration)
                local nextTime = duration - elapsed + currentTime

                addTitle(COMMUNITY_FEAST)
                if currentTime - (nextTime-duration) < 900 then r,g,b = 0,1,0 else r,g,b = .6,.6,.6 end -- green text if progressing
                GameTooltip:AddDoubleLine(date("%m/%d %H:%M", nextTime-duration*2), date("%m/%d %H:%M", nextTime-duration), .6,.6,.6, r,g,b)
                GameTooltip:AddDoubleLine(date("%m/%d %H:%M", nextTime), date("%m/%d %H:%M", nextTime+duration), 1,1,1, 1,1,1)
        end


Fizzlemizz 02-16-24 12:54 AM

You could use time() in the ticker (or an OnUpdate) and once it reaches the assigned time change over to using the countdown.

You can cancel a ticker and start a new one if you want seperate processes

Hubb777 02-16-24 01:08 AM

Quote:

Originally Posted by Fizzlemizz (Post 343342)
You could use time() in the ticker (or an OnUpdate) and once it reaches the assigned time change over to using the countdown.

You can cancel a ticker and start a new one if you want seperate processes

The main problem is that the timer starts counting down from the moment the addon is turned on and you enter the game. And it needs to do a 1.5 hour countdown from
Code:

local communityFeastTime = {
        ["EU"] = 1679749200, -- 21:00
}


Fizzlemizz 02-16-24 03:21 AM

The math might be a bit sketchy and long winded to show the "what" of it so test it but something like:
I don't know the event so I'm assuming the event is runs every 1.5 hours of the day and the start time (21:00) is the "known" time one of the events happens each day in that region (EU). If it's something else like the event only runs from 21:00 to 24:00 then this is not what you're looking for.

Lua Code:
  1. local Backdrop = {
  2.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  3. }
  4.  
  5. local frame_x = 0      
  6. local frame_y = -200    
  7. f = CreateFrame("Button", "ZAMROTimer", UIParent, "BackdropTemplate")
  8. f:SetWidth(255)                                            
  9. f:SetHeight(20)
  10. f:SetBackdrop(Backdrop)
  11. f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
  12. f.text:SetTextHeight(15)
  13. f.text:SetPoint("CENTER")
  14. f:SetClampedToScreen(true)
  15. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  16. f:EnableMouse(true)
  17. f:SetMovable(true)
  18. f:RegisterForDrag("LeftButton")
  19. f:RegisterForClicks("AnyUp")
  20. f:Show()
  21. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  22. f:SetScript("OnDragStart",function(this)
  23.    this:StartMoving()
  24. end)
  25. f:SetScript("OnDragStop",function(this)  
  26.    this:StopMovingOrSizing()
  27.    frame_x,frame_y = this:GetCenter()
  28.    frame_x = frame_x - GetScreenWidth() / 2
  29.    frame_y = frame_y - GetScreenHeight() / 2
  30.    this:ClearAllPoints()
  31.    this:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  32. end)
  33.  
  34. local function printTime(timetotrun)
  35.     local hideSeconds = timetotrun >= 120
  36.     f.text:SetText(format("Next update in: %s", SecondsToTime(timetotrun, hideSeconds)))
  37. end
  38. local communityFeastTime = {
  39.     ["EU"] = 75600, -- 21:00 in seconds ie. (21 * 60 * 60)
  40. }
  41.  
  42. local startTime = communityFeastTime.EU -- start time from the table
  43. local t = date("*t", time()) -- the time now
  44. local timeToSeconds = ((t.hour * 60) * 60) + (t.min * 60) + t.sec -- convert time now to seconds
  45. local timeToEvent = (startTime - timeToSeconds) % 5400 -- remaining time before next event starts
  46. local timeToRun = timeToEvent -- set the ticker timer to time to next event
  47. local ticker = C_Timer.NewTicker(1, function()
  48.    if timeToRun > 0 then
  49.       timeToRun = timeToRun - 1
  50.       printTime(timeToRun)
  51.       return
  52.    end
  53.    timeToRun = 5400 -- reset ticker timer to 90 mins
  54.    printTime(timeToRun)
  55.    -- do whatever after 1 hour 30
  56. end)
  57. printTime(timeToRun)

Hubb777 02-16-24 05:06 AM

Quote:

Originally Posted by Fizzlemizz (Post 343344)
The math might be a bit sketchy and long winded to show the "what" of it so test it but something like:
I don't know the event so I'm assuming the event is runs every 1.5 hours of the day and the start time (21:00) is the "known" time one of the events happens each day in that region (EU). If it's something else like the event only runs from 21:00 to 24:00 then this is not what you're looking for.

Lua Code:
  1. local Backdrop = {
  2.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  3. }
  4.  
  5. local frame_x = 0      
  6. local frame_y = -200    
  7. f = CreateFrame("Button", "ZAMROTimer", UIParent, "BackdropTemplate")
  8. f:SetWidth(255)                                            
  9. f:SetHeight(20)
  10. f:SetBackdrop(Backdrop)
  11. f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
  12. f.text:SetTextHeight(15)
  13. f.text:SetPoint("CENTER")
  14. f:SetClampedToScreen(true)
  15. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  16. f:EnableMouse(true)
  17. f:SetMovable(true)
  18. f:RegisterForDrag("LeftButton")
  19. f:RegisterForClicks("AnyUp")
  20. f:Show()
  21. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  22. f:SetScript("OnDragStart",function(this)
  23.    this:StartMoving()
  24. end)
  25. f:SetScript("OnDragStop",function(this)  
  26.    this:StopMovingOrSizing()
  27.    frame_x,frame_y = this:GetCenter()
  28.    frame_x = frame_x - GetScreenWidth() / 2
  29.    frame_y = frame_y - GetScreenHeight() / 2
  30.    this:ClearAllPoints()
  31.    this:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  32. end)
  33.  
  34. local function printTime(timetotrun)
  35.     local hideSeconds = timetotrun >= 120
  36.     f.text:SetText(format("Next update in: %s", SecondsToTime(timetotrun, hideSeconds)))
  37. end
  38. local communityFeastTime = {
  39.     ["EU"] = 75600, -- 21:00 in seconds ie. (21 * 60 * 60)
  40. }
  41.  
  42. local startTime = communityFeastTime.EU -- start time from the table
  43. local t = date("*t", time()) -- the time now
  44. local timeToSeconds = ((t.hour * 60) * 60) + (t.min * 60) + t.sec -- convert time now to seconds
  45. local timeToEvent = (startTime - timeToSeconds) % 5400 -- remaining time before next event starts
  46. local timeToRun = timeToEvent -- set the ticker timer to time to next event
  47. local ticker = C_Timer.NewTicker(1, function()
  48.    if timeToRun > 0 then
  49.       timeToRun = timeToRun - 1
  50.       printTime(timeToRun)
  51.       return
  52.    end
  53.    timeToRun = 5400 -- reset ticker timer to 90 mins
  54.    printTime(timeToRun)
  55.    -- do whatever after 1 hour 30
  56. end)
  57. printTime(timeToRun)

Yes, it works great. You've helped me a lot. You are the best!!!

Another question is can I add another line to the variable?

1. So that after the start of the event, within 15 minutes (900 seconds), there is another message "the event is underway".
I understand this can be done through, but how?

Code:

eventDuration = 900

Fizzlemizz 02-16-24 09:44 AM

I'm not sure I understand the question. Does the "the event is underway" message last for 15 minutes after the event starts or does it appear 15 minutes after the event starts (seems a bit strange but...) and if so how long does it last? You need to be specific about what you want to happen when.

Hubb777 02-16-24 10:24 PM

Quote:

Originally Posted by Fizzlemizz (Post 343347)
I'm not sure I understand the question. Does the "the event is underway" message last for 15 minutes after the event starts or does it appear 15 minutes after the event starts (seems a bit strange but...) and if so how long does it last? You need to be specific about what you want to happen when.

1. The event starts at an interval of 1 hour and 30 minutes. This is the full cycle of the beginning of the event:

01:00
02:30
04:00
05:30
07:00
08:30
10:00
11:30
13:00
14:30
16:00
17:30
19:00
20:30
22:00
23:30

2. The event always runs for 15 minutes. Here is the start and end cycle of the event.
01:15
02:45
04:15
05:45
07:15
08:45
10:15
11:45
13:15
14:45
16:15
17:45
19:15
20:45
22:15
23:45

Now the inscription is displayed all the time - Next update in, it is necessary that while the event is going on (these are the 15 minutes), instead of Next update in, there should be an an event in progress inscription.

Fizzlemizz 02-16-24 11:44 PM

Try:
Lua Code:
  1. local Backdrop = {
  2.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  3. }
  4.  
  5. local frame_x = 0      
  6. local frame_y = -200    
  7. f = CreateFrame("Button", "ZAMROTimer", UIParent, "BackdropTemplate")
  8. f:SetWidth(255)                                            
  9. f:SetHeight(20)
  10. f:SetBackdrop(Backdrop)
  11. f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
  12. f.text:SetTextHeight(15)
  13. f.text:SetPoint("CENTER")
  14. f:SetClampedToScreen(true)
  15. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  16. f:EnableMouse(true)
  17. f:SetMovable(true)
  18. f:RegisterForDrag("LeftButton")
  19. f:RegisterForClicks("AnyUp")
  20. f:Show()
  21. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  22. f:SetScript("OnDragStart",function(this)
  23.    this:StartMoving()
  24. end)
  25. f:SetScript("OnDragStop",function(this)  
  26.    this:StopMovingOrSizing()
  27.    frame_x,frame_y = this:GetCenter()
  28.    frame_x = frame_x - GetScreenWidth() / 2
  29.    frame_y = frame_y - GetScreenHeight() / 2
  30.    this:ClearAllPoints()
  31.    this:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  32. end)
  33.  
  34. local function printTime(timetotrun, inevent)
  35.     local hideSeconds = timetotrun >= 120
  36.     local msg = "Next event is in: %s"
  37.     if inevent then
  38.         msg = "%s until event ends"
  39.     end
  40.     f.text:SetText(format(msg, SecondsToTime(timetotrun, hideSeconds)))
  41. end
  42. local communityFeastTime = { -- Known region start time(s)
  43.     ["EU"] = 75600, -- 21:00 in seconds ie. (21 * 60 * 60)
  44. }
  45. local eventTime = 15 * 60 -- Time the event runs in seconds(15 mins)
  46. local waitTime = 90 * 60 -- Time between events in seconds (90 mins)
  47. local inEvent, timeToRun
  48.  
  49. local startTime = communityFeastTime.EU -- Start time from the table
  50. local timeNow = date("*t", time()) -- The time at login
  51. local timeToSeconds = ((timeNow.hour * 60) * 60) + (timeNow.min * 60) + timeNow.sec -- Convert time now to seconds
  52. local timeToEvent = (startTime - timeToSeconds) % waitTime -- Remaining time before next event starts
  53. if timeToEvent > (waitTime - eventTime) then -- Is there between 1:15 and 1:30 to go? If so, we're in the event
  54.     inEvent = true
  55.     timeToRun = waitTime - timeToEvent
  56. else                    -- Otherwise, set the ticker timer to time to next event
  57.     inEvent = false
  58.     timeToRun = timeToEvent
  59. end
  60. local ticker = C_Timer.NewTicker(1, function()
  61.     if timeToRun > 0 then
  62.         timeToRun = timeToRun - 1
  63.         printTime(timeToRun, inEvent)
  64.         return
  65.     end
  66.     if inEvent then -- The event just finished
  67.         inEvent = false
  68.         timeToRun = waitTime - eventTime -- Reset ticker timer to 90 minutes wait time minus 15 mins event time
  69.     else  -- Waiting for the next event just expired
  70.         inEvent = true
  71.         timeToRun = eventTime -- And the event is running
  72.     end
  73.     printTime(timeToRun, inEvent)
  74. end)
  75. printTime(timeToRun, inEvent)

Hubb777 02-17-24 01:22 AM

Quote:

Originally Posted by Fizzlemizz (Post 343349)
Try:
Lua Code:
  1. local Backdrop = {
  2.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  3. }
  4.  
  5. local frame_x = 0      
  6. local frame_y = -200    
  7. f = CreateFrame("Button", "ZAMROTimer", UIParent, "BackdropTemplate")
  8. f:SetWidth(255)                                            
  9. f:SetHeight(20)
  10. f:SetBackdrop(Backdrop)
  11. f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
  12. f.text:SetTextHeight(15)
  13. f.text:SetPoint("CENTER")
  14. f:SetClampedToScreen(true)
  15. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  16. f:EnableMouse(true)
  17. f:SetMovable(true)
  18. f:RegisterForDrag("LeftButton")
  19. f:RegisterForClicks("AnyUp")
  20. f:Show()
  21. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  22. f:SetScript("OnDragStart",function(this)
  23.    this:StartMoving()
  24. end)
  25. f:SetScript("OnDragStop",function(this)  
  26.    this:StopMovingOrSizing()
  27.    frame_x,frame_y = this:GetCenter()
  28.    frame_x = frame_x - GetScreenWidth() / 2
  29.    frame_y = frame_y - GetScreenHeight() / 2
  30.    this:ClearAllPoints()
  31.    this:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  32. end)
  33.  
  34. local function printTime(timetotrun, inevent)
  35.     local hideSeconds = timetotrun >= 120
  36.     local msg = "Next event is in: %s"
  37.     if inevent then
  38.         msg = "%s until event ends"
  39.     end
  40.     f.text:SetText(format(msg, SecondsToTime(timetotrun, hideSeconds)))
  41. end
  42. local communityFeastTime = { -- Known region start time(s)
  43.     ["EU"] = 75600, -- 21:00 in seconds ie. (21 * 60 * 60)
  44. }
  45. local eventTime = 15 * 60 -- Time the event runs in seconds(15 mins)
  46. local waitTime = 90 * 60 -- Time between events in seconds (90 mins)
  47. local inEvent, timeToRun
  48.  
  49. local startTime = communityFeastTime.EU -- Start time from the table
  50. local timeNow = date("*t", time()) -- The time at login
  51. local timeToSeconds = ((timeNow.hour * 60) * 60) + (timeNow.min * 60) + timeNow.sec -- Convert time now to seconds
  52. local timeToEvent = (startTime - timeToSeconds) % waitTime -- Remaining time before next event starts
  53. if timeToEvent > (waitTime - eventTime) then -- Is there between 1:15 and 1:30 to go? If so, we're in the event
  54.     inEvent = true
  55.     timeToRun = waitTime - timeToEvent
  56. else                    -- Otherwise, set the ticker timer to time to next event
  57.     inEvent = false
  58.     timeToRun = timeToEvent
  59. end
  60. local ticker = C_Timer.NewTicker(1, function()
  61.    if timeToRun > 0 then
  62.       timeToRun = timeToRun - 1
  63.       printTime(timeToRun, inEvent)
  64.       return
  65.    end
  66.    if inEvent then -- The event is in progress
  67.     inEvent = false
  68.     timeToRun = waitTime -- Reset ticker timer to 90 mins
  69.    else  -- Waiting for the next event
  70.     inEvent = true
  71.     timeToRun = eventTime
  72.    end
  73.    printTime(timeToRun, inEvent)
  74. end)
  75. printTime(timeToRun, inEvent)

Hi. Yes, it worked. You've been very helpful. I will recommend this forum to everyone. Everyone here is very friendly.

UPD: I edited the code and replaced 120 with 0. The problem is that after completing the 15 minute timer, it started counting down 1.5 hours to the next event. Although there should be 1 hour and 15 minutes left.
The interval between events is 1 hour and 15 minutes.
The event lasts for 15 minutes.
For example: the event started at 10:00, ended at 10:15, after that the timer should show that the next event is at 11:30, and this code shows that the event will be at 11:45 (and it needs to be at 11:30)

This is fixed by the command /reload - as I understand it, the timer time is not reset every time. Is that why you have to prescribe?

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 function printTime(timetotrun, inevent)
    local hideSeconds = timetotrun >= 0
    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"] = 46800, -- 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 is in progress
    inEvent = false
    timeToRun = waitTime -- Reset ticker timer to 90 mins
  else  -- Waiting for the next event
    inEvent = true
    timeToRun = eventTime
  end
  printTime(timeToRun, inEvent)
end)
printTime(timeToRun, inEvent)


Fizzlemizz 02-17-24 09:40 AM

The time between the events is 90 minutes for the login test but once you've started the clock it's then reduced by 15 minutes (the time the event takes) which I didn't account for.

The ticker code would be:
Lua Code:
  1. local ticker = C_Timer.NewTicker(1, function()
  2.     if timeToRun > 0 then
  3.         timeToRun = timeToRun - 1
  4.         printTime(timeToRun, inEvent)
  5.         return
  6.     end
  7.     if inEvent then -- The event just finished
  8.         inEvent = false
  9.         timeToRun = waitTime - eventTime -- Reset ticker timer to 90 minutes wait time minus 15 mins event time
  10.     else  -- Waiting for the next event just expired
  11.         inEvent = true
  12.         timeToRun = eventTime -- And the event is running
  13.     end
  14.     printTime(timeToRun, inEvent)
  15. end)
  16. printTime(timeToRun, inEvent)

Also fixed in my previous post.

Hubb777 02-17-24 10:29 PM

Quote:

Originally Posted by Fizzlemizz (Post 343351)
The time between the events is 90 minutes for the login test but once you've started the clock it's then reduced by 15 minutes (the time the event takes) which I didn't account for.

The ticker code would be:
Lua Code:
  1. local ticker = C_Timer.NewTicker(1, function()
  2.     if timeToRun > 0 then
  3.         timeToRun = timeToRun - 1
  4.         printTime(timeToRun, inEvent)
  5.         return
  6.     end
  7.     if inEvent then -- The event just finished
  8.         inEvent = false
  9.         timeToRun = waitTime - eventTime -- Reset ticker timer to 90 minutes wait time minus 15 mins event time
  10.     else  -- Waiting for the next event just expired
  11.         inEvent = true
  12.         timeToRun = eventTime -- And the event is running
  13.     end
  14.     printTime(timeToRun, inEvent)
  15. end)
  16. printTime(timeToRun, inEvent)

Also fixed in my previous post.

So the time is taken locally? And if the player's time is different, will there be a discrepancy? Is it possible to make the start of time not in seconds, but using Unix Timestamp? https://www.unixtimestamp.com/
1708234200

Maybe these parts of the code will help
Code:

eFrame.regionEventStartTime = v.regionEventStartTime[GetCurrentRegion()]
Code:

local start_timestamp = GetServerTime() - self.regionEventStartTime
                local next_event = self.eventIntervalInSeconds - start_timestamp % self.eventIntervalInSeconds
                local spawning = self.eventIntervalInSeconds - next_event < self.eventDuration
                local remaining = self.eventDuration - (self.eventIntervalInSeconds - next_event)
                local showedTime = spawning and remaining or next_event


Code:

regionEventStartTime = {
                                [1] = 16862400102,},        -- eu
                        eventDuration = 900,
                        eventIntervalInSeconds = 5400,
                        enable = true,
                        datablock = {}
                },

According to the example that I want, an addon has been made - https://www.wowinterface.com/downloa...sionTimer.html

Fizzlemizz 02-17-24 11:20 PM

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):
Lua Code:
  1. local Backdrop = {
  2.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  3. }
  4.  
  5. local frame_x = 0    
  6. local frame_y = -200   
  7. f = CreateFrame("Button", "ZAMROTimer", UIParent, "BackdropTemplate")
  8. f:SetWidth(255)                                          
  9. f:SetHeight(20)
  10. f:SetBackdrop(Backdrop)
  11. f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
  12. f.text:SetTextHeight(15)
  13. f.text:SetPoint("CENTER")
  14. f:SetClampedToScreen(true)
  15. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  16. f:EnableMouse(true)
  17. f:SetMovable(true)
  18. f:RegisterForDrag("LeftButton")
  19. f:RegisterForClicks("AnyUp")
  20. f:Show()
  21. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  22. f:SetScript("OnDragStart",function(this)
  23.     this:StartMoving()
  24. end)
  25. f:SetScript("OnDragStop",function(this)  
  26.     this:StopMovingOrSizing()
  27.     frame_x,frame_y = this:GetCenter()
  28.     frame_x = frame_x - GetScreenWidth() / 2
  29.     frame_y = frame_y - GetScreenHeight() / 2
  30.     this:ClearAllPoints()
  31.     this:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  32. end)
  33.  
  34. local function printTime(timetotrun, inevent)
  35.     local hideSeconds = timetotrun >= 120
  36.     local msg = "Next event is in: %s"
  37.     if inevent then
  38.         msg = "%s until event ends"
  39.     end
  40.     f.text:SetText(format(msg, SecondsToTime(timetotrun, hideSeconds)))
  41. end
  42.  
  43.  
  44. regionEventStartTime = {
  45.     [1] = { -- eu
  46.         starttime = 16862400102,
  47.         eventDuration = 900,
  48.         eventIntervalInSeconds = 5400,
  49.         enable = true,
  50.         datablock = {}
  51.     },
  52. }
  53. local inEvent, timeToRun
  54. local eventTime = regionEventStartTime[1].eventDuration -- Time the event runs in seconds(15 mins)
  55. local waitTime = regionEventStartTime[1].eventIntervalInSeconds -- Time between events in seconds (90 mins)
  56. local startTime = regionEventStartTime[1].starttime -- Start time from the table
  57. local serverTime = GetServerTime()
  58. local timeToEvent = (startTime - serverTime) % waitTime -- Remaining time before next event starts
  59.  
  60. if timeToEvent > (waitTime - eventTime) then -- Is there between 1:15 and 1:30 to go? If so, we're in the event
  61.     inEvent = true
  62.     timeToRun = eventTime - (waitTime - timeToEvent)
  63. else                    -- Otherwise, set the ticker timer to time to next event
  64.     inEvent = false
  65.     timeToRun = timeToEvent
  66. end
  67. local ticker = C_Timer.NewTicker(1, function()
  68.     if timeToRun > 0 then
  69.         timeToRun = timeToRun - 1
  70.         printTime(timeToRun, inEvent)
  71.         return
  72.     end
  73.     if inEvent then -- The event just finished
  74.         inEvent = false
  75.         timeToRun = waitTime - eventTime -- Reset ticker timer to 90 minutes wait time minus 15 mins event time
  76.     else  -- Waiting for the next event just expired
  77.         inEvent = true
  78.         timeToRun = eventTime -- And the event is running
  79.     end
  80.     printTime(timeToRun, inEvent)
  81. end)
  82. printTime(timeToRun, inEvent)


All times are GMT -6. The time now is 04:14 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI