Jump to content
Crazy_Man

Progress bar for capturing a zone in a multipalyer mission. Problem with remoteExec.

Recommended Posts

Hello, i have a problem in inserting my progress bar in my code made for capturing a zone.

 

The problem is that only players inside the list of the trigger need to see the progress bar and for that i used the remoteExec command.

 

But when testing on server the code crash. But it works fine in the editor.

 

I have put some //// where commands from the progress bar are.

 

The variable barLayer = [1,2,3,4];

 

I have this :


private ["_sideunits", "_sidegroup", "_trgCapture", "_trgBlock", "_sideBlock"];

_done = false;
_resMarker = _this select 4;
_posMarker = getPos (_this select 5);
_tower = _this select 5;
_resGroup = _this select 6;
_attackMarker = _this select 7;
_towerStatus = _tower getVariable "side";

////////////////////////////////
_layer = barLayer select 0;
barLayer = barLayer - [_layer];
///////////////////////////////


if (_this select 0 == east) then {

	_sideunits = side_east;
	_sidegroup = east;
	_sideBlock = independent;
	_trgBlock = _this select 1;
	_trgCapture = _this select 2;
};

if (_this select 0 == independent) then {

	_sideunits = side_independent;
	_sidegroup = independent;
	_sideBlock = east;
	_trgBlock = _this select 2;
	_trgCapture = _this select 1;
};

if (_tower getVariable "side" == _sidegroup) exitWith {};

disableSerialization; ////

_timer = [_trgCapture, _trgBlock, _layer] spawn {
	private "_txt";
	_trg = _this select 0;
	_trgB = _this select 1;
	_layer = _this select 2; ////
	_cp = time_capture;

	///////////////////////////////////////////////////////////////////
	[_layer,["myProgressBar","PLAIN"]] remoteExec ["cutRsc", list _trg];
	waitUntil {!isNull (uiNameSPace getVariable "myProgressBar")};
	_display = uiNameSpace getVariable "myProgressBar";
	_bar = _display displayCtrl 2;
	_cpBar = 0;
	_barTime = 1/time_capture;
	///////////////////////////////////////////////////////////////////

	while {_cp > 1} do {

		if (!triggerActivated _trgB) then {
			_txt = format ["Captured in %1 sec", _cp];
			_cp = _cp - 1;

			////
			_cpBar = _cpBar + _barTime;
			_bar progressSetPosition _cpBar;
			////

		} else {
			_txt = format ["Captured in %1 sec\n\nBLOCKED !", _cp];
			[["ATTACKED !", "PLAIN DOWN"]] remoteExec ["cutText", list _trgB];
		};

		[[_txt, "PLAIN DOWN"]] remoteExec ["cutText", list _trg];
		sleep 1;

	};

	[_layer,["default","PLAIN"]] remoteExec ["cutRsc", list _trg]; ////
	barLayer pushBack _layer;

};

	if (_tower getVariable "side" == _sideBlock) then {
		deleteMarker _resMarker;
		_attackMarker setMarkerAlpha 1;
		[_sideblock, _tower] call msg_attack;
	};

while {triggerActivated _trgCapture and !_done} do {

	if (scriptDone _timer and !triggerActivated _trgBlock) then {

		_tower setvariable ["side", _sidegroup];
		[] spawn fn_spawnMission;
		[_sidegroup, _towerStatus] call countCapture;
		[_sideunits, _sidegroup] execVM (_this select 3);
		[_sidegroup, _tower, _sideunits] execVM "ai\ai_upgrade.sqf";


		_done = true;
	};
};

if (!triggerActivated _trgCapture) then {

	/////////////////////////////////
	_layer cutRsc ["default","PLAIN"];
	barLayer pushBack _layer;
	////////////////////////////////
	*/
	terminate _timer;


	if (_tower getVariable "side" == _sideBlock) then {
		createMarker [_resMarker, _posMarker];
		_resMarker setMarkerShape "ICON";
		_resMarker setMarkerType "hd_dot";
		_resMarker setMarkerAlpha 0;
		_attackMarker setMarkerAlpha 0;
	};
};

 

Share this post


Link to post
Share on other sites

I remember reading somewhere that controls and displays can't be passed over the network. Maybe that's the issue? Also you might be better off putting everything in a function and remoteExec the function for players within the area.

  • Like 2

Share this post


Link to post
Share on other sites
10 minutes ago, Mr H. said:

I remember reading somewhere that controls and displays can't be passed over the network. Maybe that's the issue? Also you might be better off putting everything in a function and remoteExec the function for players within the area.

i think your right on that. have a function on each client and just remoteExec the function to the players in the trigger

Share this post


Link to post
Share on other sites

Correct. If you check your RPT, you'll see the error warning message. Can't remember what it is says though.

Share this post


Link to post
Share on other sites

About displays (general): There is no reason to remoteExec display and control layers (frames,buttons,data fields...). Your screen displays that locally. You just need to:

- create the display locally (for each player, in init.sqf or initPlayerLocal.sqf)

- share the public variables which are the core of this display (score, messages, shared data...)

 

Anyway for a hint or a cutText, this kind of display can be remoteExec.

 

Where did you define your time_capture? This data should be public. If not > zero divisor or undefined variable.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

time_capture is defined in initServer.sqf and the value by default is 60 and cannot be 0.

 

This script is sets off with a trigger (make global true) created in initServer.sqf.

 

initServer.sqf:

time_capture = 60;

trgtower1INDEP = createTrigger ["EmptyDetector", getPos tower1, true];
trgtower1INDEP setTriggerArea [10, 10, 0, true, 25];
trgtower1INDEP setTriggerActivation ["GUER", "PRESENT", true];
trgtower1INDEP setTriggerStatements ["this", "[independent,trgtower1INDEP,trgtower1EAST,'locations\tower1.sqf', 'respawn_easttower1', tower1, 'grouptower1build', 'tower1_attack'] execVM 'capture.sqf'", ""];

trgtower1EAST = createTrigger ["EmptyDetector", getPos tower1, true];
trgtower1EAST setTriggerArea [10, 10, 0, true, 25];
trgtower1EAST setTriggerActivation ["EAST", "PRESENT", true];
trgtower1EAST setTriggerStatements ["this", "nul = [east,trgtower1INDEP,trgtower1EAST,'locations\tower1.sqf', 'respawn_guerillatower1', tower1, 'grouptower1build', 'tower1_attack'] execVM 'capture.sqf'", ""];

 

 

Thanks for your responses! I will try with a function and remoteExec that function and use global variables for the core of the display.

 

But the problems is if an ennemy player enter the area the function need to freeze ans the display too.

 

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites
Quote

But the problems is if an ennemy player enter the area the function need to freeze ans the display too.


One possible solution: Store the progress in a variable attached to the trigger and make the function fetch it, handle the  progress value on the server only then and broadcast it to the other machines.

  • Like 1

Share this post


Link to post
Share on other sites

I followed your idea Mr H. and i have this:

_timer = [_trgCapture, _trgBlock, _tower] spawn {
	private "_txt";
	_trg = _this select 0;
	_trgB = _this select 1;
	_tower = _this select 2;
	_cp = time_capture;
	_list = []; /////
	_barTime = 1/time_capture; /////
	_cpBar = 0; /////

	while {_cp > 1} do {

		if (!triggerActivated _trgB) then {
			_txt = format ["Captured in %1 sec", _cp];

			/////////////////////////
			_unitBar = list _trg select (count list _trg - 1);
			[[_trg, _trgB, _cp, _tower],fn_progressBar] remoteExec ["spawn", (list _trg) - _list];
			_list pushBackUnique _unitBar;

			_trg setVariable ["progressBar", _cpBar, true];
			_cpBar = _cpbar + _barTime;
			/////////////////////////

			_cp = _cp - 1;

		} else {
			_txt = format ["Captured in %1 sec\n\nBLOCKED !", _cp];
			[["ATTACKED !", "PLAIN DOWN"]] remoteExec ["cutText", list _trgB];
		};

		[[_txt, "PLAIN DOWN"]] remoteExec ["cutText", list _trg];
		sleep 1;

	};
};

 

And in my function fn_progressBar i have this:

fn_progressBar = {

	_trg = _this select 0;
	_trgB = _this select 1;
	_cp = _this select 2;
	_tower = _this select 3;

	1 cutRsc ["myProgressBar","PLAIN"];
	waitUntil {!isNull (uiNameSPace getVariable "myProgressBar")};
	_display = uiNameSpace getVariable "myProgressBar";
	_bar = _display displayCtrl 2;

	while {_cp > 1} do {

		if (!triggerActivated _trgB) then {

			_bar progressSetPosition (_trg getVariable "progressBar");
			_cp = _cp - 1;

		};

		sleep 1;
		if (player distance getPos _tower > 10) exitWith {};
	};
	hint "DEFAULT";
	1 cutRsc ["default","PLAIN"];
};

 

Work fine in the editor but on the server the:

if (!triggerActivated _trgB) then {

	_bar progressSetPosition (_trg getVariable "progressBar");
	_cp = _cp - 1;
    
};

seems to doesn't works.

 

I put some hints everywhere in the function fn_progressBar and in that section the hint doesn't happens. I really don't understand why :dontgetit:....

 

And so the progress bar doesn't fill.

Share this post


Link to post
Share on other sites

Ok i got it!

 

The triggerActivated command is the problem. I tricked with a variable attached to the trigger. 

 

Now my script works perfectly, thank you all for your help!

  • Like 1
  • Thanks 1

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

×