sickboy 13 Posted February 27, 2007 Sickboys Scripts [ Tested 1.04 ] Work Perfectly. Awesome Matt, Thanks for testing  Special Ed: I am unsure myself, altough I love scripting, im not the time-guru . Maybe you could post the scripts? How big are the steps that the time is skipped? I also don't fully understand how the 'clouds are pushed through frames' Since Victor wrote some of the code he might give you some insight Share this post Link to post Share on other sites
Guest Posted February 27, 2007 ColonelSandersLite time flow modifier <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private [ "_timeFactor", "_interval", "_timeFactor", "_startTime", "_i", "_nowTime", "_timeDifference" ]; // this is the factor that time will be sped up by // if you pass it 30, 1 real time min == 30 game time mins _timeFactor = _this select 0; // interval, every frame (1) is slow but smooth. every 5 frames is fast but jerky, every 10 frames has no noticible FPS hit, but is very jerky // this should probably be user configurable in some way. _interval = _this select 1; // parse the time factor into a useable format _timeFactor = _timeFactor/60/60; while {true} do { while {true} do { while {true} do { _startTime = time; _i = 0; waitUntil {_i = _i + 1; _i > _interval}; _nowTime = time; _timeDifference = _nowTime - _startTime; if (_timeDifference > 0) then { skipTime (_timeFactor/(_interval/_timeDifference)); }; }; }; }; He actually posted this script on Ofpec and here in forums as well (download link that is) - but, again, he mentioned that due to clouds being affected by the skip time, the lesser the time between each skipTime (which means smoother) the more it lags because clouds are moved along with the time change (nother words, a ten second skiptime would 'jerk' the clouds from their current position to where they *would* be had ten seconds passed) - hence, like he put in his notes, a smooth appearance is lesser time amounts of each skip time, but then more regular fps drop is noticed. He said there wasnt anything that can be done, because the 3d cloud layer is directly linked to the time, just wondered if you guys might know of a way to keep the clouds from being affected by this.. Share this post Link to post Share on other sites
VictorFarbau 0 Posted February 27, 2007 I must say I didn't like the scripts I saw so far It's good work and appreciated, sure, but to me it all looks a bit lengthy and clumsy. So I decided to throw a new script into the ring which I claim is the shortest fully MP compatible time sync script. Nothing wrong with a bit of competition, right? Just having fun. Instructions for a test: 1. Create a new mission that contains a player, an "H (invisible)" object called "mytimeobject" and of course a logic object called "Server" (as usual for MP missions). 2. Call both scripts "MPtimeserver.sqs", "MPtimeclient.sqs" 3. Watch the dawn The server script maintains an absolute hour:minute time format, all clients will synchronize to the exact server time, whether this means in- oder decreasing the current localtime by the necessary values. MPtimeserver.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"># _servertime = continuous count of time in minutes, starts at 05:00h in this example # _accel = acceleration factor (1h in 24h = accel 24) ?!(local Server): exit _servertime = 5 * 3600 _accel = 24 _updateinterval = 1 mytimeobject setpos [0,0,0] #tempusfugit ~_updateinterval _servertime = _servertime + (_updateinterval * _accel) _abshours = floor(_servertime / 3600) _absmin = floor((_servertime MOD 3600) / 60) mytimeobject setpos [_abshours,_absmin,0] goto "tempusfugit" MPtimeclient.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"># Time client script _serverhours = 0 _servermin = 0 #tempusfugit ~2 _localhours = floor daytime _localmin = 60 * (daytime MOD (floor daytime)) _serverhours = (getpos mytimeobject) select 0 _servermin = (getpos mytimeobject) select 1 skipTime (_serverhours - _localhours) skipTime ((_servermin - _localmin) / 60) goto "tempusfugit" Regards, Victor Share this post Link to post Share on other sites
sickboy 13 Posted February 27, 2007 ... Only cool Victor, I like what I see, altough I am a strong believer for going sqf-only, not that there would be any possible performance gain I can think of in this case though Thanks for the lesson btw  Nice to see ur changing/updating the server time now aswell Share this post Link to post Share on other sites
snkman 351 Posted February 27, 2007 LoL damn this is the SkipTime Server Sync. Script battle Thread. Well agree pretty nice Script you have made there Victor Share this post Link to post Share on other sites
VictorFarbau 0 Posted February 28, 2007 SNKMAN, just be advised that the init.sqs script is launched right after the mission is loaded (which means it already runs during briefing). This can have undesireable effects at times - for example when accessing objects that are only initialized after the mission begins. What I generally do is to set a trigger around the player on the map that is set off by anyone which launches a "runscripts.sqs" which has all the launch commands in it. This way I make sure my scripts are only being started once the mission really begins. The runscripts.sqs could look like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> this exec "MPtimserver.sqs this exec "MPtimeclient.sqs" exit Since neither script exepects any parameter it doesn't really matter if you launch them with "this" or "[]". Regards, Victor Share this post Link to post Share on other sites
snkman 351 Posted March 1, 2007 Hey VictorFarbau, thank's for your help it really work's like a charme too. B.t.w. right now i try to convert all my script's to .sqf maybee can you convert this to .sqf? Share this post Link to post Share on other sites
snkman 351 Posted March 2, 2007 Hey VictorFarbau, i was just testing your Script with 1.05 on a dedicated Server and it look's like it doesn't work... In the Editor and on a local hosted Game it works pretty nice but on a Dedicated Server the Time skip is that fast 1 sec. it's night another sec. it's day. First i thought my Graphic Card is damaged till i looked on the clock. Well can you fix that plz? Share this post Link to post Share on other sites
VictorFarbau 0 Posted March 3, 2007 Error confirmed. Very odd indeed since it worked before. I wonder what they changed in 1.05 again that breaks this, guess I will find out I will try to fix this during this weekend. I just got used to an accelerated time during missions as well now. Regards, Victor Share this post Link to post Share on other sites
snkman 351 Posted March 3, 2007 Okay thank you very much VictorFarbau Share this post Link to post Share on other sites
VictorFarbau 0 Posted March 3, 2007 I found the error. The position of "mytimeobject" was not distributed in an MP environment anymore. Just guessing, but maybe these are optimizations to the netcode and only certain object classes positions are getting updated through netcode now. Either way, I went back to global (public) variables and this works fine again. Let me know if you see any more errors with that. Victor PS: Your request to convert this to SQF. It doesn't make sense for this particular piece of code in my mind. First it runs as a single instance (precompiled SQF is good if you spawn the same script a lot of times) and secondly SQF runs synchronously (caller has to wait for script to end) which means you would need more code only to call it correctly. Nah, useless here. Timeserver.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"># Accelerated Time Server build 002, (c) 2007 Victor Farbau # Map objects needed: game logic called "Server" # servertime = continuous count of time in seconds # accel = acceleration factor (1h in 24h = accel 24) # _hourlist holds an array of scenic starting hours, could also be set to a fix value if desired # VFserverhours, VFservermin are public variables that contain the server time ?!(local Server): exit _hourlist = [4,5,6,7,12,17,18,19] _hourcount = (count _hourlist) - 1 _servertime = (_hourlist select (random _hourcount)) * 3600 _accel = 4 _updateinterval = 2 #tempusfugit _servertime = _servertime + (_updateinterval * _accel) VFserverhours = floor(_servertime / 3600) VFservermin = floor((_servertime MOD 3600) / 60) publicVariable "VFserverhours" publicVariable "VFservermin" ~_updateinterval goto "tempusfugit" timeclient.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"># Accelerated Time Client build 002, (c) 2007 Victor Farbau # If this runs on a dedicated server then quit now ?(player != player): exit # Init global variables locally to avoid undefined values being used; then wait 5 more sec for server VFserverhours = 1 VFservermin = 1 ~5 #tempusfugit ~2 _localhours = floor daytime _localmin = 60 * (daytime MOD (floor daytime)) skipTime (VFserverhours - _localhours) skipTime ((VFservermin - _localmin) / 60) goto "tempusfugit" Share this post Link to post Share on other sites
snkman 351 Posted March 3, 2007 WoW that fast! Thank you very much Victor for fixing this fantastic piece of Script. Well okay if you say there's no need for .sqf Thanks Victor Share this post Link to post Share on other sites
VictorFarbau 0 Posted March 11, 2007 Fixed an DIV by 0 bug by just skipping the time from 00:00 to 01:00 AM. Also added 2 code lines to accelerate the night time (20h to 3h) by 2x. I mean, nights are ok but not for hours during a mission. If this effect is not desired, remove the two lines before "~updateinterval" completely and it will run with a constant speed. Fixed MPtimeserver.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"># Accelerated Time Server build 004, (c) 2007 Victor Farbau # Map objects needed: game logic called "Server" # servertime = continuous count of time in seconds (00:00 is skipped, too much workaround otherwise) # accel = acceleration factor (1h in 24h = accel 24) # _hourlist holds an array of scenic starting hours, could also be set to a fix value if desired # VFserverhours, VFservermin are public variables that contain the server time ?!(local Server): exit _accel = 6 _updateinterval = 2 _hourlist = [4,5,6,7,12,17,18,19] _hourcount = (count _hourlist) - 1 _servertime = (_hourlist select (random _hourcount)) * 3600 _taccel = _accel #tempusfugit _servertime = _servertime + (_updateinterval * _taccel) ?(_servertime < 3600): _servertime = 3601 VFserverhours = floor(_servertime / 3600) VFservermin = floor((_servertime MOD 3600) / 60) publicVariable "VFserverhours" publicVariable "VFservermin" ?((VFserverhours > 20) OR (VFserverhours < 3)) : _taccel = _accel * 2 ?((VFserverhours > 3) AND (VFserverhours < 20)) : _taccel = _accel ~_updateinterval goto "tempusfugit" MPtimeclient.sqs remains identical. Cheers, Victor Share this post Link to post Share on other sites
snkman 351 Posted March 11, 2007 Well im sorry Victor but the script still has the same error as bevore... After the error my NVGoogles have strange flashes all over the place? Share this post Link to post Share on other sites
VictorFarbau 0 Posted March 11, 2007 Interesting - at any specific time? Does the clock advance correctly? I fixed this due to an error that would cause the server to not update the time correctly anymore. Flashing of NVgoggles... very odd. I will try to reproduce. Victor Share this post Link to post Share on other sites
snkman 351 Posted March 11, 2007 Yeah it always happends at 12 P.M. so exactly at midnight like bevore. Well some guy's told me, that they can't use the NVgoogles after the error becouse there are light flashes all over the screen and at i played the mission last time i get this too. Hope you can fix it. Share this post Link to post Share on other sites
VictorFarbau 0 Posted March 11, 2007 You're right And my fix was premature. I fixed this again and this time I even tested it It properly runs through time now and at midnight it skips one hour (to avoid DIV 0 annoyances). When using NV goggles it flashes exactly one time when the new day starts (don't ask me why) but then it continues to run normally. And if not let me know Again, delete the last two lines of the server script if you don't want an even more accelerated night time. Regards, Victor MPtimeserver.sqs Quote[/b] ]# Accelerated Time Server build 005, © 2007 Victor Farbau# Map objects needed: game logic called "Server" # servertime = continuous count of time in seconds (00:00 is skipped, too much workaround otherwise) # accel = acceleration factor (24h in 1h = accel 24) # _hourlist holds an array of scenic starting hours, could also be set to a fix value if desired # VFserverhours, VFservermin are public variables that contain the server time ?!(local Server): exit _accel = 24 _taccel = _accel _onehour = 3600 _oneday = (24 * _onehour) - _accel _hourlist = [4,5,6,7,12,17,18,19] _hourcount = (count _hourlist) - 1 _servertime = (_hourlist select (random _hourcount)) * 3600 #tempusfugit ~1 _servertime = _servertime + _taccel ?(_servertime < _onehour): _servertime = _onehour + 1 ?(_servertime > _oneday): _servertime = _onehour + 1 VFserverhours = floor(_servertime / 3600) VFservermin = floor((_servertime MOD 3600) / 60) publicVariable "VFserverhours" publicVariable "VFservermin" ?((VFserverhours > 20) OR (VFserverhours < 3)) : _taccel = _accel * 2 ?((VFserverhours > 3) AND (VFserverhours < 20)) : _taccel = _accel goto "tempusfugit" MPtimeclient.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"># If this runs on a dedicated server - quit now ?(player != player): exit # Init global variables locally to avoid undefined values being used; then wait 5 sec for server ~5 #tempusfugit ~1 _localhours = floor daytime _localmin = 60 * (daytime MOD (floor daytime)) skipTime (VFserverhours - _localhours) skipTime ((VFservermin - _localmin) / 60) goto "tempusfugit" Share this post Link to post Share on other sites
warpuppy 0 Posted March 12, 2007 Hi there all @ Victor Sorry to trouble but would the above mentioned scripts work in single player mode and if so could you tell me how to run it As i undestand you need a Game logic called server and from there i am totally lost Sorry i am still very wet behind the ears wheni tcomes to editing @ all old hand and scripting vetrans I really take my hat off to guys and i just wanted to say thanks for the hard work you guys do Share this post Link to post Share on other sites
snkman 351 Posted March 12, 2007 Well for single player you need only this: MPtimeclient.sqs" <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"># If this runs on a dedicated server - quit now ?(player != player): exit # Init global variables locally to avoid undefined values being used; then wait 5 sec for server ~5 #tempusfugit ~1 _localhours = floor daytime _localmin = 60 * (daytime MOD (floor daytime)) skipTime (VFserverhours - _localhours) skipTime ((VFservermin - _localmin) / 60) goto "tempusfugit" The other script is just for Server Sync. Okay create a new text document with "Notepad" for example call it "init.sqs" put it into your Mission folder and write this in it: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> [] exec "MPtimeclient.sqs" Put the "MPtimeclient.sqs" Script in your mission folder, create a Game Logic called Server and that's it. Share this post Link to post Share on other sites
snkman 351 Posted April 20, 2007 Hey sickboy, just tested your Script and it look's like Time is not Sync on a Server after JIP. Maybe it's becouse of 1.05 (beta) i don't know... May can you fix it? EDIT: Never mind It works the time just need some time to Sync. Pretty good job Sickboy Share this post Link to post Share on other sites