Jump to content
Blackheart_Six

Yet Another Convoy Script

Recommended Posts

498-Blackheart-Productions256x256.jpg

 

Yet Another Convoy Script

What this does:
1. Finds 2 random positions opposite sides of map.
2. Creates Start Point and Release Point markers.
3. Spawns a 4 vehicle convoy. APC, MRAP, Tanks, Trucks for OPFOR, and vehicles move to the release point. 
4. When the convoy reaches the Release Point, the convoy will be deleted, along with markers.

I currently use this script in Combat Operations 2022 for convoy ambush mission and security escort.
 

TESTED:

Altis

Gabreta

Livonia

Weferlingen

 

You can change vehicles, add or subtract vehicles.

 

Spoiler

/*
TITLE: Yet Another Convoy Script
AUTHOR: Blackheart_Six
A Blackheart Brigade Production
Version: BRAVO 
Instruction for Use: 
Copy code and paste into a sqf file, and name as you like.  
Run the script: [] execVM "convoyScript.sqf"; or Copy the code into your convoy task. You need to provide success triggers. 
Go to line 139 to edit separation/speed/combat mode.
*/
if (!isServer) exitWith {};

private _mapCenter = [worldSize/2,worldSize/2];  //Find map center 
if ([worldName, "altis",false] call BIS_fnc_inString) then {mapXY = (worldSize/4);} else {mapXY = (worldSize/2);}; //Adjust the distance from map center radius for Altis vs. Livonia vs. etc. 

//----------------------------------------- Convoy Start Point -------------------------------------------------//
private _fsp = [_mapCenter,(mapXY-1000),mapXY,0,0,0.15,0,[],[getPos player, getPos player]] call BIS_fnc_findSafePos; //Find a safe position along the edge of the map. 
waitUntil {sleep .1; (!isNil "_fsp")}; //Wait until position is found.

_sbp = selectBestPlaces [ _fsp,300,"(1 - forest) * (1 - hills) * (1 - sea) * (1 - trees) * (1 + meadow) * (1 - houses)",100,1]; //Finds a meadow to spawn convoy. Better option than road. 
_spot = _sbp select 0;
_startPoint = _spot select 0;
waitUntil {sleep .1; (!isNil "_sbp")};

private _mrkr1 = createMarker ["mrkr1", _startPoint]; //Creates start point marker. 
_mrkr1 setMarkertype "mil_marker";
private _gridPosStart = mapGridPosition _startPoint; //Returns the map grid position for marker text. 
_mrkr1 setMarkerText format ["SP Grid %1",_gridPosStart];

_convoyDirection = _startPoint getDir _fsp; //Set direction of convoy towards SP Marker. 

//----------------------------------------- Convoy Release Point -------------------------------------------------//
private _direction = _startPoint getDir _mapcenter; //Returns the direction from start point to map center
private _distance = _startPoint distance _mapcenter; //Returns the distance from the start point to map center
private _releasePoint = _mapCenter getPos [_distance, _direction]; //Returns postion opposite of the start point. 
private _fsp2 = [_releasePoint,0,1000,0,0,0,0,[],[getPos player, getPos player]] call BIS_fnc_findSafePos; 
waitUntil {sleep .1; (!isNil "_fsp2")}; 

private _nearestRoadSegment = [_fsp2, 1000] call BIS_fnc_nearestRoad; //Find the nearest road within 500 meters. This is the release convoy position.
private _convoyRPPos = position _nearestRoadSegment; 
waitUntil {sleep .1; (!isNil "_convoyRPPos")}; 

private _mrkr2 = createMarker ["mrkr2",_convoyRPPos]; //Creates release point marker.
_mrkr2 setMarkertype "mil_marker";
private _gridPosRelease = mapGridPosition _convoyRPPos; //Returns the map grid position for marker text. 
_mrkr2 setMarkerText format ["RP Grid %1",_gridPosRelease];

//----------------------------------------- Create Group and Path -------------------------------------------------//
convoy = creategroup EAST;
//Code from BIKI for calculatePath
(calculatePath ["wheeled_APC","careless",_startPoint, _convoyRPPos]) addEventHandler
["PathCalculated", 
	{
		{
			_pathMrkr = createMarker ["pathMrkr" + str _forEachIndex, _x];
			_pathMrkr setMarkerType "mil_dot";
			_pathMrkr setMarkerAlpha 1; // Change Alpha to view/not view markers. 
			_pathMrkr setMarkerSize [.5,.5];
			//_pathMrkr setMarkerText str _forEachIndex; //Code to show marker text for troubleshooting
			convoy addWaypoint [getMarkerPos _pathMrkr,-1];
			[convoy,1] setWaypointBehaviour "CARELESS";
		} forEach (_this select 1);
	}
];

//----------------------------------------- Create Convoy Elements -------------------------------------------------//
//Code by dreadedentity posted in this topic. 
private _vehicleDirection = _convoyDirection;
private _convoygrp = [];
private _crew = [];
private _vehicleList = [];
private _relPos = [15, 180];
private _randomSelect = floor random 3; //creating variable not super necessary from what I can tell
switch (_randomSelect) do {
	case 0: { //APC Convoy
		_vehicleList = ["O_T_MRAP_02_ghex_F", "O_T_APC_wheeled_02_rcws_v2_ghex_F", "O_T_APC_wheeled_02_rcws_v2_ghex_F", "O_T_APC_wheeled_02_rcws_v2_ghex_F"];
	};
	case 1: { //Truck Convoy
		_vehicleList = ["O_T_MRAP_02_hmg_ghex_F", "O_T_Truck_03_ammo_ghex_F", "O_T_Truck_03_fuel_ghex_F", "O_T_Truck_03_medical_ghex_F"];
	};
	case 2: { //Tank Convoy
		_vehicleList = ["O_T_MBT_02_cannon_ghex_F", "O_T_MBT_02_cannon_ghex_F", "O_T_MBT_02_cannon_ghex_F", "O_T_MBT_02_cannon_ghex_F"];
	};
};

private "_veh";
private _pos = _startPoint;
{
	_veh = createVehicle [_x, _pos, [], 0, "NONE"];
	_convoygrp pushBack _veh;
	_crew = createVehicleCrew _veh;
	//_crew pushBack (createVehicleCrew _veh);
	_veh setDir _vehicleDirection;
	_pos = _veh getRelPos _relPos;
	[_veh,_crew] join convoy; 
} forEach _vehicleList;

//Convoy attributes. Combat Mode/Formation/Seperation/Speed
{
	(vehicle _x) setCombatMode "YELLOW";
	(vehicle _x) setFormation "COLUMN";
	(vehicle _x) setConvoySeparation 100;
	(vehicle _x) limitSpeed 20;
} forEach (units convoy);

//----------------------------------------- Mission Clean Up -------------------------------------------------//
sleep 10;
trigger1 = createTrigger ["emptyDetector",getMarkerPos _mrkr2, true]; //Release Point Trigger and clean up. 
trigger1 setTriggerActivation ["EAST", "PRESENT", false];
trigger1 setTriggerArea [100,100,0];
trigger1 setTriggerStatements ["this && {alive _x && (side _x) == east} count units _convoy >= 1","",""]; //Change east to side of the convoy vehicles. 
waitUntil {sleep 1; triggerActivated trigger1};

for "_i" from 1 to 3 do {deleteMarker ("mrkr" + str _i);}; // Deletes the start and release point markers. 
for "_i" from 0 to 10000 do {deleteMarker ("pathmrkr" + str _i);}; //Deletes the unknown number of path markers.
{
	deleteVehicle _x;  //Deletes the vehicle crew. 
	deleteVehicle vehicle _x; //Deletes vehicle. 
} forEach units convoy; 

deleteGroup convoy; //Deletes the group. 
sleep 10;
[] execVM "vehicleConvoy.sqf";

 


 

 

  • Like 2

Share this post


Link to post
Share on other sites

Cool script, for the issue of the ending position being in water, maybe the surfaceIsWater command can be useful?

 

Also I rewrote some of the script to get rid of all the copy-paste, I hope you find that helpful:

private _vehicleDirection = vehicleDirection;
private _convoy = [];
private _crew = [];
private _vehicleList = [];
private _relPos = [15, 180];
private _randomSelect = floor random 3; //creating variable not super necessary from what I can tell
switch (_randomSelect) do {
	case 0: { //APC Convoy
		_vehicleList = ["O_T_MRAP_02_ghex_F", "O_T_APC_wheeled_02_rcws_v2_ghex_F", "O_T_APC_wheeled_02_rcws_v2_ghex_F", "O_T_APC_wheeled_02_rcws_v2_ghex_F"];
	};
	case 1: { //Truck Convoy
		_vehicleList = ["O_T_MRAP_02_hmg_ghex_F", "O_T_Truck_03_ammo_ghex_F", "O_T_Truck_03_fuel_ghex_F", "O_T_Truck_03_medical_ghex_F"];
	};
	case 2: { //Tank Convoy
		_vehicleList = ["O_T_MBT_04_command_F", "O_T_MBT_04_cannon_F", "O_T_MBT_04_cannon_F", "O_T_MBT_02_cannon_ghex_F"];
		_relPos = [20, 180];
	};
};

private "_veh";
private _pos = getMarkerPos _mrkr2;
{
	_veh = createVehicle [_x, _pos, [], 0, "NONE"];
	_convoy pushBack _veh;
	_crew pushBack (createVehicleCrew _veh);
	_veh setDir _vehicleDirection;
	_pos = _veh getRelPos _relPos;
} forEach _vehicleList;

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Hi Dread,

 

Thanks! Yes I can always use the help. I am not very efficient in my coding as you can tell. I am a hardware guy who enjoys the challenge.

 

It does work pretty well though, and I am happy I got it to run. 🙂

 

I'll look at the surfaceIsWater command. I've only had one instance of the position out over water, but that's one too many.

 

Anywho, thanks again I really appreciate it.

Share this post


Link to post
Share on other sites

Version BRAVO

 

UPDATED:

1. Utilized dreadedentity code to simplify script.

2. Adjusted start point from road position to meadow position near road. This gives better spawning and direction.

 

TESTED:

Altis

Gabreta

Livonia

Weferlingen

 

See post #1 for updated script.

Share this post


Link to post
Share on other sites

Hey Blackheart, here's some quality of life things you could improve

1. Use the code tag for syntax highlighting so that your script can be easily read on the forum.

2. Instead of "//Go to line 139 to edit ...", you can utilize params or #define. Params is a simple way to make your script much easier to use. It's a one-liner and it allows you to specify default values too.

3. Not sure why convoy is a global variable because it makes the script unsafe to run twice at the same time. Having two convoys active at the same time is a totally plausible use case but if it's not allowed then the script should exit early if the convoy already exists.

Share this post


Link to post
Share on other sites

1. I used spoiler tag because of the length of the code and posting to the forums. Granted not a thousand lines of code, but I've been around long enough to know better. 

2. The //Go to line 139.... is a comment to tell someone how to edit. All the comments are for someone like me who might want to learn to script something. I don't think params or #define is appropriate for that purpose. 

 

Thanks for the feedback though!

 

Share this post


Link to post
Share on other sites

Alright, I assumed you shared it for others to use in their missions.

 

I don't mind the spoiler, I meant that you can nest code block inside a spoiler.

Share this post


Link to post
Share on other sites

-  minor change for better waypoint handling. Removed index number, and name.

- add code tag to spoiler.

 

Post #1 Update. Steam Updated.

 

  • 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

×