{"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\/nl\/fivem-real-time-sync\/","title":{"rendered":"FiveM Real-Time Sync"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Deze tutorial leidt u door het maken van een FiveM-script dat de in-game klok synchroniseert met de echte tijd. Dit zorgt ervoor dat de spelomgeving de werkelijke tijd weerspiegelt, wat de realisme voor spelers vergroot.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We behandelen zowel server-side als client-side scripting, het toevoegen van functionaliteit om de synchronisatie te starten en stoppen, en het instellen van de resource voor uw FiveM-server.<\/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\">Voorwaarden<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Voordat je begint, zorg ervoor dat je het volgende hebt:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>FiveM-server toegang<\/strong>: U heeft administratieve toegang nodig tot uw <a href=\"https:\/\/fivemx.com\/nl\/converting-fivem-scripts\/\" title=\"Converteren van FiveM Scripts \u2013 ESX, QBCore, QBOX (Framework Guide)\" data-wpil-monitor-id=\"1661\">FiveM-server om scripts toe te voegen<\/a>.<\/li>\n\n\n\n<li><strong>Basiskennis van Lua<\/strong>: Bekendheid met Lua-scripting helpt u het script te begrijpen en aan te passen.<\/li>\n\n\n\n<li><strong>Teksteditor<\/strong>: Software zoals Visual Studio Code, Sublime Text of Notepad++ voor het bewerken van scriptbestanden.<\/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\">De resource-map instellen<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Navigeer naar uw Resources-map<\/strong>:Zoek de <code data-no-translation=\"\">resources<\/code> map in uw FiveM-serverdirectory. Deze bevindt zich meestal op:bashCode kopieren<code data-no-translation=\"\">your-fivem-server-folder\/resources\/<\/code><\/li>\n\n\n\n<li><strong>Maak een nieuwe Resource-map<\/strong>:In de <code data-no-translation=\"\">resources<\/code> map, maak een nieuwe map met de naam <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>Navigeer naar de <code data-no-translation=\"\">realtime<\/code> Map<\/strong>:Deze map bevat alle benodigde scripts en configuratiebestanden voor de real-time synchronisatie.<\/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\">Het maken van het server-side script (<code data-no-translation=\"\">server.lua<\/code>)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Cre\u00ebren <code data-no-translation=\"\">server.lua<\/code><\/strong>:In de <code data-no-translation=\"\">realtime<\/code> map, maak een nieuw bestand met de naam <code data-no-translation=\"\">server.lua<\/code>.<\/li>\n\n\n\n<li><strong>Voeg de volgende code toe aan <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>Uitleg<\/strong>:\n<ul class=\"wp-block-list\">\n<li><strong>RegisterNetEvent<\/strong>: Registreert een netwerkevenement genaamd \"realtime:event\" dat de huidige echte tijd naar de client stuurt wanneer geactiveerd. <code data-no-translation=\"\">realtime:event<\/code>.<\/li>\n\n\n\n<li><strong>AddEventHandler<\/strong>: Definieert wat er gebeurt wanneer de <code data-no-translation=\"\">realtime:event<\/code> wordt geactiveerd.<\/li>\n\n\n\n<li><strong>os.date<\/strong>: Haalt de huidige systeemtijd op (uur, minuut, seconde).<\/li>\n\n\n\n<li><strong>TriggerClientEvent<\/strong>: Stuurt de tijdgegevens naar de client die de gebeurtenis heeft geactiveerd.<\/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\">Het maken van het client-side script (<code data-no-translation=\"\">client.lua<\/code>)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Cre\u00ebren <code data-no-translation=\"\">client.lua<\/code><\/strong>:In de <code data-no-translation=\"\">realtime<\/code> map, maak een nieuw bestand met de naam <code data-no-translation=\"\">client.lua<\/code>.<\/li>\n\n\n\n<li><strong>Voeg de volgende code toe aan <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>Uitleg<\/strong>:\n<ul class=\"wp-block-list\">\n<li><strong>SetMillisecondsPerGameMinute<\/strong>: Definieert hoe lang een in-game minuut duurt. Door het in te stellen op <code data-no-translation=\"\">60000<\/code> wordt 1 in-game minuut gelijk aan 1 echte minuut.<\/li>\n\n\n\n<li><strong>RegisterNetEvent &amp; AddEventHandler<\/strong>: Luistert naar de <code data-no-translation=\"\">realtime:event<\/code> van de server en werkt de in-game klok dienovereenkomstig bij.<\/li>\n\n\n\n<li><strong>NetworkOverrideClockTime<\/strong>: Overschrijft de in-game klok om overeen te komen met de echte tijd ontvangen van de server.<\/li>\n\n\n\n<li><strong>TriggerServerEvent<\/strong>: Start de synchronisatie door de servergebeurtenis te activeren.<\/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\">Een stopfunctionaliteit toevoegen<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Om het in- en uitschakelen van de real-time synchronisatie mogelijk te maken, voegen we functies toe om de synchronisatie te starten en stoppen.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Update <code data-no-translation=\"\">client.lua<\/code> met stopfunctionaliteit<\/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>Uitleg<\/strong>:\n<ul class=\"wp-block-list\">\n<li><strong>syncActive<\/strong>: Een vlag om te bepalen of synchronisatie actief is.<\/li>\n\n\n\n<li><strong>StartRealTimeSync<\/strong>: Start een lus die elke minuut tijdupdates van de server aanvraagt.<\/li>\n\n\n\n<li><strong>StopRealTimeSync<\/strong>: Stopt de synchronisatie door de vlag op false te zetten.<\/li>\n\n\n\n<li><strong>RegisterCommand<\/strong>: Voegt een commando toe (<code data-no-translation=\"\">\/toggleTimeSync<\/code>) dat spelers kunnen gebruiken om synchronisatie aan of uit te zetten.<\/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\">Het maken van het Resource Manifest (<code data-no-translation=\"\">fxmanifest.lua<\/code>)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Elke FiveM-resource vereist een manifestbestand dat de metadata en afhankelijkheden definieert.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Cre\u00ebren <code data-no-translation=\"\">fxmanifest.lua<\/code><\/strong>:In de <code data-no-translation=\"\">realtime<\/code> map, maak een nieuw bestand met de naam <code data-no-translation=\"\">fxmanifest.lua<\/code>.<\/li>\n\n\n\n<li><strong>Voeg de volgende code toe aan <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>Uitleg<\/strong>:\n<ul class=\"wp-block-list\">\n<li><strong>fx_version<\/strong>: Specificeert de versie van het FiveM-manifest. <code data-no-translation=\"\">cerulean<\/code> is de nieuwste op het moment van schrijven.<\/li>\n\n\n\n<li><strong>spel<\/strong>: Geeft aan voor welk spel de resource is (<code data-no-translation=\"\">gta5<\/code>).<\/li>\n\n\n\n<li><strong>author, description, version<\/strong>: Metadata over uw resource.<\/li>\n\n\n\n<li><strong>server_script &amp; client_script<\/strong>: Specificeert de server- en clientscripts die moeten worden geladen.<\/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\">De Resource starten op uw server<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Bewerk uw serverconfiguratie<\/strong>:Open het configuratiebestand van uw server, meestal genaamd <code data-no-translation=\"\">server.cfg<\/code>.<\/li>\n\n\n\n<li><strong>Voeg de Resource toe aan de configuratie<\/strong>:Voeg de volgende regel toe om ervoor te zorgen dat de <code data-no-translation=\"\">realtime<\/code> resource start met de server:rubyCode kopieren<code data-no-translation=\"\">ensure realtime <\/code><strong>Notitie<\/strong>: Als u gebruikmaakt van <code data-no-translation=\"\">start<\/code> in plaats van <code data-no-translation=\"\">ensure<\/code>, kunt u gebruiken: <code data-no-translation=\"\">start realtime<\/code><\/li>\n\n\n\n<li><strong>Sla uw server op en herstart deze<\/strong>:Na het opslaan van de wijzigingen in <code data-no-translation=\"\">server.cfg<\/code>, herstart u uw FiveM-server om de nieuwe resource te laden.<\/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\">Volledige resource download<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Voor het gemak vindt u hier de volledige set bestanden die u moet maken voor de <code data-no-translation=\"\">realtime<\/code> resource.<\/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\">Volledig script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Hier kunt u het script downloaden dat we zojuist hebben gemaakt:<\/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\">U heeft succesvol een FiveM-resource gemaakt die de in-game klok synchroniseert met de echte tijd. Dit script voegt een speelgebied toe doordat de game-omgeving de werkelijke tijd weerspiegelt, wat een laag realisme toevoegt voor spelers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>U kunt het script verder aanpassen door synchronisatie-intervallen aan te passen, meer commando's toe te voegen of het te integreren met andere serverfuncties.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Voel u vrij om op deze basis voort te bouwen om aan de unieke behoeften van uw server te voldoen!<\/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\/nl\/wp-json\/wp\/v2\/posts\/158437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/comments?post=158437"}],"version-history":[{"count":3,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/posts\/158437\/revisions"}],"predecessor-version":[{"id":212559,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/posts\/158437\/revisions\/212559"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/media\/193436"}],"wp:attachment":[{"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/media?parent=158437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/categories?post=158437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/tags?post=158437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}