Hi guys,
I have created a cron task inside server.lua that sends out a chatMessage at a specified time which works… However, it seems to be sending the chatMessage at the host time and not the server time. For instance, my server is based in Germany and my local machine is UK. Germany is 1 hour ahead so if I set the cron task to to send the message at 20:00 I would expect to receive that message at 19:00 UK time but I dont, I get it at 20:00 UK time.
Can anyone help with this or suggest a way to get it to send at server time and not client time?
Thanks in advance for your help, much appreciated.
CODE:
local Jobs = {}
local LastTime = nil
local text1 = "SERVER RESTART IN 15 MINS"
function RunAt(h, m, cb)
table.insert(Jobs, {
h = h,
m = m,
cb = cb
})
end
function GetTime()
local timestamp = os.time()
local d = os.date('*t', timestamp).wday
local h = tonumber(os.date('%H', timestamp))
local m = tonumber(os.date('%M', timestamp))
return {d = d, h = h, m = m}
end
function OnTime(d, h, m)
for i=1, #Jobs, 1 do
if Jobs[i].h == h and Jobs[i].m == m then
Jobs[i].cb(d, h, m)
end
end
end
function Tick()
local time = GetTime()
if time.h ~= LastTime.h or time.m ~= LastTime.m then
OnTime(time.d, time.h, time.m)
LastTime = time
end
SetTimeout(60000, Tick)
end
LastTime = GetTime()
Tick()
AddEventHandler('cron:runAt', function(h, m, cb)
RunAt(h, m, cb)
end)
-- Execute task 20:00, every day
function CronTask(d, h, m)
print('Task done')
TriggerClientEvent('chatMessage', -1, "ALERT", {255, 0, 0}, text1)
end
TriggerEvent('cron:runAt', 20, 00, CronTask)