Jump to content

getRealTime client from the server


Egor_Varaksa

Recommended Posts

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
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

What I would recommend is:

  1. Add a the "onClientResourceStart" event and call the server with triggerServerEvent (let's call it "requestServerTime") so to ask for the server's time.
  2. Implement the event on the server, then return the server's real time with triggerClientEvent (let's call this one "returnServerTime").
  3. 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).
  4. 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.
  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...