!!Time Machine!! -
Yashas - 27.12.2013
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!!!
Re: !!Time Machine!! -
Yashas - 28.12.2013
bump
AW: !!Time Machine!! -
Nero_3D - 28.12.2013
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
Re: AW: !!Time Machine!! -
Yashas - 30.12.2013
Quote:
Originally Posted by Nero_3D
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.
AW: !!Time Machine!! -
Nero_3D - 30.12.2013
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 ?
Re: AW: !!Time Machine!! -
Yashas - 31.12.2013
Quote:
Originally Posted by Nero_3D
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.
AW: !!Time Machine!! -
Nero_3D - 31.12.2013
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
Re: !!Time Machine!! -
park4bmx - 31.12.2013
It does move by itself, but u can allways keep forcing it the same value
Re: AW: !!Time Machine!! -
Yashas - 01.01.2014
Quote:
Originally Posted by Nero_3D
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.