DazzaJay Posted January 14, 2008 Share Posted January 14, 2008 Hello all, i have just a small script request, a "real time" script, that will make the ingame clock sync to the time in "Windows Server 2003" (or if windows time not possible, just a normal time speed), instead of the original "1 second = 1 minute" system that it is on. Thanks in advance to anyone who can do this. Link to comment
Jumba' Posted January 14, 2008 Share Posted January 14, 2008 This is copied directly from the dev wiki with a few tweaks. more info here http://development.mtasa.com/index.php? ... etRealTime function showtime () local time = getRealTime() local hours = time.hour local minutes = time.minute outputChatBox ( "Server Time: "..hours..":"..minutes ) end addCommandHandler( "time", showtime ) Link to comment
DazzaJay Posted January 14, 2008 Author Share Posted January 14, 2008 Thanks for the quick reply because im a total noob at lua, i need to know a few things, does that update the in game clock + time of day (as in how light, dark, where sun is, etc) also, does it override all maps time settings with real time, and how do i go about installing it as a resource. Thanks. Link to comment
Jumba' Posted January 14, 2008 Share Posted January 14, 2008 Thanks for the quick replybecause im a total noob at lua, i need to know a few things, does that update the in game clock + time of day (as in how light, dark, where sun is, etc) also, does it override all maps time settings with real time, and how do i go about installing it as a resource. Thanks. oh no, sorry, I understood your question wrong, i thought you wanted to show the server time, I have no idea how to do what you want, Sorry.. maybe you can check the setGameSpeed function and see if you can make 1 minute take 60 seconds, not sure how though. Link to comment
DazzaJay Posted January 14, 2008 Author Share Posted January 14, 2008 Changing game speed, will not only slow the clock down, but put everything into slow motion... so to get the clock to run at real time in that method, it would mean dlowing the game down 60X which means that everything, walking, shooting, driving, everything would be 60X slower. but for a better way of setting the time to real time without slowing the game down...... my guesses are this would be easy for somone who knows what they are doing. a part that checks server time, which using a timer once a second sets the game time to the same time. and ofcourse, repeas once a second, to keep the game time set to real time. as for how to go about it, no idea, altho i do know that you can set the game time with the admin panel, so i dare say the awnser lies in there, i just have no idea how to find it, or how to get it to work. Link to comment
[email protected] Posted January 14, 2008 Share Posted January 14, 2008 It's possible to check the real server time, and use setTime() client-side, when the event "onClientRender" is triggered. The reason why that is a bad idea is that the game engine messes up screen drawing when setting the time. Doing this on every frame render makes the client's screen flicker really badly. Doing this every 500 or 1000 miliseconds is possible, but again the flickering is really annoying. Link to comment
dn83 Posted January 14, 2008 Share Posted January 14, 2008 I think I saw a discussion about this exact same thing somewhere, but I can't remember where.. (some other thread probably) Try this one: (client-side) function syncTime() local realTime = getRealTime() local hour = realTime.hour local minute = realTime.minute setTime( hour , minute ) end addEventHandler( "onClientRender" , rootElement , syncTime ) I tried it and it works, but I think sky flickering is increased and fps decreased.. Could be my imagination.. Might work better serverside, with a timer instead of the onClientRender (there has to be something to stop the ingame-time from running at 60x speed again) Edit: ok, so it's not just my imagination then Link to comment
DazzaJay Posted January 14, 2008 Author Share Posted January 14, 2008 Well, Time Sync Tool keeps the time at system time (in single player only ofcourse) the only thing that even slightly flickers is the Realtime Shadows of static objects, as they move 3 times a second. As for flickering, there is a massive problem with that as it is, because of this "Awesome new font rendering system" or whatever, i have to put up with constant sky flickering, and if i use that console command to stop that crap from happening, the chat goes all blocky, and other text on screen gets supersised. its really a Great new system. But anyways, how do i put that code into a script so i can test this out on my end with a timer of 500ms instead of the render option, and the game time being set to server time and not client time? as if it gets set to client time, then that means that some people will have daytime on thier screen while others will have night, and that will make things a little unfair on some maps visability wise. Link to comment
dn83 Posted January 14, 2008 Share Posted January 14, 2008 also, how do i put that code into a script so i can test this out on my end with a timer of 500ms instead of the render option, and the game time being set to server time and not client time? replace the eventhandler with a setTimer() The wiki says getRealTime() returns the servertime, also when run as a client script. Don't know if it's true (and don't know why it wouldn't be ), but if it is true then all players will have the same time on their screen (server-time) Link to comment
Jumba' Posted January 14, 2008 Share Posted January 14, 2008 (edited) i did what you said and I got a stack overflow error function setTime() local realTime = getRealTime() local hour = realTime.hour local minute = realTime.minute setTime( hour , minute ) end setTimer ( setTime, 500, 0 ) btw dn68, the wiki says this This example outputs local time (server or client, where ever it was triggered) as hours and minutes so i think that getRealTime gets local time if run clientside Edited January 14, 2008 by Guest Link to comment
DazzaJay Posted January 14, 2008 Author Share Posted January 14, 2008 function syncTime() local realTime = getRealTime() local hour = realTime.hour local minute = realTime.minute setTime( hour , minute ) end setTimer ( "500" , rootElement , syncTime ) is that right? and also, how would i go about running this on the server to test, like, is that the only stuff to go in the .lua file? or is more code neded or what? Link to comment
Jumba' Posted January 14, 2008 Share Posted January 14, 2008 function syncTime() local realTime = getRealTime() local hour = realTime.hour local minute = realTime.minute setTime( hour , minute ) end setTimer ( "500" , rootElement , syncTime ) is that right? and also, how would i go about running this on the server to test, like, is that the only stuff to go in the .lua file? or is more code neded or what? only that, but it doesn't work, i got a stack overflow error (line 2). No idea what that is. Link to comment
DazzaJay Posted January 14, 2008 Author Share Posted January 14, 2008 Dosent the script need an ACL or somthing that allows it to make the time change commands? Link to comment
Jumba' Posted January 14, 2008 Share Posted January 14, 2008 Dosent the script need an ACL or somthing that allows it to make the time change commands? I'll try and see, i think that may be it. Link to comment
dn83 Posted January 14, 2008 Share Posted January 14, 2008 i did what you said and I got a stack overflow error function setTime() local realTime = getRealTime() local hour = realTime.hour local minute = realTime.minute setTime( hour , minute ) end setTimer ( setTime, 500, 0 ) btw dn68, the wiki says this This example outputs local time (server or client, where ever it was triggered) as hours and minutes so i think that getRealTime gets local time if run clientside 83, not 68.. Hmm, try naming the function something else than setTime(), as it's already reserved.. Now I also noticed what was written further down on the page. But on the top of the wiki-page it still clearly says: "This function gets the real server time and returns it in a table." Link to comment
dn83 Posted January 14, 2008 Share Posted January 14, 2008 function syncTime() local realTime = getRealTime() local hour = realTime.hour local minute = realTime.minute setTime( hour , minute ) end setTimer ( "500" , rootElement , syncTime ) is that right? and also, how would i go about running this on the server to test, like, is that the only stuff to go in the .lua file? or is more code neded or what? Not quite, it's setTimer( function , delay , iterations ) -- 0 iterations are infinite, a loop so it would be setTimer( syncTime , 500 , 0 ) Link to comment
DazzaJay Posted January 14, 2008 Author Share Posted January 14, 2008 thanks for the tip. as id only started to get a basic grasp on Mirc scripting, and now DM is out, ive gotta learn everything again, so now i know what order thigns fgo in in timers Any luck with the ACL? Link to comment
Jumba' Posted January 14, 2008 Share Posted January 14, 2008 (edited) Hmm, try naming the function something else than setTime(), as it's already reserved.. ah thanks! it works now, the sky does flicker allot though = / and the acl is not needed, it worked without it this is the code i used function syncTime() local realTime = getRealTime() local hour = realTime.hour local minute = realTime.minute setTime( hour , minute ) end setTimer ( syncTime, 500, 0 ) the problem was that setTime is a reserved function (obviously ) Edited January 14, 2008 by Guest Link to comment
DazzaJay Posted January 14, 2008 Author Share Posted January 14, 2008 (edited) ok, so this dosent need an ACL? function syncTime() local realTime = getRealTime() local hour = realTime.hour local minute = realTime.minute setTime( hour , minute ) end setTimer ( syncTime, 500, 0 ) just to doubble check, is that correct? also, if i go to admin console, and click the set time thing over and over.... about once a second, i dont get any sky flickering.... i havent tested this script yet tho, so i dont know what it does, but im guessing it should act in a similar way to the admin panel. Edited January 14, 2008 by Guest Link to comment
DazzaJay Posted January 14, 2008 Author Share Posted January 14, 2008 Thanks so much for your help guys! im going to go and test this now... i will post in here again if i have any problems. Link to comment
dn83 Posted January 14, 2008 Share Posted January 14, 2008 I was thinking, how about making a custom clock: remove the ingame-clock (showPlayerHudComponent() ), and make a new clock (createTextDisplay() ), and update it once a minute along with setting a new game-time with setTime().. Anybody understand what I mean? I'm not surprised if you don't That would probably stop the flickering, as the time is set only once a minute. The sun/moon might skip slightly backwards when the new time is set, but is it noticeable? Don't know. Now I really need to sleep, I might try and do this some other day when I have time. If someone else hasn't made it already by then. Link to comment
DazzaJay Posted January 14, 2008 Author Share Posted January 14, 2008 yeah, at dawn / dusk just 1 game minute of difference is a big change in the sky and the brigntness, so that idea would be really noticeable. and yeah, i just tested the script then, and i can see the flickering your talking about, where almost everything flashes white each time it changes. Link to comment
DazzaJay Posted January 14, 2008 Author Share Posted January 14, 2008 I KNOW WHAT THE FLICKERING IS!!!! very quick, possibly only a couple of Millisecond lasting "Weather Changes" i worked this out by running the script and driving down the highway.... on some of the flickers i noticed that the cars tail lights blinked on with them during the flash, and in some flash's you would get water spray from the tyres. its weather changing to a random weather on time changes for a very very short time. This was one of the problems with one of the earlier "Time Sync Tool"'s for single player, every second, on time update, the weather would change to a random weather. it seems like the same thing is happening with this script, with the only difference being that after a few ms the weather gets set right by the server. So now, we have a cause for the flicker. as for a way to fix it...... what about somthing that checks what weather is set at the time, and make sure that weather stays with the time change, or somthing like that. Link to comment
darkdreamingdan Posted January 15, 2008 Share Posted January 15, 2008 I think I saw a discussion about this exact same thing somewhere, but I can't remember where.. (some other thread probably)Try this one: (client-side) function syncTime() local realTime = getRealTime() local hour = realTime.hour local minute = realTime.minute setTime( hour , minute ) end addEventHandler( "onClientRender" , rootElement , syncTime ) I tried it and it works, but I think sky flickering is increased and fps decreased.. Could be my imagination.. Might work better serverside, with a timer instead of the onClientRender (there has to be something to stop the ingame-time from running at 60x speed again) Edit: ok, so it's not just my imagination then Firstly, you're syncing time according to the client's time, meaning changing your system clock changes the ingame time. The should be serverside. Fyi, the sky flickering is caused by changing the time repeatedly in one second. Not really to do with the weather. In the above example you're setting the time like ~30 times a second which really is silly. In the 500ms timer example, the effect is less so, but you can only reduce the effect by changing time every ~30 seconds. It might be sensible to make your own clock if you cant get around the horrible effects. Link to comment
Recommended Posts