Jump to content
Sign in to follow this  
1para{god-father}

Change time 1/2 way through game ?

Recommended Posts

I have a COOP mission on a dedi server and I start it at night time, but when we complete the first task I need it to them go to Day time.

I sure I have seen this somewhere but cannot find it on search.

But i need everyone including any JOIP to be on the same time, is this possible ?

Many thanks

I think i found it , but will this work for JIP ? will this cause any lag issue ?

movetime.sqf

while {true; } do {
setDate [2011, 6, 15, 12, 00];
sleep 5;
}; 

Edited by psvialli

Share this post


Link to post
Share on other sites

Well you should test it and find out! Post back here again if it works or not!

Share this post


Link to post
Share on other sites

skiptime is broadcasted over network after a short while, try that if setDate does not work, also i dont think you need to loop the setDate, as server will update its own time to give to JIP units.... i think...

Share this post


Link to post
Share on other sites

OK setdate does work but it does seem to cause a lot off Lag , - am i not looping it with - While{True} ??

Anyway is there a way it can just be set once so no need for a loop ? I presume the problem will be JIP if they join after the time reset ? any idea's ?

Thanks

Share this post


Link to post
Share on other sites

while {true} do {
  setDate [2011, 6, 15, 12, 00];
  sleep 5;
};

will set it to noon that date every 5 seconds, as long as mission is active.

Maybe try this in units initline instead of loop:

setDate date;

Now when unit joins server JIP it will setDate to the servers date

Edit1: date command is local, so my above wont work. are you sure setDate is not counted in when JIP after?

Edit2: running a script from init.sqf, will work though i believe.

Edit3: modified code a little, maybe it can be directly placed in init.sqf, to work with JIP.

{
_actDate = [];
if (isServer) then {_actDate = date};
if (_x == player) then {setDate _actDate};
} foreach playableUnits;

But im not even sure it will be needed as i think or hope setDAte is broadcasted to any new JIP unit.

Edited by Demonized

Share this post


Link to post
Share on other sites

This is NOT tested. If it works, it should work for alle currently and future (JIP) players. Time will progress normally also. If someone joins 40 minutes after the change their date would also be 40 minute after what the date was changed to.

[nil, nil, "per", rSpawn, [time, [2011, 6, 15, 12, 00]], {
private ["_minutesPassed","_newMinutes","_secondsOfChange","_dateTarget"];
_secondsOfChange = _this select 0;
_dateTarget = _this select 1;
_minutesPassed = round ((time-_secondsOfChange)/60);
_newMinutes = (_dateTarget select 4) + _minutesPassed;
_dateTarget set [4, _newMinutes];
setDate _dateTarget;
}] call RE;

You'll need the functions module.

Btw, only run this on one machine (eg. the server). Could use an if check:

if (isServer) then {
//Do it here
};

Edited by Muzzleflash

Share this post


Link to post
Share on other sites

Yep apply setDate only on the server.

It is quite a heavy command, so it should not be used constantly.

Share this post


Link to post
Share on other sites

Many thanks for the replys !

Just so I get this correct.

On a trigger after I complete the first mission:-

Trigger

0 = [] execVM "Movetime.sqf"

Movetime.sqf

if (isServer) then {
[nil, nil, "per", rSpawn, [time, [2011, 6, 15, 12, 00]], { 
   private ["_minutesPassed","_newMinutes","_secondsOfChange","_dateTarget"]; 
   _secondsOfChange = _this select 0; 
   _dateTarget = _this select 1; 
   _minutesPassed = round ((time-_secondsOfChange)/60); 
   _newMinutes = (_dateTarget select 4) + _minutesPassed; 
   _dateTarget set [4, _newMinutes]; 
   setDate _dateTarget; 
}] call RE;
};  

A Question

what is "CALL RE" ?

Share this post


Link to post
Share on other sites

Isn't there a script like this in the COOP gametype WAR in Takistan? I was playing the with my unit about a week ago and when you activated a OP time would accelerate! I bet you can find the script in that mission and use it...

Share this post


Link to post
Share on other sites

Hi Guys,

Still having a issue with this, it works great when we are all in the game , but JIP players it does not work.

Any idea how I can get JIP to work?

Thanks

Share this post


Link to post
Share on other sites

When I use the script Muzzleflash has provided and call it from a radio trigger, everything works fine, I can switch between night and day with ease. However, if I try and use the exact same script and call it from an addAction menu, nothing happens.

Does anyone know why this might happen?

Trigger code:

nul = [] execVM "scripts\changetimenight.sqf";

addAction code:

this addAction ["Wait until nightfall","scripts\changetimenight.sqf"];

Edited by murderhorse

Share this post


Link to post
Share on other sites

addaction is local to the caller, a editor placed trigger is global.

edit: in the addaction, simply set a variable to true instead of running the script, and have that variable in condition of the repeated trigger wich runs the script...

Edited by Demonized

Share this post


Link to post
Share on other sites
addaction is local to the caller, a editor placed trigger is global.

Ah ok, it makes sense now. Thank you.

edit: and thanks again for the solution :)

Share this post


Link to post
Share on other sites
Ah ok, it makes sense now. Thank you.

edit: and thanks again for the solution :)

The code updates the time for all current players. The "per" part ensures that it is also run for anyone who joins later.

I wrapped it all in isServer so the code is only run once as intended. That's why it works with the trigger which everyone has (including the server, which is the only one allowed to run it) and didn't work for a player that isn't the server also.

However, my intent was that the code is only run a single time. If you want to be able to use it from an action then remove the first and last line so it looks like this:

[nil, nil, "per", rSpawn, [time, [2011, 6, 15, 12, 00]], { 
   private ["_minutesPassed","_newMinutes","_secondsOfChange","_dateTarget"]; 
   _secondsOfChange = _this select 0; 
   _dateTarget = _this select 1; 
   _minutesPassed = round ((time-_secondsOfChange)/60); 
   _newMinutes = (_dateTarget select 4) + _minutesPassed; 
   _dateTarget set [4, _newMinutes]; 
   setDate _dateTarget; 
}] call RE;

Actually it might even work even if multiple people run the code, it was never the intention. However, I would recommend the method that Demonized suggested.

Share this post


Link to post
Share on other sites

One thing to mention is the pings of the different players reflect the desynchronization of time for all players on the server. So time can go out of synch by a few minutes or even tens of minutes depending on how long the mission has ran without any global update to the date on all clients.

If specific time is important (like 7:00 to trigger something) you might want to write a short script that resynchronizes time across all clients with the server every 5 minutes or so.

I believe weather must also be synchronized like this, but arma's engine likes to interfere, and hence some ppl might see rain, others might see clear day.

just something to consider.

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  

×