Egor_Varaksa Posted December 27, 2021 Share Posted December 27, 2021 How can I get real time on the client side from the server side? Link to comment
The_GTA Posted December 27, 2021 Share Posted December 27, 2021 Hello Egor_Varaksa, are you aware that the client and the server can be located in different time zones? That is why the getRealTime function can return different time values for either side. If you want to know the server's local time then you should call the getRealTime function on the server-side and then use remote MTA events using the triggerServerEvent and triggerClientEvent functions to first request the time and then send the requested values to the specific clients that want it. Link to comment
Egor_Varaksa Posted December 27, 2021 Author Share Posted December 27, 2021 (edited) If I want the time to always be updated down to the second, I need to call the triggerServerevent event every second? Will there be a load on the server? Edited December 27, 2021 by Egor_Varaksa Link to comment
The_GTA Posted December 27, 2021 Share Posted December 27, 2021 1 minute ago, Egor_Varaksa said: I need to call the triggerServerevent event every second? This is terrible practice so don't to it this often. You can count the time on the client and re-synchronize every hour or so, or by the click on a UI button triggered by the user. Link to comment
DRW Posted December 28, 2021 Share Posted December 28, 2021 What I would recommend is: Add a the "onClientResourceStart" event and call the server with triggerServerEvent (let's call it "requestServerTime") so to ask for the server's time. Implement the event on the server, then return the server's real time with triggerClientEvent (let's call this one "returnServerTime"). Implement "returnServerTime" in client, then do a comparison with the server time you just received and the client time. Make sure you compare the hour AND day, and do the difference (try to round this to the next half hour as probably you'll be off by a second or so). The difference should return the differences in time zone. Save the difference in a variable, create a function to retrieve the realTime of the client + difference, and now you have a good way to get the time of the server with just a couple initial setup requests. 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now