{"id":158437,"date":"2024-09-26T14:01:24","date_gmt":"2024-09-26T12:01:24","guid":{"rendered":"https:\/\/hifivem.com\/?p=158437"},"modified":"2026-07-24T12:46:18","modified_gmt":"2026-07-24T10:46:18","slug":"sincronizacao-em-tempo-real-fivem","status":"publish","type":"post","link":"https:\/\/rpcrate.com\/pt\/fivem-real-time-sync\/","title":{"rendered":"Como Sincronizar o Rel\u00f3gio do Jogo FiveM com UTC"},"content":{"rendered":"<p>This small development resource makes every connected client display the FXServer host\u2019s 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.<\/p>\n<p>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\u2019s local time zone.<\/p>\n<p>The configuration and code examples here target FiveM for GTA V Legacy. Enhanced has different runtime and compatibility rules; check <a href=\"https:\/\/docs.fivem.net\/docs\/developers\/legacy-vs-enhanced\/\">Cfx.re\u2019s Legacy-to-Enhanced changes<\/a> before applying them to an Enhanced server.<\/p>\n<h2 id=\"prepare-the-test\">Prepare the test<\/h2>\n<p>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.<\/p>\n<h2 id=\"1-declare-the-resource\">1. Declare the resource<\/h2>\n<p>Save this as fxmanifest.lua:<\/p>\n<pre data-no-translation=\"\" translate=\"no\"><code data-no-translation=\"\" translate=\"no\">fx_version 'cerulean'\ngame 'gta5'\nserver_script 'server.lua'\nclient_script 'client.lua'<\/code><\/pre>\n<h2 id=\"2-publish-utc-from-the-server\">2. Publish UTC from the server<\/h2>\n<p>Save this as server.lua. The leading exclamation mark in os.date selects UTC rather than the host\u2019s local time zone:<\/p>\n<pre data-no-translation=\"\" translate=\"no\"><code data-no-translation=\"\" translate=\"no\">CreateThread(function()\n    while true do\n        local now = os.date('!*t')\n        GlobalState.tutorialUtcClock = {\n            hour = now.hour, minute = now.min, second = now.sec\n        }\n        Wait(1000)\n    end\nend)\n\nAddEventHandler('onResourceStop', function(name)\n    if name == GetCurrentResourceName() then\n        GlobalState.tutorialUtcClock = nil\n    end\nend)<\/code><\/pre>\n<h2 id=\"3-display-the-shared-clock\">3. Display the shared clock<\/h2>\n<p>Save this as client.lua:<\/p>\n<pre data-no-translation=\"\" translate=\"no\"><code data-no-translation=\"\" translate=\"no\">CreateThread(function()\n    while true do\n        local clock = GlobalState.tutorialUtcClock\n        if clock then\n            NetworkOverrideClockTime(clock.hour, clock.minute, clock.second)\n        end\n        Wait(1000)\n    end\nend)\n\nAddEventHandler('onResourceStop', function(name)\n    if name == GetCurrentResourceName() then\n        NetworkClearClockTimeOverride()\n    end\nend)<\/code><\/pre>\n<h2 id=\"start-check-and-stop\">Start, check and stop<\/h2>\n<ol>\n<li>Add ensure utc_clock to server.cfg after disabling the competing clock controller on the test server.<\/li>\n<li>In the server console, run refresh and ensure utc_clock. Join with two clients and compare their displayed game time with current UTC.<\/li>\n<li>Reconnect one client, restart the resource and repeat the comparison. Inspect both F8 and server logs.<\/li>\n<li>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.<\/li>\n<\/ol>\n<h2 id=\"know-the-limits\">Know the limits<\/h2>\n<p>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.<\/p>\n<p>See <a href=\"https:\/\/docs.fivem.net\/docs\/scripting-manual\/networking\/state-bags\/\">Cfx.re state bags<\/a> and the <a href=\"https:\/\/github.com\/citizenfx\/natives\/blob\/master\/NETWORK\/NetworkOverrideClockTime.md\">clock override native<\/a> before integrating the pattern into a larger resource.<\/p>\n<h2 id=\"reference-documentation\">Reference documentation<\/h2>\n<p><a href=\"https:\/\/www.lua.org\/manual\/5.4\/manual.html#pdf-os.date\">Source: lua.org<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Este pequeno recurso de desenvolvimento faz com que cada cliente conectado exiba a hora UTC do host do FXServer. Use-o apenas quando for o \u00fanico recurso que controla o rel\u00f3gio do jogo. Se o seu framework j\u00e1 gerencia tempo e clima, configure ou estenda esse recurso em vez de executar dois sistemas de rel\u00f3gio.<\/p>","protected":false},"author":1,"featured_media":193436,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2297,2298,2340],"tags":[3001,2928,3000],"class_list":["post-158437","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-free","category-scripts","category-lua-scripting","tag-fivem-script","tag-free","tag-free-script"],"_links":{"self":[{"href":"https:\/\/rpcrate.com\/pt\/wp-json\/wp\/v2\/posts\/158437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rpcrate.com\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rpcrate.com\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rpcrate.com\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rpcrate.com\/pt\/wp-json\/wp\/v2\/comments?post=158437"}],"version-history":[{"count":3,"href":"https:\/\/rpcrate.com\/pt\/wp-json\/wp\/v2\/posts\/158437\/revisions"}],"predecessor-version":[{"id":212559,"href":"https:\/\/rpcrate.com\/pt\/wp-json\/wp\/v2\/posts\/158437\/revisions\/212559"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rpcrate.com\/pt\/wp-json\/wp\/v2\/media\/193436"}],"wp:attachment":[{"href":"https:\/\/rpcrate.com\/pt\/wp-json\/wp\/v2\/media?parent=158437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rpcrate.com\/pt\/wp-json\/wp\/v2\/categories?post=158437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rpcrate.com\/pt\/wp-json\/wp\/v2\/tags?post=158437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}