!!Time Machine!!
#1

Code:
TogglePlayerClock(playerid,ENABLE);	
new count = tickcount();
count = count%1440000;
SetPlayerTime(playerid,count/60,count%60);
The problem is the clock is running too fast in game.It runs damn fast.Along with the clock display all the weather,etc also change with the same speed.I broke my head into the code for about 2 hours,searched the forums but never found any such problems.

The clock is running too fast.1 hour in SA goes within 5-10 seconds instead of 1 minute!!!
Reply
#2

bump
Reply
#3

tickcount and GetTickCount returns values in ms, just use gettime, it is in seconds

That would be now 1 second = 1 minute in game
pawn Code:
TogglePlayerClock(playerid, ENABLE);   
new count = gettime() % 3600;
SetPlayerTime(playerid, count / 60, count % 60);
But that needs to be in a timer, otherwise it will raise like in single player
Reply
#4

Quote:
Originally Posted by Nero_3D
View Post
tickcount and GetTickCount returns values in ms, just use gettime, it is in seconds

That would be now 1 second = 1 minute in game
pawn Code:
TogglePlayerClock(playerid, ENABLE);   
new count = gettime() % 3600;
SetPlayerTime(playerid, count / 60, count % 60);
But that needs to be in a timer, otherwise it will raise like in single player
But my code works fine, the clock shows a common time for everyone.The problem is the clock runs like a cheetah.
Reply
#5

Do you update the time in a timer or is that code you posted just called once in OnPlayerConnect ?

If you call it only once it should run like in single player
Otherwise its your code like I told your before because tickcount is in milliseconds

Also why 1440000 ?
Reply
#6

Quote:
Originally Posted by Nero_3D
View Post
Do you update the time in a timer or is that code you posted just called once in OnPlayerConnect ?

If you call it only once it should run like in single player
Otherwise its your code like I told your before because tickcount is in milliseconds

Also why 1440000 ?
Let me explain my code
Code:
TogglePlayerClock(playerid,ENABLE);
:P Its understood :P

Code:
new count = tickcount();
I will get the tick in ms(tick which was counted since server start up)

Code:
count = count%1440000;
Since I get it in ms I need to convert it into seconds for the game where I must remove complete days.
One complete day in San Andreas In-game will take 24 minutes that in ms is =
24 * 60 * 1000 = 1440000ms.

So now my count has the current second that being shown in everyone's clock.

Code:
SetPlayerTime(playerid,count/60,count%60);
When I divide the count by 60 I would get the hour because every SA hour is a real world minute(so divide by 60).
The remainder left after dividing will give me the SA minutes....

All are my assumptions......hope the SAMP clock works this way.... and my code wasn't crap... :P

And what is that timer thingy??I tought the time gets updated by itself.Only I had to set it with the correct time.
Reply
#7

Yeah you are right, the time really moves by itself in seconds, it's been a long long time since I last played

The only problem I noticed is that you didn't removed the milliseconds from the tickcount
pawn Code:
new count = tickcount(); // lets say this is 5321 - 5 seconds 321 milliseconds
count = count%1440000; // thats far less than that so it stays
SetPlayerTime(playerid,count/60,count%60); // result = 88 and 41
//
new count = (tickcount() / 1000) % 1440; // 5321 / 1000 => 5, or just (gettime() % 1440)
SetPlayerTime(playerid,count/60,count%60); // 0 and 5
But I don't know why your clocks moves so fast
Since this isn't natural it is caused by a script (gamemode, filterscript, include ?)

Also this code needs to be in OnPlayerSpawn because if you die the time moves 8 hours in the future

Edit: Just noticed another thing, if you pause the game the clock stops, I think its better if you update it manually in a timer each second
Reply
#8

It does move by itself, but u can allways keep forcing it the same value
Reply
#9

Quote:
Originally Posted by Nero_3D
View Post
Yeah you are right, the time really moves by itself in seconds, it's been a long long time since I last played

The only problem I noticed is that you didn't removed the milliseconds from the tickcount
pawn Code:
new count = tickcount(); // lets say this is 5321 - 5 seconds 321 milliseconds
count = count%1440000; // thats far less than that so it stays
SetPlayerTime(playerid,count/60,count%60); // result = 88 and 41
//
new count = (tickcount() / 1000) % 1440; // 5321 / 1000 => 5, or just (gettime() % 1440)
SetPlayerTime(playerid,count/60,count%60); // 0 and 5
But I don't know why your clocks moves so fast
Since this isn't natural it is caused by a script (gamemode, filterscript, include ?)

Also this code needs to be in OnPlayerSpawn because if you die the time moves 8 hours in the future

Edit: Just noticed another thing, if you pause the game the clock stops, I think its better if you update it manually in a timer each second
I will use a timer and thanks for the that fix.I dint notice it.
Thank you both

I will go through all my code and will try to find out what is triggering the super fast clock.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)