diff --git a/lua/autorun/load_serverchatadverts.lua b/lua/autorun/load_serverchatadverts.lua new file mode 100644 index 0000000..fd72264 --- /dev/null +++ b/lua/autorun/load_serverchatadverts.lua @@ -0,0 +1,3 @@ +if SERVER then + include("sca_main.lua") +end \ No newline at end of file diff --git a/lua/sca_config.lua b/lua/sca_config.lua new file mode 100644 index 0000000..73bdce3 --- /dev/null +++ b/lua/sca_config.lua @@ -0,0 +1,3 @@ +local conf = {} + +return conf \ No newline at end of file diff --git a/lua/sca_main.lua b/lua/sca_main.lua new file mode 100644 index 0000000..7eabfc8 --- /dev/null +++ b/lua/sca_main.lua @@ -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)