working timers
This commit is contained in:
3
lua/autorun/load_serverchatadverts.lua
Normal file
3
lua/autorun/load_serverchatadverts.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
if SERVER then
|
||||
include("sca_main.lua")
|
||||
end
|
||||
3
lua/sca_config.lua
Normal file
3
lua/sca_config.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
local conf = {}
|
||||
|
||||
return conf
|
||||
43
lua/sca_main.lua
Normal file
43
lua/sca_main.lua
Normal file
@@ -0,0 +1,43 @@
|
||||
local conf = include("sca_config.lua")
|
||||
local timeSynced = false
|
||||
|
||||
local function sca_loop()
|
||||
local intervalOffset = os.time() % 60
|
||||
print("intervalOffset: ", intervalOffset)
|
||||
-- If the function isn't called at HH:MM:00 then readjust the interval
|
||||
if intervalOffset > 0 then
|
||||
timeSynced = false
|
||||
|
||||
print("[BuildBox] serverChatAdverts: Warning! Timer has not been called at HH:MM:00!! Readjusting interval...")
|
||||
timer.Adjust("sca_chatPrintService", 60 - intervalOffset)
|
||||
-- Otherwise, if timeSynced is false (interval was shorter than 60 seconds) then readjust interval to 60 seconds
|
||||
else
|
||||
if !timeSynced then
|
||||
timeSynced = true
|
||||
|
||||
timer.Adjust("sca_chatPrintService", 60)
|
||||
-- else check config and print text to players if there is any
|
||||
else
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function sca_setup()
|
||||
print("[BuildBox] serverChatAdverts: Started!")
|
||||
|
||||
-- Calculate an interval that will call a function on HH:MM:00
|
||||
print("setup time: ", os.time())
|
||||
print(os.time() % 60)
|
||||
print(60 - (os.time() % 60))
|
||||
local interval = 60 - (os.time() % 60)
|
||||
print("setup interval: ", interval)
|
||||
timer.Create("sca_chatPrintService", interval, 0, sca_loop)
|
||||
|
||||
print("[BuildBox] serverChatAdverts: Initialization completed!")
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
hook.Add("Initialize", "sca_setup", sca_setup)
|
||||
Reference in New Issue
Block a user