![]() |
|
|
|||||||
| ArmA 2 & OA - MISSION EDITING & SCRIPTING For discussing the technical aspects of creating custom ArmA 2 & the standalone expansion Operation Arrowhead missions as well as scripting. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Corporal
Join Date: Jul 2009
Posts: 76
|
Improved BIS_fnc_taskPatrol
Updated to 1.1 - The debug parameter is now optional. Slack space has also been increased to create a more rough circular patrol path and also give a greater chance for the script to find safe positions to place waypoints.
Updated to 1.2 - Performance optimizations (no spawn calls, less code). Formation type and combat mode semi randomized. Accepts 2D map coordinates (thanks Wolffy.au). **** Following up with my tweaks to BIS_fnc_taskDefend I also had a go at BIS_fnc_taskPatrol. My version creates a continually randomized roughly circular patrol path around a given point (as opposed to the BIS function which is purely random and chaotic). Generally it will move clockwise with a random chance to skip ahead and intersect across to another waypoint. It will also occasionally search out the area inside of this circle. It is very low CPU usage and doesn't use any continually running scripts after it starts but instead relies on code attached to waypoints. It won't compete with UPS or a more advanced patrol script, but it can accomplish similar goals while using a small fraction of the resources. It will probably work best with infantry in relatively open areas or aircraft as it doesn't use a lot of intelligence for creating the patrol points other than making sure they are clear of obstacles and level enough for movement. I may improve this in the future as I think of any new ideas which keep within the framework of using low resources and no continually running scripts. Suggestions welcome. ***** Copy and paste the code into a new file called "BIN_taskPatrol.sqf" and then put into your mission directory. After, in the mission editor copy the below line into the group leader's init field that you want to do the patrolling. Make sure he is in the right position as this method creates a circular path of waypoints around him. In this case the patrol will have a radius of 250m which you can change to whatever you like and the script will compensate by using more waypoints. Also make sure you have a "Functions" module placed on the map. null = [group this,(getPos this),250] execVM "BIN_taskPatrol.sqf" Just use notepad to create this script and make sure you save the file as "BIN_taskPatrol.sqf" and not "BIN_taskPatrol.sqf.txt". To make sure go to Windows Explorer and then find folder options and see that "Hide extensions for known file types" is NOT checked. Code:
/*
=======================================================================================================================
Script: BIN_taskPatrol.sqf v1.2
Author(s): Binesi
Partly based on original code by BIS
Description:
Creates a continually randomized patrol path which circles and intersects 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) debug markers on or off (Number)
_this select 4: (optional) blacklist of areas (Array)
Returns:
Boolean - success flag
Example(s):
null = [group this,(getPos this),250] execVM "BIN_taskPatrol.sqf"
null = [group this,(getPos this),250,1] execVM "BIN_taskPatrol.sqf" // Same with debug markers
-----------------------------------------------------------------------------------------------------------------------
Notes:
=======================================================================================================================
*/
_grp = _this select 0;
_pos = _this select 1;
_max_dist = _this select 2;
_debug = if ((count _this) > 3) then {_this select 3} else {0};
_blacklist = if ((count _this) > 4) then {_blacklist = _this select 4} else {[]};
_mode = ["YELLOW", "RED"] call BIS_fnc_selectRandom;
_formation = ["STAG COLUMN", "WEDGE", "ECH LEFT", "ECH RIGHT", "VEE", "DIAMOND"] call BIS_fnc_selectRandom;
_grp setBehaviour "AWARE";
_grp setSpeedMode "LIMITED";
_grp setCombatMode _mode;
_grp setFormation _formation;
_center_x = (_pos) select 0;
_center_y = (_pos) select 1;
_center_z = (_pos) select 2;
if(isNil "_center_z")then{_center_z = 0;};
_wp_count = 4 + (floor random 3) + (floor (_max_dist / 100 ));
_angle = (360 / (_wp_count -1));
_new_angle = 0;
_wp_array = [];
_slack = _max_dist / 5.5;
if ( _slack < 20 ) then { _slack = 20 };
while {count _wp_array < _wp_count} do
{
private ["_x1","_y1","_wp_pos"];
_newangle = count _wp_array * _angle;
_x1 = _center_x - (sin _newangle * _max_dist);
_y1 = _center_y - (cos _newangle * _max_dist);
_wp_pos = [[_x1, _y1, _center_z], 0, _slack, 6, 0, 50 * (pi / 180), 0, _blacklist] call BIS_fnc_findSafePos;
_wp_array = _wp_array + [_wp_pos];
sleep 0.5;
};
sleep 1;
for "_i" from 1 to (_wp_count - 1) do
{
private ["_wp","_cur_pos","_marker","_marker_name"];
_cur_pos = (_wp_array select _i);
// Create waypoints based on array of positions
_wp = _grp addWaypoint [_cur_pos, 0];
_wp setWaypointType "MOVE";
_wp setWaypointCompletionRadius (5 + _slack);
[_grp,_i] setWaypointTimeout [0, 2, 16];
// When completing waypoint have 33% chance to choose a random next wp
[_grp,_i] setWaypointStatements ["true", "if ((random 3) > 2) then { group this setCurrentWaypoint [(group this), (floor (random (count (waypoints (group this)))))];};"];
if (_debug > 0) then {
_marker_name = str(_wp_array select _i);
_marker = createMarker[_marker_name,[_cur_pos select 0,_cur_pos select 1]];
_marker setMarkerShape "ICON";
_marker_name setMarkerType "DOT";
};
sleep 0.5;
};
// End back near start point and then pick a new random point
_wp1 = _grp addWaypoint [_pos, 0];
_wp1 setWaypointType "SAD";
_wp1 setWaypointCompletionRadius (random (_max_dist));
[_grp,(count waypoints _grp)] setWaypointStatements ["true", "group this setCurrentWaypoint [(group this), (round (random 2) + 1)];"];
// Cycle in case we reach the end
_wp2 = _grp addWaypoint [_pos, 0];
_wp2 setWaypointType "CYCLE";
_wp2 setWaypointCompletionRadius 100;
true
Last edited by Binesi; 09-29-2009 at 12:12 AM. Reason: Added more instructions. Updated script to 1.1 |
|
|
|
|
|
#2 |
|
Master Sergeant
Join Date: Jun 2007
Posts: 784
|
Excellent idea!
![]() Hey, real quick - I like how you modify the new angle. Here's a little function I made that can "normalize" a dynamically created and adjusted angle. Ok, that sounded confusing. Say you have a guy facing 15 degrees, and you want a waypoint that will be a random angle +/- 30. If it is too far "left" then it will be less than 0. Call this function and it'll return the normalized angle. Example: Code:
_dirTemp = (_dirTemp + (random 120)) - 60; _dir = [_dirTemp] call JTD_fnc_dirNorm; Code:
/* JTD direction normalization function - JTD_fnc_dirNormal.sqf
By Trexian
ooooooooooooooooooooooooooooooooooooooooooooooooooo
Credits:
OFPEC
DMarkwick, for math
ooooooooooooooooooooooooooooooooooooooooooooooooooo
The purpose of the JTD direction normalization function is to take a number and adapt it so that it is between 0 and 360. This allows for the initiating script to take a direction, add or subtract from it, call the function, and end up with a valid number returned.
ooooooooooooooooooooooooooooooooooooooooooooooooooo
*/
//hint "function init";
//sleep 1;
_tempDir = _this select 0;
if ((_tempDir > 360) || (_tempDir < 0)) then
{
_dir = abs (abs (_tempDir) - 360);
}
else
{
_dir = _tempDir;
};
// return the normalized function
_dir
__________________
-----------<T>---------- ![]() Creator of JTD Ambient Civilian Traffic Module (beta ver. 2). |
|
|
|
|
|
#3 | |
|
Corporal
Join Date: Jul 2009
Posts: 76
|
Quote:
I should experiment with pre-randomizing those angles a bit instead of just using the random on BIS_fnc_findSafePos. I was already happy enough to remember my math schooling to plot a circle... haha. BTW if anyone wants to make the created waypoints even more rough and less circular find this line and lower the 7 to 6 or maybe 5. Code:
_slack = _max_dist / 7; |
|
|
|
|
|
|
#4 |
|
Master Sergeant
Join Date: Jun 2007
Posts: 784
|
Also - check your private messages.
I sent you one a bit ago.
__________________
-----------<T>---------- ![]() Creator of JTD Ambient Civilian Traffic Module (beta ver. 2). |
|
|
|
|
|
#5 |
|
Corporal
Join Date: Sep 2008
Location: Sydney,Australia
Posts: 94
|
Nice work Binesi - was thinking of doing exactly the same thing!
![]() Can you give me a link to your modified Defend script? EDIT: Found it - http://forums.bistudio.com/showthread.php?t=87129 |
|
|
|
|
|
#6 | ||
|
Corporal
Join Date: Sep 2008
Location: Sydney,Australia
Posts: 94
|
Binesi, I keep getting findSafePos errors
Quote:
Quote:
Last edited by Wolffy.au; 09-25-2009 at 10:46 PM. |
||
|
|
|
|
|
#7 |
|
CWR
Join Date: May 2007
Location: Indiana, USA
Posts: 2,054
|
Using this in a couple new mission of mine, saves me a LOT of time, thank you!
|
|
|
|
|
|
#8 |
|
Corporal
Join Date: Jul 2009
Posts: 76
|
I haven't seen this error but I updated the script with a greater amount of slack space to search for a waypoint position and it is less picky about being near something. This will also cause the circular path to be a bit more random and reduce chances of a findSafePos error.
The debug parameter is also now optional. You can use the same parameters as the BIS function if you like. Last edited by Binesi; 09-26-2009 at 12:43 AM. |
|
|
|
|
|
#9 |
|
CWR
Join Date: May 2007
Location: Indiana, USA
Posts: 2,054
|
Here's something that's odd, and just started happening on my new mission. Every one of the units I put this in, no matter where, a waypoint is created to a building in Novy Sobor. Even when I'm on the other side of the map, any idea why?
EDIT - The reason was because I had the module "Functions" placed. Strange. |
|
|
|
|
|
#10 |
|
Corporal
Join Date: Jul 2009
Posts: 76
|
This script uses the BIS_fnc_findSafePos from the functions module to find a safe place to put a waypoint. I forgot to add that into the notes and instructions. Updated.
Last edited by Binesi; 09-26-2009 at 06:07 AM. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|