Jump to content
soldier9945

BIS_fnc_showMissionStatus shows wrong countdown time (at server start?)

Recommended Posts

Apparently I have not managed to implement the BIS_fnc_showMissionStatus properly.

 

It works fine on a Dedicated server, the end script ends the mission on the right time. But I can't seem to find out how to show the right time to the players.

 

It displays too much time on the client, but only if I join the Dedicated server. If I launch the mission from the editor it works, at least for me, with the right time showing.

 

 

Original BIS_FNC_countdown

/*

    Author: Karel Moricky



    Description:

    Trigger countdown



    Parameter(s):

        0: NUMBER - countdown in seconds

        1: BOOL - true to set the value globally



    Returns:

    NUMBER

*/



private ["_countdown","_isGlobal"];

_countdown = [_this,0,0,[0,true]] call bis_fnc_param;

_isGlobal = [_this,1,true,[true]] call bis_fnc_param;



switch (typename _countdown) do {

    case (typename 0): {

        private ["_servertime"];

        _servertime = if (ismultiplayer) then {servertime} else {time};

        switch true do {

            case (_countdown < 0): {

                missionnamespace setvariable ["bis_fnc_countdown_time",nil];

                if (_isGlobal) then {publicvariable "bis_fnc_countdown_time";};

                -1

            };

            case (_countdown == 0): {

                private ["_time"];

                _time = missionnamespace getvariable "bis_fnc_countdown_time";

                if (isnil "_time") then {

                    -1

                } else {

                    (_time - _servertime) max 0

                };

            };

            case (_countdown > 0): {

                private ["_time"];

                _time = _servertime + _countdown;

                missionnamespace setvariable ["bis_fnc_countdown_time",_time];

                if (_isGlobal) then {publicvariable "bis_fnc_countdown_time";};

                _time

            };

            default {

                -1

            };

        };

    };

    case (typename true): {

        ([] call bis_fnc_countdown) > 0

    };

    default {

        -1

    };

};

I have used in the initServer.sqf file (I expect the second parameter to set the mission time as a public variable for clients to get the right time when they initialize):

// Mission End
[600, true] call BIS_fnc_countdown; //start mission Countdown

It seems to work fine on the server as stated, my End.sqf script ends the mission on the right time, 10mins after beginning.

 

Problem is, when I want to show the player this timeout through initPlayerLocal.sqf:

// Show Tickets Status
[] call BIS_fnc_showMissionStatus; 

It shows numbers over the 1000's, as if the client interprets the server time wrong.

 

I've checked after letting the Dedicated server was running for some time... and it strangely worked...

 

EDIT: can reproduce this. Restarting server and connecting in about a minute shows the wrong countdown number. Waiting approx. 10min shows the right number. How do I fix that?

Share this post


Link to post
Share on other sites

The script uses serverTime which is unreliable for the first 5 minutes after a server start. Until the server time gets synced its value is huge.

Make a simple mission with a playable unit. In the description.ext enable the debug console with enableDebugConsole = 2.

Start up your dedicated server, log in as admin and start the mission.

Run this from the debug console using 'Server Exec'.

h = [] spawn {
	
	[600, true] call BIS_fnc_countdown;
	[] remoteExec [ "BIS_fnc_showMissionStatus", 0 ];
	
	while { true } do {
		[ [ serverTime, time ], {
			hint format[ "Client ST : %1\nServer ST : %2\n\nClient T : %3\nServer T : %4", serverTime, param[ 0 ], time, param[ 1 ] ];
		} ] remoteExec [ "BIS_fnc_spawn", 0 ];
		sleep 1;
	};
};
Notice how serverTime on the client is correct but the servers serverTime is something like 1.3335435e+006 a rather large number.

Waituntil the client ST gets to >300. Notice how server ST suddenly syncs to the correct time.

Leave the server running but disconnect from it and rejoin. Start the same mission and redo the code in the console.

Notice how both times are correct and in sync.

Either lock your server for the first 5mins and do not start any missions.

OR

Do not apply any count downs until time > 300,

OR

create your own countdown timer that does not rely on serverTime and fills in the variable "bis_fnc_countdown_time" so you can still use the BIS_fnc_showMissionStatus.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks again!

 

The script uses serverTime which is unreliable for the first 5 minutes after a server start. Until the server time gets synced its value is huge.

 

Does that mean it's a bug to be fixed? What synchronizes the server? A module? Do you know why it does wait 5mins before syncing?

 

Thanks for the suggestions! I'll try to find another countdown script.

Share this post


Link to post
Share on other sites

Does that mean it's a bug to be fixed? What synchronizes the server? A module? Do you know why it does wait 5mins before syncing?

Don't think its a bug, it has been documented on the wiki as such for a long time.

As to why it behaves like this I have no idea, I'm just familiar with its behaviour as its something I had to work around for a project I was helping on a month or so ago.

Share this post


Link to post
Share on other sites
Guest

A workaround will be to have a local Countdown function that you run on the client simultanously. (Using time and not servertime).

I'm wondering if time return a proper value server side. Then you just have to run the countdown server side and broadcast the current number.

Share this post


Link to post
Share on other sites

On re reading the script you have have shown there is nothing stopping you running the current script client side.
Instead of the server starting the countdown at mission load you could have the first player to join start it.
Something like....
initPlayerLocal.sqf

if ( isNil "bis_fnc_countdown_time" ) then {
	[ 600, true ] call BIS_fnc_countdown;
};

So if it has not already been set (publicVariables are initialised before initPlayer) run the function which PVs it.
OR
initPlayerServer.sqf

params[ "_player" ];
if ( isNil "bis_fnc_countdown_time" ) then {
	[ 600, true ] remoteExec [ "BIS_fnc_countdown", _player ];
};
  • Like 1

Share this post


Link to post
Share on other sites

Still having the problem when loading it with the first player connecting... but only on a dedicated server. Hosted local server doesn't have this error.

 

I will try to make my own counter as suggested:

 

[...]

create your own countdown timer that does not rely on serverTime and fills in the variable "bis_fnc_countdown_time" so you can still use the BIS_fnc_showMissionStatus.

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

×