Thread Tools Display Modes
02-15-24, 05:41 AM   #1
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
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")
  Reply With Quote
02-15-24, 06:52 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
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.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
02-15-24, 07:30 AM   #3
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Xrystal View Post
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?
  Reply With Quote
02-15-24, 07:57 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
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.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 02-15-24 at 08:01 AM.
  Reply With Quote
02-15-24, 08:33 AM   #5
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Xrystal View Post
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.
  Reply With Quote
02-15-24, 10:28 AM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
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.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 02-15-24 at 10:31 AM.
  Reply With Quote
02-15-24, 10:29 PM   #7
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Xrystal View Post
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?
  Reply With Quote
02-15-24, 11:55 PM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-15-24 at 11:58 PM.
  Reply With Quote
02-16-24, 12:46 AM   #9
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
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
  Reply With Quote
02-16-24, 12:54 AM   #10
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-16-24 at 01:02 AM.
  Reply With Quote
02-16-24, 01:08 AM   #11
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
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
}
  Reply With Quote
02-16-24, 03:21 AM   #12
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-16-24 at 03:27 AM.
  Reply With Quote
02-16-24, 05:06 AM   #13
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
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
  Reply With Quote
02-16-24, 09:44 AM   #14
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-16-24 at 12:08 PM.
  Reply With Quote
02-16-24, 10:24 PM   #15
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'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.

Last edited by Hubb777 : 02-16-24 at 10:29 PM.
  Reply With Quote
02-16-24, 11:44 PM   #16
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-17-24 at 09:49 AM.
  Reply With Quote
02-17-24, 01:22 AM   #17
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
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)

Last edited by Hubb777 : 02-17-24 at 04:23 AM.
  Reply With Quote
02-17-24, 09:40 AM   #18
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-17-24 at 09:49 AM.
  Reply With Quote
02-17-24, 10:29 PM   #19
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
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

Last edited by Hubb777 : 02-17-24 at 10:48 PM.
  Reply With Quote
02-17-24, 11:20 PM   #20
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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)
__________________
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 12:28 AM.
  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