Use Coupon WELCOME to save 20%

$ USD
  • $ USD
  • € EUR
  • £ GBP
  • $ AUD
  • R$ BRL
  • CHF CHF
  • ¥ JPY
FiveM Real-Time Sync – Free FiveM Mods

How to Sync the FiveM Game Clock to UTC

This small development resource makes every connected client display the FXServer host’s UTC time. Use it only when it is the sole owner of the game clock. If your framework already manages time and weather, configure or extend that resource instead of running two clock systems.

This example requires state-awareness support for GlobalState. Stop other time/weather synchronization resources on the test instance so one controller owns the clock. It displays UTC, not the server host’s local time zone.

The configuration and code examples here target FiveM for GTA V Legacy. Enhanced has different runtime and compatibility rules; check Cfx.re’s Legacy-to-Enhanced changes before applying them to an Enhanced server.

Prepare the test

Check that the host clock is accurate. Back up the existing time-resource configuration and use an isolated server. Create resources/[local]/utc_clock with the three files below. The server publishes time; clients cannot set GlobalState values on the server.

1. Declare the resource

Save this as fxmanifest.lua:

fx_version 'cerulean'
game 'gta5'
server_script 'server.lua'
client_script 'client.lua'

2. Publish UTC from the server

Save this as server.lua. The leading exclamation mark in os.date selects UTC rather than the host’s local time zone:

CreateThread(function()
    while true do
        local now = os.date('!*t')
        GlobalState.tutorialUtcClock = {
            hour = now.hour, minute = now.min, second = now.sec
        }
        Wait(1000)
    end
end)

AddEventHandler('onResourceStop', function(name)
    if name == GetCurrentResourceName() then
        GlobalState.tutorialUtcClock = nil
    end
end)

3. Display the shared clock

Save this as client.lua:

CreateThread(function()
    while true do
        local clock = GlobalState.tutorialUtcClock
        if clock then
            NetworkOverrideClockTime(clock.hour, clock.minute, clock.second)
        end
        Wait(1000)
    end
end)

AddEventHandler('onResourceStop', function(name)
    if name == GetCurrentResourceName() then
        NetworkClearClockTimeOverride()
    end
end)

Start, check and stop

  1. Add ensure utc_clock to server.cfg after disabling the competing clock controller on the test server.
  2. In the server console, run refresh and ensure utc_clock. Join with two clients and compare their displayed game time with current UTC.
  3. Reconnect one client, restart the resource and repeat the comparison. Inspect both F8 and server logs.
  4. Run stop utc_clock in the server console to release this override. To restore your previous time system, remove the new ensure line and restart the original time resource or server.

Know the limits

This example follows a real 24-hour UTC day; it does not accelerate daylight or select a regional daylight-saving time zone. Network and scheduling delays mean it is not a precise wall-clock display. It does not synchronize weather.

See Cfx.re state bags and the clock override native before integrating the pattern into a larger resource.

Reference documentation

Source: lua.org

Leave a Reply