{"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":"fivem-real-time-sync","status":"publish","type":"post","link":"https:\/\/fivemx.com\/pl\/fivem-real-time-sync\/","title":{"rendered":"FiveM Synchronizacja w czasie rzeczywistym"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Ten poradnik przeprowadzi Ci\u0119 przez tworzenie skryptu FiveM, kt\u00f3ry synchronizuje zegar w grze z rzeczywistym czasem. Dzi\u0119ki temu \u015brodowisko gry b\u0119dzie odzwierciedla\u0107 aktualny czas, zwi\u0119kszaj\u0105c realizm dla graczy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Om\u00f3wimy zar\u00f3wno skrypty po stronie serwera, jak i klienta, dodaj\u0105c funkcjonalno\u015b\u0107 uruchamiania i zatrzymywania synchronizacji oraz konfiguracj\u0119 zasobu dla Twojego serwera FiveM.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\">Wymagania wst\u0119pne<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Przed rozpocz\u0119ciem upewnij si\u0119, \u017ce posiadasz nast\u0119puj\u0105ce rzeczy:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Dost\u0119p do serwera FiveM<\/strong>: Wymagany jest dost\u0119p administracyjny do Twojego <a href=\"https:\/\/fivemx.com\/pl\/converting-fivem-scripts\/\" title=\"Konwersja FiveM Scripts \u2013 ESX, QBCore, QBOX (Przewodnik po frameworku)\" data-wpil-monitor-id=\"1661\">serwera FiveM, aby dodawa\u0107 skrypty<\/a>.<\/li>\n\n\n\n<li><strong>Podstawowa znajomo\u015b\u0107 Lua<\/strong>: Znajomo\u015b\u0107 skrypt\u00f3w Lua pomo\u017ce Ci zrozumie\u0107 i dostosowa\u0107 skrypt.<\/li>\n\n\n\n<li><strong>Edytor tekstu<\/strong>: Oprogramowanie takie jak Visual Studio Code, Sublime Text lub Notepad++ do edycji plik\u00f3w skrypt\u00f3w.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"setting-up-the-resource-folder\">Konfigurowanie folderu zasob\u00f3w<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Przejd\u017a do katalogu Resources<\/strong>:Znajd\u017a <code data-no-translation=\"\">resources<\/code> folder w katalogu Twojego serwera FiveM. Zazwyczaj znajduje si\u0119 on pod adresem:bashCode kopieren<code data-no-translation=\"\">your-fivem-server-folder\/resources\/<\/code><\/li>\n\n\n\n<li><strong>Utw\u00f3rz nowy folder zasobu<\/strong>:Wewn\u0105trz folderu <code data-no-translation=\"\">resources<\/code> , utw\u00f3rz nowy folder o nazwie <code data-no-translation=\"\">realtime<\/code>.bashCode kopieren<code data-no-translation=\"\">your-fivem-server-folder\/resources\/realtime\/<\/code><\/li>\n\n\n\n<li><strong>Przejd\u017a do <code data-no-translation=\"\">realtime<\/code> Folder<\/strong>:Ten folder b\u0119dzie zawiera\u0107 wszystkie niezb\u0119dne skrypty i pliki konfiguracyjne do synchronizacji czasu rzeczywistego.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-the-server-side-script-server-lua\">Tworzenie skryptu po stronie serwera (<code data-no-translation=\"\">server.lua<\/code>)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Tworzy\u0107 <code data-no-translation=\"\">server.lua<\/code><\/strong>:Wewn\u0105trz folderu <code data-no-translation=\"\">realtime<\/code> folder, utw\u00f3rz nowy plik o nazwie <code data-no-translation=\"\">server.lua<\/code>.<\/li>\n\n\n\n<li><strong>Dodaj nast\u0119puj\u0105cy kod do <code data-no-translation=\"\">server.lua<\/code><\/strong>:luaCode kopieren<code data-no-translation=\"\">RegisterNetEvent(\"realtime:event\") AddEventHandler(\"realtime:event\", function() local hour = tonumber(os.date(\"%H\")) local minute = tonumber(os.date(\"%M\")) local second = tonumber(os.date(\"%S\")) TriggerClientEvent(\"realtime:event\", source, hour, minute, second) end) <\/code><strong>Wyja\u015bnienie<\/strong>:\n<ul class=\"wp-block-list\">\n<li><strong>RegisterNetEvent<\/strong>: Rejestruje zdarzenie sieciowe o nazwie <code data-no-translation=\"\">realtime:event<\/code>.<\/li>\n\n\n\n<li><strong>AddEventHandler<\/strong>: Okre\u015bla, co si\u0119 dzieje, gdy <code data-no-translation=\"\">realtime:event<\/code> jest wyzwolone.<\/li>\n\n\n\n<li><strong>os.date<\/strong>: Pobiera bie\u017c\u0105cy czas systemowy (godzina, minuta, sekunda).<\/li>\n\n\n\n<li><strong>TriggerClientEvent<\/strong>: Wysy\u0142a dane czasu do klienta, kt\u00f3ry wywo\u0142a\u0142 zdarzenie.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-the-client-side-script-client-lua\">Tworzenie skryptu po stronie klienta (<code data-no-translation=\"\">client.lua<\/code>)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Tworzy\u0107 <code data-no-translation=\"\">client.lua<\/code><\/strong>:Wewn\u0105trz folderu <code data-no-translation=\"\">realtime<\/code> folder, utw\u00f3rz nowy plik o nazwie <code data-no-translation=\"\">client.lua<\/code>.<\/li>\n\n\n\n<li><strong>Dodaj nast\u0119puj\u0105cy kod do <code data-no-translation=\"\">client.lua<\/code><\/strong>:luaCode kopieren<code data-no-translation=\"\">-- Set the duration of one in-game minute in milliseconds SetMillisecondsPerGameMinute(60000) -- 60,000 ms = 1 real-world minute RegisterNetEvent(\"realtime:event\") AddEventHandler(\"realtime:event\", function(hour, minute, second) NetworkOverrideClockTime(hour, minute, second) end) -- Trigger the server event to initiate synchronization TriggerServerEvent(\"realtime:event\") <\/code><strong>Wyja\u015bnienie<\/strong>:\n<ul class=\"wp-block-list\">\n<li><strong>SetMillisecondsPerGameMinute<\/strong>: Okre\u015bla, jak d\u0142ugo trwa jedna minuta w grze. Ustawienie go na <code data-no-translation=\"\">60000<\/code> sprawia, \u017ce 1 minuta w grze r\u00f3wna si\u0119 1 minucie czasu rzeczywistego.<\/li>\n\n\n\n<li><strong>RegisterNetEvent &amp; AddEventHandler<\/strong>: Nas\u0142uchuje zdarzenia <code data-no-translation=\"\">realtime:event<\/code> z serwera i odpowiednio aktualizuje zegar w grze.<\/li>\n\n\n\n<li><strong>NetworkOverrideClockTime<\/strong>: Zast\u0119puje zegar w grze, aby dopasowa\u0107 go do czasu rzeczywistego otrzymanego z serwera.<\/li>\n\n\n\n<li><strong>TriggerServerEvent<\/strong>: Inicjuje synchronizacj\u0119 poprzez wywo\u0142anie zdarzenia serwera.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"adding-a-stop-functionality\">Dodawanie funkcjonalno\u015bci zatrzymania<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Aby umo\u017cliwi\u0107 w\u0142\u0105czanie i wy\u0142\u0105czanie synchronizacji czasu rzeczywistego, dodamy funkcje uruchamiania i zatrzymywania synchronizacji.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Aktualizacja <code data-no-translation=\"\">client.lua<\/code> z funkcjonalno\u015bci\u0105 zatrzymania<\/strong>:luaCode kopieren<code data-no-translation=\"\">local syncActive = true local syncThread = nil -- Function to start synchronization function StartRealTimeSync() if not syncActive then syncActive = true syncThread = CreateThread(function() while syncActive do TriggerServerEvent(\"realtime:event\") Wait(60000) -- Wait for 1 minute before next sync end end) end end -- Function to stop synchronization function StopRealTimeSync() if syncActive then syncActive = false if syncThread then -- In Lua, there's no direct way to kill a thread. -- Using a flag to exit the loop effectively stops the thread. syncThread = nil end end end RegisterNetEvent(\"realtime:event\") AddEventHandler(\"realtime:event\", function(hour, minute, second) if syncActive then NetworkOverrideClockTime(hour, minute, second) end end) -- Start synchronization on resource start StartRealTimeSync() -- Example: Command to toggle synchronization RegisterCommand(\"toggleTimeSync\", function() if syncActive then StopRealTimeSync() print(\"Real-time synchronization stopped.\") else StartRealTimeSync() print(\"Real-time synchronization started.\") end end, false) <\/code><strong>Wyja\u015bnienie<\/strong>:\n<ul class=\"wp-block-list\">\n<li><strong>syncActive<\/strong>: Flaga okre\u015blaj\u0105ca, czy synchronizacja jest aktywna.<\/li>\n\n\n\n<li><strong>StartRealTimeSync<\/strong>: Inicjuje p\u0119tl\u0119, kt\u00f3ra co minut\u0119 \u017c\u0105da aktualizacji czasu z serwera.<\/li>\n\n\n\n<li><strong>StopRealTimeSync<\/strong>: Zatrzymuje synchronizacj\u0119 poprzez ustawienie flagi na false.<\/li>\n\n\n\n<li><strong>RegisterCommand<\/strong>: Dodaje komend\u0119 (<code data-no-translation=\"\">\/toggleTimeSync<\/code>) kt\u00f3r\u0105 gracze mog\u0105 u\u017cy\u0107 do w\u0142\u0105czania lub wy\u0142\u0105czania synchronizacji.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-the-resource-manifest-fxmanifest-lua\">Tworzenie manifestu zasobu (<code data-no-translation=\"\">fxmanifest.lua<\/code>)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ka\u017cdy zas\u00f3b FiveM wymaga pliku manifestu, kt\u00f3ry definiuje jego metadane i zale\u017cno\u015bci.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Tworzy\u0107 <code data-no-translation=\"\">fxmanifest.lua<\/code><\/strong>:Wewn\u0105trz folderu <code data-no-translation=\"\">realtime<\/code> folder, utw\u00f3rz nowy plik o nazwie <code data-no-translation=\"\">fxmanifest.lua<\/code>.<\/li>\n\n\n\n<li><strong>Dodaj nast\u0119puj\u0105cy kod do <code data-no-translation=\"\">fxmanifest.lua<\/code><\/strong>: <code data-no-translation=\"\">fx_version 'cerulean' game 'gta5' author 'YourName' description 'Real-Time Synchronization Script for FiveM' version '1.0.0' server_script 'server.lua' client_script 'client.lua'<\/code><\/li>\n\n\n\n<li><strong>Wyja\u015bnienie<\/strong>:\n<ul class=\"wp-block-list\">\n<li><strong>fx_version<\/strong>: Okre\u015bla wersj\u0119 manifestu FiveM. <code data-no-translation=\"\">cerulean<\/code> jest najnowsza w momencie pisania.<\/li>\n\n\n\n<li><strong>gra<\/strong>: Wskazuje gr\u0119, dla kt\u00f3rej jest zas\u00f3b (<code data-no-translation=\"\">gta5<\/code>).<\/li>\n\n\n\n<li><strong>autor, opis, wersja<\/strong>: Metadane dotycz\u0105ce twojego zasobu.<\/li>\n\n\n\n<li><strong>server_script &amp; client_script<\/strong>: Okre\u015bla skrypty serwera i klienta do za\u0142adowania.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"starting-the-resource-on-your-server\">Uruchamianie zasobu na twoim serwerze<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Edytuj konfiguracj\u0119 serwera<\/strong>:Otw\u00f3rz plik konfiguracyjny serwera, zazwyczaj nazwany <code data-no-translation=\"\">server.cfg<\/code>.<\/li>\n\n\n\n<li><strong>Dodaj zas\u00f3b do konfiguracji<\/strong>:Dodaj nast\u0119puj\u0105c\u0105 lini\u0119, aby upewni\u0107 si\u0119, \u017ce <code data-no-translation=\"\">realtime<\/code> zas\u00f3b zaczyna si\u0119 od serwera:rubyCode kopieren<code data-no-translation=\"\">ensure realtime <\/code><strong>Uwaga<\/strong>: Je\u015bli u\u017cywasz <code data-no-translation=\"\">start<\/code> zamiast <code data-no-translation=\"\">ensure<\/code>, mo\u017cesz u\u017cy\u0107: <code data-no-translation=\"\">start realtime<\/code><\/li>\n\n\n\n<li><strong>Zapisz i uruchom ponownie sw\u00f3j serwer<\/strong>:Po zapisaniu zmian w <code data-no-translation=\"\">server.cfg<\/code>, uruchom ponownie sw\u00f3j serwer FiveM, aby za\u0142adowa\u0107 nowy zas\u00f3b.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"full-resource-download\">Pe\u0142ne pobranie zasobu<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Dla wygody, oto kompletny zestaw plik\u00f3w, kt\u00f3re musisz utworzy\u0107 dla <code data-no-translation=\"\">realtime<\/code> zasobu.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-server-lua\">1. <code data-no-translation=\"\">server.lua<\/code><\/h3>\n\n\n\n<pre data-no-translation=\"\" class=\"EnlighterJSRAW\" data-enlighter-language=\"lua\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">RegisterNetEvent(\"realtime:event\")\nAddEventHandler(\"realtime:event\", function()\n local hour = tonumber(os.date(\"%H\"))\n local minute = tonumber(os.date(\"%M\"))\n local second = tonumber(os.date(\"%S\"))\n TriggerClientEvent(\"realtime:event\", source, hour, minute, second)\nend)\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-client-lua\">2. <code data-no-translation=\"\">client.lua<\/code><\/h3>\n\n\n\n<pre data-no-translation=\"\" class=\"EnlighterJSRAW\" data-enlighter-language=\"lua\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">local syncActive = true\nlocal syncThread = nil\n\n-- Function to start synchronization\nfunction StartRealTimeSync()\n if not syncActive then\n syncActive = true\n syncThread = CreateThread(function()\n while syncActive do\n TriggerServerEvent(\"realtime:event\")\n Wait(60000) -- Wait for 1 minute before next sync\n end\n end)\n end\nend\n\n-- Function to stop synchronization\nfunction StopRealTimeSync()\n if syncActive then\n syncActive = false\n if syncThread then\n -- In Lua, threads are cooperative; setting syncActive to false will stop the loop\n syncThread = nil\n end\n end\nend\n\nRegisterNetEvent(\"realtime:event\")\nAddEventHandler(\"realtime:event\", function(hour, minute, second)\n if syncActive then\n NetworkOverrideClockTime(hour, minute, second)\n end\nend)\n\n-- Start synchronization on resource start\nStartRealTimeSync()\n\n-- Example: Command to toggle synchronization\nRegisterCommand(\"toggleTimeSync\", function()\n if syncActive then\n StopRealTimeSync()\n print(\"Real-time synchronization stopped.\")\n else\n StartRealTimeSync()\n print(\"Real-time synchronization started.\")\n end\nend, false)\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-fxmanifest-lua\">3. <code data-no-translation=\"\">fxmanifest.lua<\/code><\/h3>\n\n\n\n<pre data-no-translation=\"\" class=\"EnlighterJSRAW\" data-enlighter-language=\"lua\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">fx_version 'cerulean'\ngame 'gta5'\n\nauthor 'YourName'\ndescription 'Real-Time Synchronization Script for FiveM'\nversion '1.0.0'\n\nserver_script 'server.lua'\nclient_script 'client.lua'\n<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Pe\u0142ny skrypt<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Tutaj mo\u017cesz pobra\u0107 skrypt, kt\u00f3ry w\u0142a\u015bnie utworzyli\u015bmy:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/codeload.github.com\/HiFiveM\/fivem-realtime\/zip\/refs\/heads\/main\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">https:\/\/github.com\/HiFiveM\/fivem-realtime\/archive\/refs\/heads\/main.zip<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/HiFiveM\/fivem-realtime\/tree\/main\/fivem-realtime\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/github.com\/HiFiveM\/fivem-realtime\/tree\/main\/fivem-realtime\" rel=\"noreferrer noopener nofollow\">GitHub<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pomy\u015blnie utworzy\u0142e\u015b zas\u00f3b FiveM, kt\u00f3ry synchronizuje zegar w grze z czasem rzeczywistym. Ten skrypt dodaje obszar rozgrywki, zapewniaj\u0105c, \u017ce \u015brodowisko gry odzwierciedla rzeczywisty czas, dodaj\u0105c warstw\u0119 realizmu dla graczy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Mo\u017cesz dalej dostosowywa\u0107 skrypt, zmieniaj\u0105c interwa\u0142y synchronizacji, dodaj\u0105c wi\u0119cej komend lub integruj\u0105c go z innymi funkcjami serwera.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u015amia\u0142o rozwijaj t\u0119 podstaw\u0119, aby dostosowa\u0107 j\u0105 do unikalnych potrzeb swojego serwera!<\/p>","protected":false},"excerpt":{"rendered":"<p>FiveM Real Time Sync keeps the in-game clock aligned with real-world time and includes start and stop controls.<\/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:\/\/fivemx.com\/pl\/wp-json\/wp\/v2\/posts\/158437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fivemx.com\/pl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fivemx.com\/pl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fivemx.com\/pl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fivemx.com\/pl\/wp-json\/wp\/v2\/comments?post=158437"}],"version-history":[{"count":3,"href":"https:\/\/fivemx.com\/pl\/wp-json\/wp\/v2\/posts\/158437\/revisions"}],"predecessor-version":[{"id":212559,"href":"https:\/\/fivemx.com\/pl\/wp-json\/wp\/v2\/posts\/158437\/revisions\/212559"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemx.com\/pl\/wp-json\/wp\/v2\/media\/193436"}],"wp:attachment":[{"href":"https:\/\/fivemx.com\/pl\/wp-json\/wp\/v2\/media?parent=158437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemx.com\/pl\/wp-json\/wp\/v2\/categories?post=158437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemx.com\/pl\/wp-json\/wp\/v2\/tags?post=158437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}