Jump to content
Sign in to follow this  
snkman

1 Hour realtime = 24 Hour's ingame?

Recommended Posts

Hi guy's,

well someone know's how to do that?

If you play 1 hour ArmA it should be night and day ( 1 hour Realtime = 24 hour's in ArmA )

For MP and synchronously for all client's.

Share this post


Link to post
Share on other sites

just run a script on all clients that skips time at the the appropriate rate (assuming skipTime still has a local effect).

Share this post


Link to post
Share on other sites

skiptime is local, the trick is to synchronise the times with the server, if you dont i can assure you that as time passes, clients and server will become more and more out ofm sync

obviously sync'ing every skiptime is too much, so i would reduce this to once every 5 minutes or some such delay

Share this post


Link to post
Share on other sites

Can you Guy's please maybe give me some code's how to do that? smile_o.gif

Share this post


Link to post
Share on other sites

I think by now there are numerous time scripts out there which run in MP. At least I am using mine for years now. The principle is very simple.

1. On the server (and only there!wink_o.gif you run a time keeper script that updates a global variable every 5 min.

2. On each client you run a watch script that checks whether the global variable has changed and if so runs a skiptime command on the client.

Commands used:

publicVariable (global effect)

skiptime (local effect)

Cheers,

Victor

Share this post


Link to post
Share on other sites
I think by now there are numerous time scripts out there which run in MP...

You'd be surprised. In OFP I was never given a solution (or one that I could get working) on how to do this. I could use this in sooo many missions. I would have most of my missions using 1hr RT=24hr game time. It gives the impression of being in a prolonged conflict zone.

Share this post


Link to post
Share on other sites

I managed to do it, but the only problem was people JIP they would start with the time that everyone started at, at the start of the mission and they had daylight while everyone was nighttime and it just screwed things up lol.

Share this post


Link to post
Share on other sites
skiptime is local, the trick is to synchronise the times with the server, if you dont i can assure you that as time passes, clients and server will become more and more out ofm sync

obviously sync'ing every skiptime is too much, so i would reduce this to once every 5 minutes or some such delay

Is that why when I die on a coop mission, then disconnect from the server, join again in a different slot its daytime for me. But still night for my other teammates?

Share this post


Link to post
Share on other sites
skiptime is local, the trick is to synchronise the times with the server, if you dont i can assure you that as time passes, clients and server will become more and more out ofm sync

obviously sync'ing every skiptime is too much, so i would reduce this to once every 5 minutes or some such delay

Is this proven? I have the idea that I played at night time and another guy at day time and it didn't make *ANY* difference and was NOT causing any desyncs etc. But I could be wrong?

JIP Compatible, Time, Fog & Overcast Sync:

This will Sync time and weather with server every 240 seconds, and IF there is change in the weather, there will be a 30 second transition-time.

- Place a Gamelogic on the map and name it: server

- Make/add to end of init.sqf:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[240, 30] spawn compile preProcessFile "Sync.sqf";

- Make Sync.sqf: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// Sync Time & Weather - by Sickboy (sb_at_6thSense.eu)

private ["_transtime","_synctime"];

_synctime = _this select 0; // Every xx Seconds server will broadcast to sync Time & Weather

_transtime = _this select 1; // Seconds needed per Weather Transition (From Current Weather to New Weather (if any))

if(isnil "var_syncset")then{var_syncset=false;};if(isnil "var_currtime")then{var_currtime=0;};

if(isnil "var_currfog")then{var_currfog=0;};if(isnil "var_curroc")then{var_curroc=0;};

// Initialize Server/Client Engines

if(local server)then{[_synctime] spawn compile preProcessFile "Sync_srv.sqf";} else {[_transtime] spawn compile preProcessFile "Sync_cl.sqf";};

- Make Sync_srv.sqf:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// Sync Time & Weather - by Sickboy (sb_at_6thSense.eu)

private ["_synctime"];

_synctime=_this select 0;

scr_sync={var_currtime=daytime;publicVariable "var_currtime";var_currfog=fog;publicVariable "var_currfog";var_curroc=overcast;publicVariable "var_curroc";var_syncset=true;publicVariable "var_syncset";};

// Join In Progress Publisher

onPlayerConnected "[] spawn scr_sync";

// Server Loop for publishing

waitUntil{sleep _synctime;[] spawn scr_sync; false};

- Make Sync_cl.sqf: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// Sync Time & Weather - by Sickboy (sb_at_6thSense.eu)

private ["_transtime"];

_transtime=_this select 0;

// Client Loop for Receiving from Server

waitUntil{waitUntil{var_syncset};var_syncset=false;skipTime (var_currtime - daytime + 24) % 24;_transtime setfog var_currfog;_transtime setOvercast var_curroc; false};

If you Want Speedup Time:

This should skiptime by 0.2 hour (14 minutes) every 30 seconds (1 hour real time = 24 hour game time)

- Add this to the init.sqf:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[30, 0.2] spawn compile preProcessFile "speedTime.sqf";

- Make speedTime.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// Speedup Time - by Sickboy (sb_at_6thSense.eu)

// (Every _sleep seconds, skiptime _skip.)

private ["_sleep","_skip"];

_sleep = _this select 0; // Sleep in seconds to skip time

_skip = _this select 1; // Amount of time skipped to accomodate your wishes

// Looping Timeskip on Server & Client

waitUntil {sleep _sleep;skipTime _skip; false};

If you Want Random Overcast & Fog:

- Add this to the init.sqf:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_scr"];

_scr=compile preProcessFile "dynWeather.sqf";

if(local server)then{["Overcast", 120, 0.1, 0.7, 0.08] spawn _scr;["Fog", 120, 0.05, 0.5, 0.05] spawn _scr;};

- make dynWeather.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// Simple Dynamic Weather - by Sickboy (sb_at_6thSense.eu)

// (Every _sleep seconds, set up to max or down to min.)

private ["_c","_i","_sleep","_min","_max","_steps"];

_type = _this select 0; // "Overcast" or "Fog"

_sleep = _this select 1; // Sleep until Change on server (Clients will receive the updated info through sync.sqf every _synctime)

_min = _this select 2; // Minimum

_max = _this select 3; // Maximum

_steps = _this select 4; // Step-size up and down

// Code to run

_c="waitUntil

   {

      _i=%1;

      while{_i<=_max}do{sleep _sleep;_i=_i+_steps;10 set%1 _i};

      while{_i>=_min}do{sleep _sleep;_i=_i-_steps;10 set%1 _i};

      false

   };";

// Execute Loop

call compile format[_c,_type];You can leave out all the 'Sync' scripts for Single Player if you wish smile_o.gif

Tested in v1.02, working fine (Didn't test the overcast/fog though)

Share this post


Link to post
Share on other sites

I am indeed surprised that there is still a need for these. So let me simply share my two scripts (client and server) here if it helps anybody.

Note 1: de-sync issues observed at a 1% rate, happens more when clients have sub-par connectivity. In that case a global variable updated by the server might not reach the client or -worse- be set to 0. As said, can happen but rarely.

Note 2: The map needs a EMPTY-GAME LOGIC called "server" on it (as for most other MP compatible missions as well).

Code for "Timeserver.sqs"

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

# Timeserver build 007

# Victor Farbau 2004

?!(local Server): exit

#update interval in minutes

_updateinterval = 6

#could be totally random, but these daytimes create the best atmosphere

_hours = [5,6,7,12,17,18,19,20]

_hourcount = (count _hours) - 1

globaltime = _hours select (random _hourcount)

#weatherloop

globalfog = random 0.5

globaloc = random 1

globaltwready = 1

sbcflag = sbcflag + 1

sbcmsg = 1

publicVariable "sbcflag"

publicVariable "sbcmsg"

publicVariable "globaltime"

publicVariable "globalfog"

publicVariable "globaloc"

publicVariable "globaltwready"

~(_updateinterval * 60)

goto "weatherloop"

Code for "Timeclient.sqs"

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

# Time and weather client build 009

# Victor Farbau 2005

#client

~5

?(globaltwready != 1): goto "client"

#waitfortime

~2

?((globaltime < 0) OR (globaltime > 24)): goto "waitfortime"

skiptime globaltime

#waitforfog

~2

?((globalfog < 0) OR (globalfog > 1)): goto "waitforfog"

15 setfog globalfog

#waitforovercast

~2

?((globaloc < 0) OR (globaloc > 1)): goto "waitforovercast"

15 setOvercast globaloc

_checksum = (globalfog + globaloc)

#waitforupdate

~15

?((globalfog + globaloc) == _checksum): goto "waitforupdate"

goto "waitforfog"

Regards,

Victor

Share this post


Link to post
Share on other sites
...

Hi there Victor, I am not really sure how your script is going to speed up time and synchronise it every xx Minutes? Aswell as that the server does not skiptime, unless you run the timeskipCLIENT also on the server smile_o.gif

In your example, the time will be skipped by either any of these amounts of hours: [5,6,7,12,17,18,19,20] (picked at the start of the script), and then skips this amount of time every 6 minutes (adjustable). I don't see any parts which synchronise the time or JIP considerations. Aswell as that this setup requires the time ALWAYS to be updated by the server, which means you cant make it update every few seconds, because then you would need the server to publicVariable every few seconds and you dont want that in Multiplayer smile_o.gif

The problem is that if you do long delays before skipping time,  the skiptime must be bigger, and because of this the daytime transactions will seem large (every 6 minutes the time would skip 2.4 hours (this could make a change from light into night ;D))

Share this post


Link to post
Share on other sites

That is correct sickboy, I didn't bother to change my script specifically to the needs. I thought the necessary changes might be obvious and easy to do. huh.gif

Don't get me wrong - I am just assuming a certain level of script understanding so I honestly thought this is obvious enough. I believe that's the best way to learn as well - study how other people solved problems and learn from modification.

I wasn't aware whether this was a request a la "here's what I need - gimme a script!". I am sure SNKMAN's knowledge will grow further if he manages to pull this off now  biggrin_o.gif

And to the script question of yours: yes the server does not execute the skiptime command. This would be pointless for a dedicated server and "skiptime" only has a local effect on each client. If you run a non-dedicated server then both scripts will run on your machine and the time will still be skipped. The odds and ends of local versus global effects in OFP/Arma are a fountain of joy, I can tell you  smile_o.gif

Greetz,

Victor

Share this post


Link to post
Share on other sites

i made a skiptime script for OFP,

i shall post it here, however whether it will run soundly in arma and how to modify it for JIP is another matter

But it will give you some idea of how the sync works and how to speed up/slow down during sunrise and sunset periods to give a smoother transiytion from day to night

There are 3 scripts

and ofcourse it uses a gamelogic called "server" so that you can identify which node is the server

(gamelogics being local only to the server machine)

therefore

?(local) server:

actually means,

is the gamelogic server local on this machine

I could have simply named the gamelogic "Dedi"

and used ?(local Dedi): to reach the same conclusion

Enough of the basics already!!

here's the code

updateclock.sqs

Quote[/b] ]?(local Server):exit

newTime = false

#start

@(newTime)

_serverTime = currentServerTime

_timeChange = _serverTime - daytime

skipTime _timeChange

newTime = false

goto "start"

updateclockserver.sqs

Quote[/b] ]?!(local Server):exit

newTime = false;PublicVariable "newTime"

~5

#start

~10

currentServerTime = daytime; PublicVariable "currentServerTime"

newTime = true; PublicVariable "newTime"

goto "start"

updateskiptimeserver.sqs

Quote[/b] ]

?!(Local Server):Exit

#start

<span style='color:red'>? (daytime >= 4.5) && (daytime < 7.5):_delay = 2.5;_skip = .05

? (daytime >= 7.5) && (daytime < 16.5):_delay = 30;_skip = 0.4

? (daytime >= 16.5) && (daytime < 20):_delay = 2.5;_skip = .05

? ((daytime >= 20) && (daytime < 24)) || ((daytime > 0) && (daytime < 4.5)):_delay = 20;_skip = 0.4</span>

~_delay

skipTime _skip

goto "start"

This code is ancient, I havent looked at it for over 3 years, its not very efficient and for arma requires a complete re-write and modification to sqf format, but will give you some idea of what is involved

NB the text in red allows for a smoother transition for sunrise sunset

Hope that helps

Share this post


Link to post
Share on other sites
Quote[/b] ]NB the text in red allows for a  smoother transition for sunrise sunset
That's nicely thought of! smile_o.gif
That is correct sickboy, I didn't bother to change my script specifically to the needs. I thought the necessary changes might be obvious and easy to do. huh.gif

Don't get me wrong - I am just assuming a certain level of script understanding so I honestly thought this is obvious enough. I believe that's the best way to learn as well - study how other people solved problems and learn from modification.

I wasn't aware whether this was a request a la "here's what I need - gimme a script!". I am sure SNKMAN's knowledge will grow further if he manages to pull this off now  biggrin_o.gif

And to the script question of yours: yes the server does not execute the skiptime command. This would be pointless for a dedicated server and "skiptime" only has a local effect on each client. If you run a non-dedicated server then both scripts will run on your machine and the time will still be skipped. The odds and ends of local versus global effects in OFP/Arma are a fountain of joy, I can tell you  smile_o.gif

Greetz,

Victor

I also assumed that, but it seems that some ppl simply need the scripts... as they can see what the script supposed to do and how that is related to scriting syntax smile_o.gif

I think it is important to have the time of the clients synced with the time of the server.....

1. If the clients do not have 1 universal source to sync from, then they can never be really synced smile_o.gif And How can a new joined player, know how far he needs to skip time?

2. All scripts that rely on daytime, being night, light, morning, afternoon etc. etc. will not work as they should on the server, if you do not update the time on the server...

Share this post


Link to post
Share on other sites

Sickboy,

but the clients are synchronized with the server. But through a global variable managed by the server and not actually the servers local time. Main point is that all clients have the same local time.

Answering:

1. The universal source in the quoted script is the "globaltime" variable managed by the server and distributed to all clients via the "globalVariable" function.

2. This shouldn't be a problem. Each time the script starts it checks whether "globaltime" has a valid value already and if so skips the amount of hours to reach the same time. When joining a game a client should typically get updated on all global variables and objects first thing.

Cheers,

Victor

Share this post


Link to post
Share on other sites
1. The universal source in the quoted script is the "globaltime" variable managed by the server and distributed to all clients via the "globalVariable" function.

2. This shouldn't be a problem. Each time the script starts it checks whether "globaltime" has a valid value already and if so skips the amount of hours to reach the same time. When joining a game a client should typically get updated on all global variables and objects first thing.

1. The globaltime variable is not a time variable at all, but an amount of hours that it should skip PER timeskip, there is no synchronising in this way, only the same amount of hours PER skip... which does not make all the clients always have the same time or near the same time smile_o.gif Especially since some clients join the game later....

2. As far as I know, the global variables are NOT broadcasted when new clients connect (JIP), hence that we need onPlayerConnected...

Share this post


Link to post
Share on other sites

Ok, if you need to be such a nitpick...

If you want it real easy:

1. create an HeliHempty object and call it "timerobject" somewhere on the map and let the server set its position to [0..24,0..60,0] according to the desired time 0..24:0..60

2. The position of map objects will be synchronized during connect and later on as well so each client can simply read the position of "timerobject" and set the local clock accordingly using skipTime

3. Repeat steps 1 and 2 as desired on servers and clients.

Bang boom global time is set; it's just not elegant to always use these workarounds instead of proper programming.

Cheers,

Victor

Share this post


Link to post
Share on other sites
Ok, if you need to be such a nitpick...

If you want it real easy:

1. create an HeliHempty object and call it "timerobject" somewhere on the map and let the server set its position to [0..24,0..60,0] according to the desired time 0..24:0..60

2. The position of map objects will be synchronized during connect and later on as well so each client can simply read the position of "timerobject" and set the local clock accordingly using skipTime

3. Repeat steps 1 and 2 as desired on servers and clients.

Bang boom global time is set; it's just not elegant to always use these workarounds instead of proper programming.

Cheers,

Victor

It has nothing to do with NitPicking, it has simply todo with keeping a good framework without creating inconsistencies that later on or in other situations create problems...

Nice about the position btw smile_o.gif Thanks for the tip smile_o.gif

Quote[/b] ]Bang boom global time is set; it's just not elegant to always use these workarounds instead of proper programming.
Sure it isn't ... But ur programming code was lacking certain aspects... But anyway, "Nitpicking" anyways, right?.. smile_o.gif

Share this post


Link to post
Share on other sites

Hey Guy's,

thank's alot for the help.

Well i choosed sickboy's script and it work's really well! thumbs-up.gif

@sickboy

Just one question to your Script: Does it change weather too? Or is it only to Sync the Weather?

In the script i saw "var_currfog" what does it do?

Share this post


Link to post
Share on other sites

Sickboy, ah well, I just found it nitpicking to elaborate on the function of skipTime and its usage to skip time instead of setting it. I know darn well since I programmed and tested that stuff myself. But that's all right with me, it's the sum of all aspects and concerns that usually creates the solution so keep on nitpicking smile_o.gif

Anyway, for most MP script parts I started to use map objects as well now; I am just slowly getting tired of trying all the proper ways that often won't work for any apparent reason.

So the HeliHEmpty object has become the single most useful component in my ArmA programming these days smile_o.gif By setting the position you can basically transfer 3 variables at the same time in a way that works almost 100% in MP. SP missions are much more simple and usually quickly done - only to fail miserably when it comes to playing them on a server.

Regards,

Victor

Share this post


Link to post
Share on other sites
@sickboy

Just one question to your Script: Does it change weather too? Or is it only to Sync the Weather?

In the script i saw "var_currfog" what does it do?

Nice to hear that it works m8 smile_o.gif You might want to incorporate some of the ideas by Terox which include skipping time more slowly around the crucial day-change times like in the morning and afternoon.

The weather is not automaticly changed. It is merely synced.

var_currfog saves the fog setting of the server and gets broadcasted for the clients to read back and put as their fog setting, it's only there for the purpose of syncing the fog, it should remain untouched by other scripts smile_o.gif

I updated my Post with Random Overcast/Fog and split the time part out into seperate script.

http://www.flashpoint1985.com/cgi-bin....1012084

Share this post


Link to post
Share on other sites

GREATE! biggrin_o.gif Thank's a lot pal. thumbs-up.gif

Share this post


Link to post
Share on other sites
GREATE!  biggrin_o.gif  Thank's a lot pal.  thumbs-up.gif

It was updated oncemore... Better configuration options and setup, if you ask me smile_o.gif

I will release these scripts in some scripting package sometime, together with some other handy stuff smile_o.gif

Share this post


Link to post
Share on other sites
Guest

hey guys, mind if I ask a question regarding all of this accel time function -

I have a script written by CSL, that does pretty much the same thing, its just simplified for single player use, although even at most optimum settings, it still lags a little due to clouds being pushed thru frames each skip time incriment, is there any way to disable the clouds from being affected by an accel time script? It doesent appear there is, thought id ask as it looks like you guys got a pretty solid angle on this script app wink_o.gif

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  

×