Sync time in reallife?

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

try os.date() and os.time ?

uhm…where i put that ?

else where can i have the function like that … ?

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)

i try it now thank’s

Did this work? Been trying to do the same.

time = GetUtcTime()
works well for me

1 Like

Where can I insert this?

would like to have real time

please for an answer

I am very interested. How could this be inserted?

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

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

4 Likes

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

1 Like

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?

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:

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

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

I can not find a way to implement server side, can you help me create it with you?

gg MY BROW SUCCEFUL WORK