Jump to content
Sign in to follow this  
Electricleash

skipTime/setDate/daytime and Multiplayer

Recommended Posts

I have recently been experimenting in the editor with these codes:

skipTime/setDate/daytime

I have created a script with help of the Wiki that works nicely for starts:

while {alive player} do {

skipTime 0.00933;

sleep 0.00002;

};

However I am now trying to figure out this suggestion:

Here is a useful piece of code that will enable the mission to skip forward to any given time, irrespective of what time it happens to be in the mission:

skipTime (_timeToSkipTo - daytime + 24 ) % 24

See also: a % b

Where would I put in the time I want to skip to and in what format should it be?

It frustrates how the wiki assumes you know.

Also I was wondering if there was (similar to the daytime code) a way to check the current time on a server, as this code is local to players machines only.

What i'm attempting is that during a coop game an objective is met by one of the players, thus triggering time to skip forward for all players.

E.g. a mission takes place during the early morning and at dusk (these IMHO have the nicest atmosphere) so I want time to move forward at regular pace during these times and to move slightly faster during the day (it's a stealthy mission) and through the night (players won't have access to night vision and will likely get frustrated over a long period of time.)

I suspect I'm sliding down pipe dreams for the latter part but if someone could answer the first part, i'd be grateful.

E

Share this post


Link to post
Share on other sites

Hi all

This is exactly what I am looking for too! Can someone please explain how to make the above script fragment work so that i can jump my mission to a specific time - ie advance time to 0600 hours??

Thanks very much - I have searched for this for ages!

Share this post


Link to post
Share on other sites

create a file called skip.sqf...

updateTime=false ;
skipAmount = 0; 
timeRef = daytime ;

gotoTime ={
    skipAmount = (_this select 0) - (daytime - timeref) ;
    updateTime = true ;
    publicVariable "updateTime" ;
} ;

if (not isNull player) {
    monitorTime ={
  while {true} do {
       waitUntil {updateTime} ;
       updateTime = false;
       skiptime skipAmount ; 
  } ;
    } ;

    [] spawn { [] call monitorTime;} ;
} ;

in init.sqf put this line...

call compile preprocessfile "skip.sqf";

either from a client or the server you can then..

[48] call gotoTime ; //skip to the time 48 hours from the start of the mission

Note that the parameter you passed in is the number of hours from the mission start time. This function doesn't bother checking that the time hasn't already elapsed so you can use it to go backwards in time as well - up to you whether you consider that a bug or a feature ;-)

Edited by sbsmac

Share this post


Link to post
Share on other sites

Wow, thanks so much for the help

I cant seem to get it to engange though - I have followed the steps and have put:

[5] call gotoTime

in the on act section of a trigger, but no joy - am i doing something wrong?

Thanks again for the help.

Share this post


Link to post
Share on other sites

easiest way to debug these things is to use 'player sidechat' to print out messages depending on where in the code it gets to.

So... put

player sidechat "in gotoTime" ;

as the first statement of gototime, then you can see whether it'sbeing called.

Also, check the arma2.rpt file - I didn't botherchecking for syntax errors so the script may have failed to compile

Edited by sbsmac

Share this post


Link to post
Share on other sites

sbsmac ? I think you forgot to set skipAmount as publicvariable.

I've taken the liberty of changin the code a bit.

Instead of beeing relative to the missiontime it now jumps to a fixed daytime.

That way it also ensures that all clients have the same time. (calculation takes place on the client, taking the local time in account, the server only passes the desired time of day)

targetTime = -1; 

gotoTime ={
targetTime = _this select 0;
publicVariable "targetTime";
};


monitorTime ={
while {true} do {
	waitUntil {targetTime != -1};
	skiptime (targetTime - daytime); 
	targetTime = -1;
};
};

[] spawn { [] call monitorTime;};

Also I don't see much use in having this run only for the players, the time on ther server should be updated aswell. (unless you want enemy AI behaving like it was bright daylight while you're trying to sneak up in the middle of the night.)

Edited by Tajin

Share this post


Link to post
Share on other sites

Hey wow Tajin, that worked! So this will update server time also so that enemy are aware of the correct time is that right?

Thanks so much Tajin. SBSMAC - thanks so much also - these forums are so damn useful because of guys like you who take the time to help people out. This game has an amazing community because of poeple like you, who are damn clever when it comes to all this scripting stuff, but also patient enough to help others out.

It's much appreciated. :-)

---------- Post added at 09:40 AM ---------- Previous post was at 09:27 AM ----------

Ahh Alas, :-) I spoke too soon...

This works, but how do i change the variable? Adjusting the ? (as below) in the trigger init doesnt make any differnce - the code always changes the time to 23:00 hours..

[?] call gotoTime

Share this post


Link to post
Share on other sites

My bad, mixed up two lines.

Try it again.

Share this post


Link to post
Share on other sites

That's interesting on a couple of counts...

1) i didn't realise the ai took account of time of day (though as you say it is kind of obvious they shouldn't be abelto see in the dark).

2) What formats are acceptable for targetTime? Presumably you're not suggesting that the absolute time has to be passed in as number of hours from the epoch ?

Share this post


Link to post
Share on other sites
What formats are acceptable for targetTime?

Hours, anything between 0 and 24. Other values would technically work too, but I wouldn't recommend that.

Oh since we're already talking about it, this snipplet might be interesting to you guys.:

		if (_enabled != true) then {	
		_enabled = true;	
		tfx1 = overcast;
		tfx2 = fog;
		0.5 setFog 0.3;
		0.5 setOvercast 0.5;

		tdate = date;
		ttime = time;
		setdate [2008, 8, 20, 22, 0];
	} else {
		_enabled = false;			
		0.5 setFog tfx2;
		0.5 setOvercast tfx1;

		_passed = time - ttime;
		_hour = abs (_passed / 3600);
		_passed = _passed - _hour * 3600;
		_min = abs (_passed / 60);
		_min = (tdate select 4) + _min;
		if (_min > 60 ) then {
			_min = _min - 60;
			_hour = _hour + 1;
		};				
		_hour = (tdate select 3) + _hour;
		_day = 0;
		if (_hour > 24) then {
			_hour = _hour - 24;
			_day = 1;
		};
		setdate [(tdate select 0),(tdate select 1),(tdate select 2) + _day,_hour,_min];
	};

I'm using something like that for FLIR effects, it allows me to set the time to an specific date/time when enabling it and reverts back to the original time + the time passed afterwards.

This can also be used as a different solution for the other script, one that uses setdate instead of skiptime. (no more calculation needed then)

Share this post


Link to post
Share on other sites

Here is my contribution, which I made for farm wars. Nights are passing twice as fast as days. You can set the startdate in the init.sqf and publish it onplayerconnected:

sleep 5;
//startdate = [2009,0.529796]; //13.07.2009
_increments = 0.000002; //~1 minute

for [{_i=0},{_i<1},{_i=_i}] do
{
_date = startdate select 1;
_date = _date + _increments;
if (_date >= 1) then //set year +1
{
	startdate set [0,(startdate select 0)+1];
	startdate set [1,0];
}
else
{
	startdate set [1,_date];
};
setDate NumberToDate startdate;
if (((NumberToDate startdate) select 3) >= 20 or ((NumberToDate startdate) select 3) <= 9) then {_increments = 0.000004;} else {_increments = 0.000002;};
sleep 5;
};

Share this post


Link to post
Share on other sites

//Skiptime from current time [15.5] call gotoTime ; //skip the current time 15 hours and 30 min when is called

//Put this: call compile preprocessfile "scripts\skiptime.sqf"; at init.sqf

increm = -1000;

gotoTime ={

increm = _this select 0;

publicVariable "increm";

targettime=daytime+increm;

while {targettime>=24} do {targettime =daytime+increm-24};

publicVariable "targettime";

};

monitorTime ={

waitUntil {increm != -1000};

while {abs(targettime-daytime)>0.01} do {skipTime 0.00933;sleep 0.00002};

increm = -1000;

};

[] spawn { [] call monitorTime;}; :yay:

Another kind:

skiptime.sqf

//Pasa el tiempo la cantidad marcada en [18.5] execvm "scripts\skiptime.sqf"; //skip to the time 18 hours and 30 min from current time when is called

// stimeinc = [4] execvm "scripts\skiptime.sqf";

increm = _this select 0;

targettime=daytime+increm;

while {targettime>=24} do {targettime =daytime+increm-24};

while {abs(targettime-daytime)>0.01} do {skipTime 0.00933;sleep 0.00002};

if (true) exitwith {};

To call this

stimeinc = [15.4] execVM "skiptime.sqf";

Edited by PataPalo

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×