Jump to content
easyeb

Make time run faster at night.

Recommended Posts

So I use setTimeMultiplier to make the hours run a little faster in a mission. I’d like it to run at 2x speed at daytime, and 4x speed at night time. Anyone have any idea of how to implement that?

Share this post


Link to post
Share on other sites

Run on server only:
 

while {true}do {
waitUntil {dayTime >= 6};
setTimeMultiplier 1;
waitUntil {dayTime >= 20};
setTimeMultiplier 4;
};

Start your mission at before 6 am or it will only kick in on the second day. This is just a really crude snippet, it can be greatly improved.

  • Like 3

Share this post


Link to post
Share on other sites

I run an alive mission so time of day when script runs will vary greatly. I guess I need it to get the current time of day, and then run that snippet, no?

Share this post


Link to post
Share on other sites
1 hour ago, easyeb said:

I run an alive mission so time of day when script runs will vary greatly. I guess I need it to get the current time of day, and then run that snippet, no?

To make it work no matter the time of day upon mission start:

//initServer.sqf
GOM_fnc_variableDaytimeSpeed = {
	while {true} do {
		setTimeMultiplier ([2,4] select (daytime > 20 OR daytime < 6));
		waitUntil {sleep 10;round daytime isEqualTo 20 OR round daytime isEqualTo 6};
	};
};
_handleTimeMulti = [] spawn GOM_fnc_variableDaytimeSpeed;

You also need to put it inside initServer.sqf in mission root or it won't work.

 

Cheers

  • Like 4

Share this post


Link to post
Share on other sites

If you want to take different lengths of day into account, you could check the daytime with

if (sunOrMoon <1) then {setTimeMultiplier 4} else {setTimeMultiplier 2};

  • Like 3

Share this post


Link to post
Share on other sites
16 minutes ago, Greenfist said:

If you want to take different lengths of day into account, you could check the daytime with

if (sunOrMoon <1) then {setTimeMultiplier 4} else {setTimeMultiplier 2};

That would need to check continously right? 

Share this post


Link to post
Share on other sites
28 minutes ago, easyeb said:

That would need to check continously right? 

Yes. For example:
while {true} do { sleep 60;

    if (sunOrMoon <1) then {setTimeMultiplier 4} else {setTimeMultiplier 2}
};

Share this post


Link to post
Share on other sites
12 hours ago, Greenfist said:

Yes. For example:
while {true} do { sleep 60;

    if (sunOrMoon <1) then {setTimeMultiplier 4} else {setTimeMultiplier 2}
};

Wouldn't a couple of waitUntil do the work here too? I haven't checked it but I believe that a solution similar to Mr. H's would be fine with sunOrMoon.

 

I mean that probably you could do

// initServer.sqf
while {true} do {
	// Wait until it gets dark
	waitUntil {
		sunOrMoon < 1;
	};
	setTimeMultiplier 4; // Change the time multiplier
    
	// Wait until the sun shines again
	waitUntil {
		sunOrMoon isEqualTo 1;
	};
	setTimeMultiplier 2; // Change the time multiplier
};

I haven't checked it but it seems it should also do the work. Please correct me if I am wrong.

Nevertheless, you could use whichever suites your style better I guess.

 

EDIT: Now this is something I actually got "partially wrong". Preserving the sleep could possibly save some workload on the CPU. I don't have any indication as to how complex the sunOrMoon command is, so I can't really say how much CPU this condition check could use, but it's always good to save as much CPU as possible in ArmA.

  • Like 3

Share this post


Link to post
Share on other sites
11 hours ago, ZaellixA said:

waitUntil {

 

-Just add a little bit (ui)sleep after this.

writing a code can always be with many different ways , but maybe the most important thing , is always the performance.

 

  • Like 3

Share this post


Link to post
Share on other sites

Hey! Sorry if this is hijacking the thread too much but I thought it was relevant.

I wrote an FSM for day/night for my server and thought I'd share it as an alternative option to the while true loop. If anyone has info about which one would be most performance friendly or ways of improving it I'd love to hear (and it's the main reason I'm posting in this already "solved" topic).

 

"time.fsm":
 

Spoiler

//FSM State named "START"
_day = [true, false] select (sunOrMoon ==1);

//FSM Condition named "Night" linked to "START"
sunOrMoon != 1 && _day;

//FSM State named "setNightTime"
_day = false;
setTimeMultiplier 15;
[flagpost_us, 0] call salmon_fnc_flag;
["night"] call eos_fnc_Skill;
[] call salmon_fnc_adhan;
//The FSM State named "setNightTime" is linked to a loop that links back to both condition "Day" and condition "Night"

//FSM Condition named "Day" linked to "START"
sunOrMoon == 1 && !_day;

//FSM State named "setDayTime"
_day = true;
setTimeMultiplier 6;
[flagpost_us, 1] call salmon_fnc_flag;
["day"] call eos_fnc_Skill;
[] call salmon_fnc_adhan;
//The FSM State named "setDayTime" is linked to a loop that links back to both condition "Day" and condition "Night"

DO2k5bd.png

As I'm not the most experienced I'm not entirely sure what the smartest way to show an FSM would be but I tried to make it readable.

  • Like 1

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

×