Sync time in reallife?


#1

Anyone know how to sync the time in real life with the server for all ?


#2

try os.date() and os.time ?


#3

uhm…where i put that ?


#4

else where can i have the function like that … ?


#5

try this… in server side script… and see if you can adapt

TriggerEvent('es:addCommand', 'seeos', function(source, args, user) TriggerClientEvent('chatMessage', source, 'SYSTEM', {255, 0, 0}, "Os time == " .. os.time()) end)


#6

i try it now thank’s


#7

Did this work? Been trying to do the same.


#8

time = GetUtcTime()
works well for me


#9

Where can I insert this?

would like to have real time

please for an answer


#10

I am very interested. How could this be inserted?


#12

Should this add a kind of interface in play? Does it replace any existing string or should it be added?


#13

Hi,

If you have vSync, you should replace this in vSync/client.lua :

Citizen.CreateThread(function()

local hour = 00
local minute = 00
while true do
    Citizen.Wait(0)
    local newBaseTime = baseTime
    if GetGameTimer() - 500  > timer then
        newBaseTime = newBaseTime + 0.25
        timer = GetGameTimer()
    end
    if freezeTime then
        timeOffset = timeOffset + baseTime - newBaseTime			
    end
    baseTime = newBaseTime
    hour = math.floor(((baseTime+timeOffset)/60)%24)
    minute = math.floor((baseTime+timeOffset)%60)
    NetworkOverrideClockTime(hour, minute, 0)
	timeAndDateString = "|"
	timeAndDateString = timeAndDateString .. " " .. hour .. "h" .. minute .. " |"
	SetTextFont(0)
	SetTextProportional(1)
	SetTextScale(0.30, 0.30)
	SetTextColour(255, 255, 255, 255)
	SetTextDropshadow(0, 0, 0, 0, 255)
	SetTextEdge(1, 0, 0, 0, 255)
	SetTextDropShadow()
	SetTextOutline()
	SetTextRightJustify(true)
	SetTextWrap(0,0.95)
	SetTextEntry("STRING")
	
	AddTextComponentString(timeAndDateString)
	DrawText(0.5, 0.01)
end

end)

by

Citizen.CreateThread(function()

local hour = 00
local minute = 00
while true do

    Citizen.Wait(0)
	local years, months, days, hours, minutes, seconds = Citizen.InvokeNative(0x50C7A99057A69748, Citizen.PointerValueInt(), Citizen.PointerValueInt(), Citizen.PointerValueInt(), Citizen.PointerValueInt(), Citizen.PointerValueInt(), Citizen.PointerValueInt())
    local newBaseTime = baseTime
    if GetGameTimer() - 500  > timer then
        newBaseTime = newBaseTime + 0.25
        timer = GetGameTimer()
    end
    if freezeTime then
        timeOffset = timeOffset + baseTime - newBaseTime			
    end
    baseTime = newBaseTime
    hour = hours
    minute = minutes
	day=days
	month=months
	year=years
	second=seconds
    NetworkOverrideClockTime(hour, minute, 0)
	timeAndDateString = "|"
	timeAndDateString ="~w~" .. day .. "/" .. month .. "/" .. year .. " ~s~" .. timeAndDateString .. " ~y~" .. hour .. "h" .. minute .. " ~s~|"
	SetTextFont(0)
	SetTextProportional(1)
	SetTextScale(0.30, 0.30)
	SetTextColour(255, 255, 255, 255)
	SetTextDropshadow(0, 0, 0, 0, 255)
	SetTextEdge(1, 0, 0, 0, 255)
	SetTextDropShadow()
	SetTextOutline()
	SetTextRightJustify(true)
	SetTextWrap(0,0.95)
	SetTextEntry("STRING")
	
	AddTextComponentString(timeAndDateString)
	DrawText(0.5, 0.01)
end

end)

BR


vSync (v1.4.0) | Simple weather and time sync
#14

I’ll try it right away and let you know. Thank you very much.


#15

It works perfectly. Thanks so much! Do you think it is possible to implement or replace the date and time display with this graphic style?


#16

I do not know how, but I managed to mix the two scripts in order to display the name of the day and the month, but the only problem is that it only synchronizes the time correctly and not everything else. The count of the year, for example, starts in 2013 :confused:


#17

Is it possible to sync time to the server’s current time instead of each client being synced to their computer’s time?


#18

Use the os.time server side and send it to each player when they join would be how I’d go about.