Scammer made a script that synced time for everyone and I’m simply taking that idea a step further to sync date also.
Most if not all of the credit here goes to Scammer. I just used his timesync script and added the month/day/year aspect into it. I took into account leap year so it is scripted as if it was a real calendar. Hope you like it.
v0.2 - Updated tickrate from testing to normal.
v0.3 - Fixed no files issue and a few oversights in the code.
local leapYear = 1
TriggerServerEvent("tads:newplayer")
RegisterNetEvent("tads:timeanddatesync")
AddEventHandler("tads:timeanddatesync", function(time,date)
Citizen.CreateThread(function()
while true do
Wait(2000)
newTime = time
newDate = date
newTime.minute = newTime.minute + 1
if newTime.minute > 59 then
newTime.minute = 0
newTime.hour = time.hour + 1
if newTime.hour > 23 then
newTime.hour = 0
newDate.day = newDate.day + 1
if newDate.day > GetDaysInCurrentMonth() then
newDate.day = 1
newDate.month = newDate.month + 1
if newDate.month > 11 then
newDate.month = 0
newDate.year = newDate.year + 1
leapYear = leapYear + 1
if leapYear > 3 then
leapYear = 0
end
end
end
SetClockDate(newDate.day, newDate.month, newDate.year)
end
end
NetworkOverrideClockTime(newTime.hour, newTime.minute, 0)
TriggerServerEvent("tads:timeanddatesync", newTime, newdate)
end
end)
end)
function GetDaysInCurrentMonth()
local month = GetClockMonth()
if month == 1 then
if leapyear == 0 then
return 29
else
return 28
end
elseif month == 3 or month == 5 or month == 8 or month == 10 then
return 30
elseif month == 0 or month == 2 or month == 4 or month == 6 or month == 7 or month == 9 or month == 11 then
return 31
end
end
lines 53, 55 and line 30
(line 30, I have no idea if making the change I did would do anything bad)
Ahh. That is actually what it was supposed to be. Slight oversights on my part. I’ll update the git with these changes tonight. Thanks for catching that and letting me know.
Having a small issue where the date isnt being set to 2017 and I was wondering how to correct it since there are no errors being displayed when logging into a server and when restarting the resource.
Hi. Do you know if there is a way to shuffle the two scripts so that the synchronized time is shown by the script that shows the date at the top right of the screen?