Help in understanding the gettime function
#1

Hi guys, I use the my server time as world time so that one day in game is one day in real life...

Problem is since the clocks advanced by one hour not long ago.. the clock in game still seems to be an hour behind, the website my server is hosted on has the clocks up to date but using the
pawn Код:
gettime
function its still an hour behind... Does anyone know exactly where the gettime function retrieves the time from so I can advance it by an hour?

I searched on the SAMP Wiki but it doesn't actually give you details on where it fetches the time from, just the parameters and why it could be used.
Reply
#2

It's not the time on the website, it's your code ! Please, do show us the code.
Reply
#3

Ah I see... Well this is the timer which is called every 60 seconds to update the time by a minute

pawn Код:
forward ClockSync();
public ClockSync()
{
    gettime(Hour, Minute);

   
   
    Minute++;
    if(Minute == 60)
    {
        Hour++;
        Minute = 0;
    }

    if(Hour >= 24) Hour = 0;
   
    for(new i; i<GetMaxPlayers(); i++) SetPlayerTime(i, Hour, Minute);

    return 1;
}
Reply
#4

It must be the servers "operating" system time, that is what the function returns. If it is an hour behind it means that it is not synced or is located in different country with different timezone other than yours.
You may ask hoster to correct it or simply add +1 to your hour variable.

Edit:
Use timerfix include / plugin to correct timer issues.
Reply
#5

Quote:
Originally Posted by Hanger
Посмотреть сообщение
It must be the servers "operating" system time, that is what the function returns. If it is an hour behind it means that it is not synced or is located in different country with different timezone other than yours.
You may ask hoster to correct it or simply add +1 to your hour variable.

Edit:
Use timerfix include / plugin to correct timer issues.
Well the servers located in the UK mate and I myself am in Scotland, UK. So therefore it should be up to date, I did consider increasing it by an hour but heres a question for you...

Won't that increase it by an hour every 60 seconds? Meaning hours advance every minute? Since its adding one to the hour every minute...

Now if I try do that on another part of the script. It will reset when it goes to gettime once again in the timer back to the original...

So how would you propose I do this?
Reply
#6

No the function gettime(...) stores the values onto your integers each time you call it, so if you call it at the first line before executing the rest of the code it will reset the values to the servers operating systems time.

If you dont specify variables it returns unix timestamp.
https://sampwiki.blast.hk/wiki/Gettime

Edit:
I dont even see why you bother to do the if statements unless you will put other code under them.
Reply
#7

That's a good point... I don't need the if statements because it's all done for you... Nice pointing out man.. Secondly... Are you suggesting to advance the after the gettime function? That actually makes more sense now...

Because if it was 10.00AM on the server but 11AM in real time...

Doing gettime(hour, minute) will retrieve 10.00AM

Then advancing by one will make it 11.00AM...

then when the timer comes along again the gettime will reset it back to the default time and the next line advances it by an hour again, right?
Reply
#8

You got it in one.
Reply
#9

Makes perfect sense, yeah I was planning on just doing that instead of having to go through the hassle of submitting tickets and waiting for a response etc when I can sort of do the same effect myself, thanks hanger, appreciated mate!
Reply
#10

Because I read the previous posts and from what I can understand, you need to display players' hours/minutes but even with a GeoIP that returns the GMT wouldn't be good as there are some of the countries that cannot return GMT. Also it returns the time of the server's computer (location in UK, so GMT 0).
Quote:

Get the current server time, which will be stored in the variables &hour, &minute and &second.

It won't set everyone's time correctly.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)