Jump to content

[no TuT] Sync Restart Timer with Real Time


Guest

Recommended Posts

If you got a custom debug Monitor paste this on the very very top, before anything else:

 

fnc_split_time = {
    private ["_hour","_minute","_minute_new","_companion"];
    _hour = _this select 3;
    _minute = _this select 4;
    _companion = player getVariable["TimeCompanion",0];
    
    //Get nearest and set the companion

    switch (_hour) do {
        case 0: {
            _minute_new = _minute;
            _companion = player setVariable["TimeCompanion",_minute_new];
        };
        case 1: {
            _minute_new = (60 - _minute);
            _companion = player setVariable["TimeCompanion",_minute_new];
        };
        case 2: {
            _minute_new = (120 - _minute);
            _companion = player setVariable["TimeCompanion",_minute_new];
        };
        case 3: {
            _minute_new = (180 - _minute);
            _companion = player setVariable["TimeCompanion",_minute_new];
        };
        case 4: {
            _minute_new = _minute;
            _companion = player setVariable["TimeCompanion",_minute_new];
        };
        case 5: {
            _minute_new = (60 - _minute);
            _companion = player setVariable["TimeCompanion",_minute_new];
        };
        case 6: {
            _minute_new = (120 - _minute);
            _companion = player setVariable["TimeCompanion",_minute_new];
        };
        case 7: {
            _minute_new = (180 - _minute);
            _companion = player setVariable["TimeCompanion",_minute_new];
        };
        case 8: {
            _minute_new = _minute;
            _companion = player setVariable["TimeCompanion",_minute_new];
        };
        case 9: {
            _minute_new = (60 - _minute);
            _companion = player setVariable["TimeCompanion",_minute_new];
        };
        case 10: {
            _minute_new = (120 - _minute);
            _companion = player setVariable["TimeCompanion",_minute_new];
        };
        case 11: {
            _minute_new = (180 - _minute);
            _companion = player setVariable["TimeCompanion",_minute_new];
        };
    };
    
    
}; "PVDZE_plr_SetDate" addPublicVariableEventHandler {(_this select 1) call fnc_split_time;};

It simply get's the Hour and Minutes and subtracts them from the Restart Times. In example: If we have 1:30 pm and your server restarts every 4 hours, this will get current server time, after it's synchronised and subtract 90 Minutes from your restart timer. So whenever you do a manual restart, you won't have to bother about the restart timer, as it will allways be correct. Kinda somehow whatever...

Well to add this in your debug Monitor, first you get the Variable

_companion = player getVariable["TimeCompanion",0];

And then you edit your Restart timer (my restart timer works in minutes), so it will look like this:

((_companion)-(round(serverTime/60)))

You should not have to put PVDZE_plr_SetDate in your publicvariable.txt, unless you got a custom one. This should allways be in there anyway, as this is used by other functions.

 

 

Any more questions?

PS: Yes i know this is probably not the best solution, but it was the only thing i could think if in a short time.. Thought someone might need it / want it.. 

Link to comment
Share on other sites

Sorry, smal logic issue. It should look somewhat like this:

 

case 0: {
			_minute_new = (180 - _minute);
			_companion = player setVariable["TimeCompanion",_minute_new];
		};
		case 1: {
			_minute_new = (120 - _minute);
			_companion = player setVariable["TimeCompanion",_minute_new];
		};
		case 2: {
			_minute_new = (60 - _minute);
			_companion = player setVariable["TimeCompanion",_minute_new];
		};
		case 3: {
			_minute_new = _minute;
			_companion = player setVariable["TimeCompanion",_minute_new];
		};
		case 4: {
			_minute_new = (180 - _minute);
			_companion = player setVariable["TimeCompanion",_minute_new];
		};
Link to comment
Share on other sites

just fyi, when playing with time in arma you will always end up with client that is a few minutes off in one or the other direction cause by time not syncing right, i tried something simmular aswell but gave up after realizing time is always diffrent for each client.

 

servertime however (obviusly) always returns the same for each client ...

Link to comment
Share on other sites

just fyi, when playing with time in arma you will always end up with client that is a few minutes off in one or the other direction cause by time not syncing right, i tried something simmular aswell but gave up after realizing time is always diffrent for each client.

 

servertime however (obviusly) always returns the same for each client ...

 

Why is why this function's main functionality is just to "calculate", and then it passes the (synchronized) time to the client, which then uses that variable to calculate time to restart. However, this can be a little bit off, as the variable is first set first after a player logs in. After that the variable is the same for every single Player. So due to that, if you want it 100% accurate, just add 2 or 3 Minutes. And if you're aware, that a player might only log in like 30 minutes after restart that's not problem, because the time and with the time that function get's synced at the player setup, therefore it makes no difference, whenever you log in. Also note, that there is a simple work around for that smal delay, as the time get's synchronized every time somebody logs in, you could compare 2 variables and subtract them... Well i guess this is pretty much more accurate, then anything else.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...