Jump to content
Sign in to follow this  
Rellikplug

Filter specific items, by side, from an array

Recommended Posts

I am trying to check for nearestEntities and determine if any of the returned array are a given side. I am struggling with the condition for the BIS_fnc_conditionSelect function. At least I think that is the only issue ;)

it appears the nearestEntities command retursn the player in the array so I try to remove it using BIS_fnc_conditionSelect then use countSide to check the alters nearestEntities array for, and retturn, only items of a given side.

I have tried this several different ways and have re-written this many times; I think I am close now but, I can't afford to pull any more hair out :butbut:

private ["_target","_caller","_ID","_nearPlayer","_nearPlayerWEST","_nearPlayerEAST","_nearPlayerRESISTANCE"];

_target 	= _this select 0;
_caller 	= _this select 1;
_ID			= _this select 2;

if (!captive _caller) exitWith {hint "You are Already Free"};

_nearPlayer = (position _caller) nearEntities ["Man", 25]; //check for other units within 25 m
_lessPlayer = [_nearPlayer], {side == WEST}] call BIS_fnc_conditionalSelect; //find the player unit in the _nearPlayer array
_nearPlayerLessPlayer = _nearPlayer - _lessPlayer; //remove the player unit from the _nearPlayer array

_nearPlayerWEST = WEST countSide _nearPlayer;
_nearPlayerEAST = EAST countSide _nearPlayer;
_nearPlayerRESISTANCE = RESISTANCE countSide _nearPlayer;

if (side _caller == WEST) then {
if (count _nearPlayerEAST > 0 || count _nearPlayerRESISTANCE > 0) exitWith {
hint "You must be further away from the enemy and closer to your group to gain your freedom";
};
};
if (side _caller == EAST) then {
if (count _nearPlayerWEST > 0 || count _nearPlayerRESISTANCE > 0) exitWith {
hint "You must be further away from the enemy and closer to your group to gain your freedom";
};
};
if (side _caller == RESISTANCE) then {
if (count _nearPlayerEAST > 0 || count _nearPlayerWEST > 0) exitWith {
hint "You must be further away from the enemy and closer to your group to gain your freedom";
};
};

_caller setCaptive false; //set player not captive
hint "You have escaped...";

Share this post


Link to post
Share on other sites
{
  if (side _x == WEST) then {

  _nearPlayer = _nearPlayer - [_x];
  };
} count _nearPlayer;

Share this post


Link to post
Share on other sites

Is this the sort of thing you are going for?

player addAction [ "Escape", {
_target = _this select 0;
_caller = _this select 1;
_ID = _this select 2;

_nearPlayer = (position _caller) nearEntities ["Man", 25];
_nearPlayer = _nearPlayer - [ _caller ];

_sides = [ east, west, independent ];

if ( { _x countSide _nearPlayer > 0 }count ( _sides - [ side _caller ] ) > 0  ) then {
	hint "You must be further away from the enemy and closer to your group to gain your freedom";
}else{
	_caller setCaptive false;
	hint "You have escaped...";  
};
}, [], 1, true, true, "", "captive _this" ];

Share this post


Link to post
Share on other sites
Is this the sort of thing you are going for?

player addAction [ "Escape", {
_target = _this select 0;
_caller = _this select 1;
_ID = _this select 2;

_nearPlayer = (position _caller) nearEntities ["Man", 25];
_nearPlayer = _nearPlayer - [ _caller ];

_sides = [ east, west, independent ];

if ( { _x countSide _nearPlayer > 0 }count ( _sides - [ side _caller ] ) > 0  ) then {
	hint "You must be further away from the enemy and closer to your group to gain your freedom";
}else{
	_caller setCaptive false;
	hint "You have escaped...";  
};
}, [], 1, true, true, "", "captive _this" ];

Well... that's a lot cleaner than what I have... I think I may be over complicating it? I'll try what you suggest.

private ["_target","_caller","_ID","_nearPlayer","_nearPlayerWEST","_nearPlayerEAST","_nearPlayerRESISTANCE"];

_target 	= _this select 0;
_caller 	= _this select 1;
_ID			= _this select 2;

if (!captive _caller) exitWith {hint "You are Already Free"};

while {true} do {
_nearPlayer = (position _caller) nearEntities ["Man", 25]; //check for other units within 25 m

if (side _caller == WEST) then {
	{
		if (side _x == WEST) then {
			_nearPlayer = _nearPlayer - [_x];
		};
	} count _nearPlayer;  //find the player unit in the _nearPlayer array //remove the player unit from the _nearPlayer array
};
if (side _caller == EAST) then {
	{
		if (side _x == EAST) then {
			_nearPlayer = _nearPlayer - [_x];
		};
	} count _nearPlayer;
};
if (side _caller == RESISTANCE) then {
	{
		if (side _x == RESISTANCE) then {
			_nearPlayer = _nearPlayer - [_x];
		};
	} count _nearPlayer;
};
_nearPlayerWEST = WEST countSide _nearPlayer;
_nearPlayerEAST = EAST countSide _nearPlayer;
_nearPlayerRESISTANCE = RESISTANCE countSide _nearPlayer;
};

/*
if (side _caller == WEST) then {
if ((_nearPlayerEAST > 0) ||  (_nearPlayerRESISTANCE > 0)) exitWith {
hint "You must be further away from the enemy and closer to your group to gain your freedom";
};
};
if (side _caller == EAST) then {
if ((_nearPlayerWEST > 0) || (_nearPlayerRESISTANCE > 0)) exitWith {
hint "You must be further away from the enemy and closer to your group to gain your freedom";
};
};
if (side _caller == RESISTANCE) then {
if ((_nearPlayerEAST > 0) || (_nearPlayerWEST > 0)) exitWith {
hint "You must be further away from the enemy and closer to your group to gain your freedom";
};
};
*/
if ((side _caller == WEST) && ((_nearPlayerEAST == 0) || (_nearPlayerRESISTANCE == 0))) then {
_caller setCaptive false; //set player not captive
hint "You have escaped...";
} else {
if ((side _caller == EAST) && ((_nearPlayerWEST == 0) || (_nearPlayerRESISTANCE == 0))) then {
	_caller setCaptive false; //set player not captive
	hint "You have escaped...";
} else {
	if ((side _caller == RESISTANCE) && ((_nearPlayerEAST == 0) || (_nearPLayerWEST == 0))) then {
		_caller setCaptive false; //set player not captive
		hint "You have escaped...";
	} else {
		hint "You must be further away from the enemy and closer to your group to gain your freedom";
	};
};
};

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  

×