Jump to content

Recommended Posts

Hi,

 

I have a MP PvP system where I display a Timer at the top left of the screen.

 

Problem : When the mission ends, and outro is launched, Timer is not at 00:00:00 for everyone. some are 15s early, some are late etc ... all players are not synced !

 

Here is how it works :

 

 

What it looks like ingame (Video example) :

 

Spoiler

 

 

When the players exits the Weapon Menu :

Null = [] execVM "timer.sqf";

 

Timer script be like : 

 

Spoiler

// Created By Flash-Ranger - flashrangerarma3@gmail.com (Please respect the time I spent on this system)
// Please do not modify anything in this script without knowing what you are doing.

CutRsc["CTF_HUD", "PLAIN"];

DisableSerialization;

_n = 0;

If (TypeOf Player == "B_Soldier_lite_F") Then
	{
	((UiNamespace GetVariable "CTF_HUD") DisplayCtrl 999) CtrlSetBackgroundColor [0,0,0,0.6];
	((UiNamespace GetVariable "CTF_HUD") DisplayCtrl 9999) CtrlSetBackgroundColor [0,0,0,0.6];
	While {_n < TimeP} Do
		{
		_T = TimeP-Time;
		_h = Floor (_T/3600);
		_min = Floor((_T/3600 - Floor (_T/3600))*60);
		_s = Floor((((_T/3600 - Floor (_T/3600))*60) - Floor((_T/3600 - Floor (_T/3600))*60))*60);

		_h_Text = "";
		_min_Text = "";
		_s_Text = "";

		If (_h < 10) Then {_h_Text = "0"+Str(_h);} Else {_h_Text = Str(_h);};
		If (_min < 10) Then {_min_Text = "0"+Str(_min);} Else {_min_Text = Str(_min);};
		If (_s < 10) Then {_s_Text = "0"+Str(_s);} Else {_s_Text = Str(_s);};

		If (_h < 0) Then {_h_Text = "00"; _min_Text = "00"; _s_Text = "00";};

		((UiNamespace GetVariable "CTF_HUD") DisplayCtrl 9999) CtrlSetText (Format ["Time : %1:%2:%3",_h_Text,_min_Text,_s_Text]);
		Sleep 1;
		_n = _n + 1;
		};
}
Else
{
If (TypeOf Player == "O_Soldier_lite_F") Then
		{
		((UiNamespace GetVariable "CTF_HUD") DisplayCtrl 999) CtrlSetBackgroundColor [0,0,0,0.6];
		((UiNamespace GetVariable "CTF_HUD") DisplayCtrl 9999) CtrlSetBackgroundColor [0,0,0,0.6];
		};
	While {_n < TimeP} Do
		{
		_T = TimeP-Time;
		_h = Floor (_T/3600);
		_min = Floor((_T/3600 - Floor (_T/3600))*60);
		_s = Floor((((_T/3600 - Floor (_T/3600))*60) - Floor((_T/3600 - Floor (_T/3600))*60))*60);

		_h_Text = "";
		_min_Text = "";
		_s_Text = "";
		If (_h < 10) Then {_h_Text = "0"+Str(_h);} Else {_h_Text = Str(_h);};
		If (_min < 10) Then {_min_Text = "0"+Str(_min);} Else {_min_Text = Str(_min);};
		If (_s < 10) Then {_s_Text = "0"+Str(_s);} Else {_s_Text = Str(_s);};

		If (_h < 0) Then {_h_Text = "00"; _min_Text = "00"; _s_Text = "00";};

		((UiNamespace GetVariable "CTF_HUD") DisplayCtrl 9999) CtrlSetText (Format ["Time : %1:%2:%3",_h_Text,_min_Text,_s_Text]);
		Sleep 1;
		_n = _n + 1;
		};
};

 

 

description.ext

 

Spoiler

	class CTF_HUD
	{
		idd = 1000;
		fadeout=0;
		fadein=1;
		duration = 1e+1000;
		name = "CTF_HUD";
		onLoad = "UiNamespace SetVariable ['CTF_HUD', _This Select 0]";

		class controlsBackground
		{

			class CTF_HUD_Label : RscText
			{
				idc = 9999;
				text = "";
				x = safezoneX;
				y = safezoneY;
				w = 0.250;
				h = 0.040;
				colorBackground[] = {0, 0, 0, 0.6};
				colorText[] = {1.0, 1.0, 1.0, 1};
				sizeEx = 0.031;
				style = ST_CENTER;
			};

		};
	};

 

 

in my Mission, outro.sqf is activated by a trigger :

 

Spoiler

condition="(TimeP<10000 and ((time >= TimeP) or (TimeEnd >= TimeP))) or (ScoreP<10000 and ((WScore>=ScoreP) or (EScore>=ScoreP)))";
onActivation="TimeEnd=time; publicVariable ""TimeEnd""; Null = [] execVM ""Outro.sqf""";

 

NB : TimeP and ScoreP are two var from my init file :


TimeP = (paramsArray select 0) + 60;
ScoreP = (paramsArray select 1);

 

 

 

Many thanks for all the help I can get !

Best regards.

Share this post


Link to post
Share on other sites

I made some research and it appears that a simple 
 

estimatedTimeLeft TimeP;

would solve my problem ... Can someone confirm ? 

Share this post


Link to post
Share on other sites

If you'd use CBA you could use cba_missionTime and synch it to that. cba_missionTime is the same for everyone.

Share this post


Link to post
Share on other sites

I want no mods sorry.

But maybe I could Unpack CBA mod to see how they did it in their modules.

Share this post


Link to post
Share on other sites

The problem I currently see is that you are using sleep.

This in an scheduled environment, sleep 1 doesn't mean you wait 1 second. more like you wait 1 second +  the time the scheduler is occupied.

 

And if you don't use any mods, I would recommend an onEachFrame Eventhandler. Or take use in something like Diag_tickTime or Servertime,(not time)

 

But if you use estimatedEndServerTime and estimatedTimeLeft  you just have to add an cutRsc (I hope I dont mix these up) and you are good to go.

  • Like 1

Share this post


Link to post
Share on other sites

Right, I'll look into this and post an update soon ;)

 

Thanks Crewt.

Share this post


Link to post
Share on other sites

 

On 2017-5-19 at 10:47 AM, Flash-Ranger said:

Right, I'll look into this and post an update soon ;)

 

Thanks Crewt.

 

Did you get this working Flash-Ranger? I would like to incorporate into a larger mission if i can manage it ..

 

Thanks

Gav

Share this post


Link to post
Share on other sites
16 hours ago, gavc said:

 

 

Did you get this working Flash-Ranger? I would like to incorporate into a larger mission if i can manage it ..

 

Thanks

Gav

 

Hi, 

 

I do not have much time right now as I am in my last phase of my Studies.

 

If you want to integrate my scripts into something please do mention my name somewhere. I do not spend hours just so anybody can copy ;)

Please feel free to send me a mail if you want more information : flashrangerarma3@gmail.com

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

×