Jump to content
Sign in to follow this  
kibaBG

[HELP] Define blacklist area for patrol

Recommended Posts

I am using https://community.bistudio.com/wiki/BIS_fnc_taskPatrol to ask spawned units to patrol area marker but how to make them patrol only in that area. What to write in the blacklist parameter? 
 

_group, _pos, 200, ???] call BIS_fnc_taskPatrol;

What should be the fourth parameter so everything outside area marker is blacklisted?  I would be really, really thankful if somebody solves this! I need the script paramedics asap lol. 

Share this post


Link to post
Share on other sites

Its more I like to whitelist the marker area, so all patrol positions to be inside. 🙂 

Share this post


Link to post
Share on other sites
4 hours ago, kibaBG said:

Its more I like to whitelist the marker area, so all patrol positions to be inside. 🙂 

 

Smart, using blacklisting in combination with elliptical areas would be a lot... 😛

 

Here is taskPatrol rewritten with the 4th parameter being a whitelist instead of a blacklist. 

How you wish to define and call it is up to you but I recommend a CfgFunctions definition.

Procedure: 

Spoiler

 

Do 3-5 times:

  1. From the previous position step a random direction and distance (within 50 - MAX DISTANCE m).
  2. Where we land check if its safe and within the whitelist.
    • No: repeat step 1 up to 100 times.
    • Yes: add a waypoint and set the new position as the previous.
  3. Back to 1.

 

 

 

 

Code (with bonus test code included):

Spoiler

/*
	File: fn_taskPatrol_whitelist.sqf
	By: mrCurry - https://forums.bohemia.net/profile/759255-mrcurry/
	Variant of: A3\functions_f\spawning\fn_taskPatrol.sqf
	By: Joris-Jan van 't Land

	Description:
	Create a random patrol of several waypoints around a given position.

	Parameter(s):
	_this select 0: the group to which to assign the waypoints (Group)
	_this select 1: the position on which to base the patrol (Array)
	_this select 2: the maximum distance between waypoints (Number)
	_this select 3: (optional) whitelist of areas (Array)
	
	Returns:
	Boolean - success flag
*/

//Validate parameter count
if ((count _this) < 3) exitWith {["Function requires at least 3 parameters!"] call BIS_fnc_error; false};

private ["_grp", "_pos", "_maxDist", "_whitelist", "_posWhitelist"];
_grp = _this select 0;
_pos = _this select 1;
_maxDist = _this select 2;

_whitelist = [];
if ((count _this) > 3) then {_whitelist = _this select 3};

//Validate parameters
if ((typeName _grp) != (typeName grpNull)) exitWith {["Group (0) must be a Group!"] call BIS_fnc_error; false};
if ((typeName _pos) != (typeName [])) exitWith {["Position (1) must be an Array!"] call BIS_fnc_error; false};
if ((typeName _maxDist) != (typeName 0)) exitWith {["Maximum distance (2) must be a Number!"] call BIS_fnc_error; false};
if ((typeName _whitelist) != (typeName [])) exitWith {["Blacklist (3) must be an Array!"] call BIS_fnc_error; false};

private _checkWhitelist = !(_whitelist isEqualTo []);
if (_checkWhitelist) then
{
	_posWhitelist = _whitelist apply 
	{
		// top-left, bottom-right coordinates 
		if (_x isEqualTypeParams [[],[]]) then 
		{
			_x select 0 params [["_x0", 0], ["_y0", 0]];
			_x select 1 params [["_x1", 0], ["_y1", 0]];
			private _a = (_x1 - _x0) / 2;
			private _b = (_y0 - _y1) / 2;
			[[_x0 + _a, _y0 - _b], abs _a, abs _b, 0, true]
		}
		else
		{
			// other area compatible formats
			_x call BIS_fnc_getArea
		};
	};
};

_grp setBehaviour "SAFE";

//Create a string of randomly placed waypoints.
private ["_prevPos"];
_prevPos = _pos;
for "_i" from 0 to (2 + (floor (random 3))) do
{
	private ["_wp", "_newPos", "_tries"];
	_newPos = [_prevPos, 50, _maxDist, 1, 0, 60 * (pi / 180), 0, []] call BIS_fnc_findSafePos;
	_tries = 100;
	while { _tries > 0 && _checkWhitelist && { _posWhitelist findIf { _newPos inArea _x } < 0 } } do {
		_tries = _tries - 1;
		
		_newPos = [_prevPos, 50, _maxDist, 1, 0, 60 * (pi / 180), 0, []] call BIS_fnc_findSafePos;
	};

	if(_tries == 0) exitWith { ["Failed to find a new whitelisted point far enough away from the previous one, is the white listed area large enough?"] call BIS_fnc_error; };

	_prevPos = _newPos;

	_wp = _grp addWaypoint [_newPos, 0];
	_wp setWaypointType "MOVE";
	_wp setWaypointCompletionRadius 20;

	//Set the group's speed and formation at the first waypoint.
	if (_i == 0) then
	{
		_wp setWaypointSpeed "LIMITED";
		_wp setWaypointFormation "STAG COLUMN";
	};
};

//Cycle back to the first position.
private ["_wp"];
_wp = _grp addWaypoint [_pos, 0];
_wp setWaypointType "CYCLE";
_wp setWaypointCompletionRadius 20;

true

/* Test code - assumes you set up the function as TEST_fnc_taskPatrol_whitelist and have created 3 area markers named "marker_0", "marker_1" and "marker_2".

[] spawn {
	openMap [true, false];

	while {visibleMap} do {
		while { count waypoints group player > 0} do {
			private _wps = waypoints group player;
		deleteWaypoint (_wps select 0);
		};
		group player addWaypoint [getPos player, 0];

		[group player, getPos player, 150, ["marker_0", "marker_1", "marker_2"]] call TEST_fnc_taskPatrol_whitelist;

		sleep 3;
	};
};

*/

 

 

Note that since it is using a whitelist instead of a blacklist it's more probable that you accidentally create combination of parameters that will result in no waypoints.

I've added a BIS_fnc_error message for that situation so keep an eye out for it.

  • Like 3

Share this post


Link to post
Share on other sites

@mrcurry answered your actual question, but to your original question, any Biki entry should explain what each parameter should be. For BIS_fnc_taskPatrol:

 

Quote

Syntax: 

     [group, position, distance, blacklist] call BIS_fnc_taskPatrol

Parameters:

     group: Group - the group to patrol

     position: Position - the position on which to base the patrol

     distance: Number - maximum distance between waypoints in meters

     blacklist: Array - (optional) blacklist of areas

 

So, the blacklist parameter should be an array of areas, "area" typically being defined as a trigger, marker, or location. Locations are a PITA to work with so we'll forget that option.

 

Let's say we want to exclude patrols from trigger areas trig1 and trig2, and marker areas "mark1" and "mark2."

//Biki sample with no blacklist

[group _unit, getPos _unit, 1000] call BIS_fnc_taskPatrol;

//add blacklist array [trig1, trig2, "mark1", "mark2"]

[group _unit, getPos _unit, 1000, [trig1, trig2, "mark1", "mark2"]] call BIS_fnc_taskPatrol;

 

  • Like 3

Share this post


Link to post
Share on other sites

@mrcurry Thank you so much, I will write back after heavy testing the script. 

@Harzach Thanks for explaining, I figured this and I did my area markers rectangle so I can place another four area markers to each and blacklist them. I sounds crazy but it works, the only problem is the manual labor is a lot ...  

  • Like 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
Sign in to follow this  

×