Jump to content
Sign in to follow this  
DeclaredEvol

Day and Night cycle script?

Recommended Posts

Excuse my last thread, I had stated the wrong idea of mind. What I was wanting to know is if there is a way to do a day and night cycle like possibly Sahrani life or Chernarus life??

I'm making night and day simulations for a clan I may be doing in the future. The training map has a location on the map for a camp out with a campfire and tent and some supplies. And it would really help to have a dynamic changing time from day to night and night to day.

[[Please delete my last thread, sorry for the inconvenience]]

Share this post


Link to post
Share on other sites

Don't know if I understand you correctly, here is what I suggest:

Extend your parameters in the Description.ext to the following:

class SkipTime {
title="Time Speedup";
values[]={0,1,3,4};
default=0;
texts[]={"24 hours day","12 hours day","6 hours day","2 hours day"};
};

Write this into your init.sqf:

if(not isNil "paramsArray") then{
[paramsArray select <x>] spawn {  //<x> a placeholder for the element in your paramsArray
	_skipspeed = (_this select 0)/2;
	while{_skipspeed > 0} do{
		sleep 0.5;
		skipTime(_skipspeed/3600);
	};
};
};

Now you can choose via mission parameter to have a 24h day, a 12h day, a 6h day and a 2h day.

In the Init.sqf code you can see the "sleep 0.5;" in the fifth line. This is the interval of jumping forward in time. Increase it, you will have a bit more of a slide show, but less performance loss, decreasing it makes the time skipping more fluently, but will cost you performance. Furthermore please note that, in the editor this won't work, since there the paramsArray is empty all the time - it will only work for MP.

If you intend to use it in SP, screw the Description.ext and params thing, replace the "paramsArray select <x>" fragment in the second code to either 0,1,2,4, corresponding to the desired speed of skiptime.

Share this post


Link to post
Share on other sites

Never ever do loops in the init.sqf. This script is meant to do initialization things, whatever is needed to be done at mission start. Keep it "one-shot" and don't do loops of any sort in it.

Better make a separate script for the time speedup and this script might be launched by the init.sqf.

Share this post


Link to post
Share on other sites
Never ever do loops in the init.sqf. This script is meant to do initialization things, whatever is needed to be done at mission start. Keep it "one-shot" and don't do loops of any sort in it.

Better make a separate script for the time speedup and this script might be launched by the init.sqf.

Actually, I agree to what you say, Myke, I wouldn't place it in the Init.sqf either, but this here was in purpose of simplification.

However, since the above loop appears within a spawn scope, it wouldn't cause any problems anyway.

Edited by Bon

Share this post


Link to post
Share on other sites

Shame on me, didn't noted the spawn command. Yes, agree, this way it wont cause problems. Should read entire code not only fragments. My apologies, mate.

Share this post


Link to post
Share on other sites

The server SHOULD (as I choose these words wisely) synchronize the daytime to JIP.

I made the experience that most of the times it does, sometimes not, where, in the second case it is a well-known bug that, I believe, did exist already in Armed Assault.

Share this post


Link to post
Share on other sites

Ok thank you for the help, all I need to know is what command do I need to execute. Where would I need to execute the command, and how to execute both the .ext and init.sqf??

Everything else seems quite clear to me though, I really appreciate your help. Just stick with me a little bit longer so I can get this right :]

---------- Post added at 06:31 PM ---------- Previous post was at 05:53 PM ----------

question about the following loop fragment:

while{_skipspeed > 0} do{

sleep 0.5;

skipTime(_skipspeed/3600);

};

I don't see _skipspeed decrementing. How does this loop ever end?

Edited by DeclaredEvol

Share this post


Link to post
Share on other sites

If you don't have a Description.ext yet, create it (in the root of your mission folder), and write this into it:

titleParam1="Time Speedup";
valuesParam1[]={0,1,3,11};
defvalueParam1=0;
textsParam1[]={"24 hours day","12 hours day","6 hours day","2 hours day"};

Next if you don't have an Init.sqf yet, create it (in the root of your mission folder), and write into it:

if(not isNil "paramsArray") then{
[Param1] spawn {  //<x> a placeholder for the element in your paramsArray
	_skipspeed = (_this select 0)/2;
	while{_skipspeed > 0} do{
		sleep 0.5;
		skipTime(_skipspeed/3600);
	};
};
};

Now, what happens in this code fragment? Simply said, every half a second it skips current time by the settled duration in seconds. That happens until the mission is over (on serverside) or the player leaves the session (on clientside). In other words, its an endless loop.

Edited by Bon

Share this post


Link to post
Share on other sites

Do I have to add a specific command to the game logic or will it automatically do this if its in the mission folder???

Share this post


Link to post
Share on other sites
Do I have to add a specific command to the game logic or will it automatically do this if its in the mission folder???

Well hey, I got it to work. I had to learn a little bit of script first though. But thanks for the help, it was a good source instruction.

Share this post


Link to post
Share on other sites

while(true)
{
     statements...
}

while(true) is a more explicit way of creating an endless loop... no checking, it just keeps going :bounce3:

Cheers

Share this post


Link to post
Share on other sites

@DeclaredEvol: The Description.ext extension file gets automatically loaded with the mission, the Init.sqf or Init.sqs script gets automatically initialized when starting the mission, all by the ArmA2 Engine. This is scripting basics, I recommend to study the code of some other missions or an editor guide like Mr_Murray's one before going any further.

@TheHarvesteR: What is the better solution for this case, either this:

while{_skipspeed > 0} do{
sleep 0.5;
skipTime(_skipspeed/3600);
};

or this:

while{true} do{
       if(_skipspeed > 0) exitWith{};
sleep 0.5;
skipTime(_skipspeed/3600);
};

Btw thanks for teaching me how to script an endless loop, now I can rest in peace. ;)

Edited by Bon

Share this post


Link to post
Share on other sites
@DeclaredEvol: The Description.ext extension file gets automatically loaded with the mission, the Init.sqf or Init.sqs script gets automatically initialized when starting the mission, all by the ArmA2 Engine. This is scripting basics, I recommend to study the code of some other missions or an editor guide like Mr_Murray's one before going any further.

@TheHarvesteR: What is the better solution for this case, either this:

while{_skipspeed > 0} do{
sleep 0.5;
skipTime(_skipspeed/3600);
};

or this:

while{true} do{
       if(_skipspeed > 0) exitWith{};
sleep 0.5;
skipTime(_skipspeed/3600);
};

Btw thanks for teaching me how to script an endless loop, now I can rest in peace. ;)

Actually, if all you want is an endless loop, there's really no need to check for anything.

If I'm not mistaken, the _skipspeed variable should not change, so it will never be smaller than zero. The while condition was only set to check if _skipspeed was higher than zero precisely because of that, so the script will never stop iterating. That's why using while(true) will have the same effect.

So, in the end, your script should look like this:

while{true} do{
       sleep 0.5;
skipTime(_skipspeed/3600);
};

just an endless loop, that iterates every .5 seconds, and changes the time of day every so often.

Cheers

Edited by TheHarvesteR

Share this post


Link to post
Share on other sites

In case _skipspeed is zero, the while loop must not be entered.

To make it a bit more clear for you, look at this equivalent code:

if(_skipspeed > 0) then {
    while{true}  do{
    sleep 0.5;
    skipTime(_skipspeed/3600);
    };
};

The check whether the statement "true" is true or "_skipspeed > 0" is true is exactly the same. Your computer doesn't perform the one check faster than the other. The only advantage about this one is a bit better readability.

So the way I did initially is at least as good as your suggestion, since my variant even safes one check.

Share this post


Link to post
Share on other sites

Ahh OK, I didn't think _skipspeed could be zero, then your first suggestion would be the best.

I thought you were using the check just to keep an inifinite loop going, but if the check is really checking against a possibility, then it's the best approach.

Cheers

Share this post


Link to post
Share on other sites
In case _skipspeed is zero, the while loop must not be entered.

To make it a bit more clear for you, look at this equivalent code:

if(_skipspeed > 0) then {
    while{true}  do{
    sleep 0.5;
    skipTime(_skipspeed/3600);
    };
};

The check whether the statement "true" is true or "_skipspeed > 0" is true is exactly the same. Your computer doesn't perform the one check faster than the other. The only advantage about this one is a bit better readability.

So the way I did initially is at least as good as your suggestion, since my variant even safes one check.

Sorry this topic is extremely old, but anyways doesn't the skipspeed need to be equal to or greater than 0??? That way if it is zero, then it must actually be =>

BTW, I forgot how to initialize this in the game... mind showing me how once more?

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  

×