[Release]Time And Date Sync v0.3

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.

3 Likes

screenshot ? :smiley: - Awesome release

the link got no files

No files on github! Please update


Looks like its suppose to be this one.

there not the same as the time sync

Ha wow I’m dumb. Well it’s fixed now. The files are there. Sorry for the delay everyone!

1 Like

This wasnt working for me but I managed to fix it

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.

Edit: github is now updated.

2 Likes

so does this sync the weather and time for everyday and does it work?

Hoi hoi there

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?

Citizen.CreateThread(function()
	while true do
		Wait(1)
		timeAndDateString = "|"
		
		if displayTime == true then
			CalculateTimeToDisplay()
			timeAndDateString = timeAndDateString .. "| 09" .. hour .. ":" .. minute .. "00 |"
		end
		if displayDayOfWeek == true then
			CalculateDayOfWeekToDisplay()
			timeAndDateString = timeAndDateString .. " " .. dayOfWeek .. " |"
		end
		if displayDate == true then
			CalculateDateToDisplay()
			timeAndDateString = timeAndDateString .. " " .. month .. " " .. dayOfMonth .. ", " .. year .. " |"
		end

how do I add time and date iv tried so many diffent ways