Jump to content
Sign in to follow this  
Twiznak

[SOLVED]Help adding Planes to Combat Patrol reinforcements.

Recommended Posts

Hi everyone! I making a set of combat patrol missions with IFA3 assets. Everything works as it should except for the Planes being spawned as reinforcements. What is happening is that planes spawn on the ground and then taxi into a tree. I want the planes to spawn in the air at 2500m. Adding crazy immersion to the battlefield with the wailing engines of dive bombers. Please help. I'll show you my approach, please correct me.

 

Here is the script I am working with. It is the custom combat patrol mod by Basstard420.

fn_cpsendreinforcements.sqf

Spoiler

/*
	Author: Josef Zemanek

	Description:
	Combat Patrol reinforcements handle
*/


//#define BAS_CCP_DEBUG


params [
	"_reinfType",
	["_cnt", 1],
	["_roadSegment", objNull]
];

if (isNull _roadSegment) then {
	_roadSegment = selectRandom BIS_CP_reinf_approach_roads;
};
_connected = roadsConnectedTo _roadSegment;
_nearestToTarget = objNull;
{if ((_x distance BIS_CP_targetLocationPos) < (_nearestToTarget distance BIS_CP_targetLocationPos)) then {_nearestToTarget = _x}} forEach _connected;
_dir = _nearestToTarget getDir BIS_CP_targetLocationPos;

_reinfGrp = grpNull;
_grpVeh = objNull;
_vehType = "";

_sleep = TRUE;

_startingPos = position _roadSegment;

if (typeName _reinfType == typeName "") then {
//	_vehType = toLower getText (configFile >> "CfgVehicles" >> _reinfType >> "vehicleClass");
	_vehType = switch true do {
		case (_reinfType isEqualTo BIS_CP_enemyVeh_MRAP):	{"car"};
		case (_reinfType isEqualTo BIS_CP_enemyVeh_Truck):	{"truck"};
		default												{toLower getText (configFile >> "CfgVehicles" >> _reinfType >> "vehicleClass")};
	};
	/* Check for wrecks or frozen vehicle */
	{
		_veh = _x;
		{_veh deleteVehicleCrew _x} forEach crew _veh;
		deleteVehicle _veh;
		diag_log format ["CCP_DEBUG: deleted %1 reinforcement vehicle %2", ["wrecked","frozen"] select (alive _veh), typeOf _veh];
	} forEach (_roadSegment nearObjects ["LandVehicle", 10]);
	/* Spawn reinforcement vehicle */
	_pos = getPosATL _roadSegment;
	_veh = createVehicle [_reinfType, _pos, [], 0, if (_vehType in ["air", "autonomous"]) then {"FLY"} else {"NONE"}];
	diag_log format ["CCP_DEBUG: spawned a %1 reinforcement vehicle", typeOf _veh];
	/* Fix for vehicles sunk in the ground */
	if (_pos select 2 < 0 && {_vehType in ["car", "truck"]}) then {
		_veh allowDamage false;
		_pos set [2,0];
		_veh setPosATL (_pos vectorAdd [0,0,1]);
		waitUntil {sleep 0.1; (getPosATL _veh) select 2 < 0.1};
		_veh allowDamage true;
		_veh setDamage 0;
	};
	if (toLower missionName == "mp_combatpatrol_03" && toLower worldName == "tanoa" && toLower _reinfType == "o_heli_transport_04_covered_f") then {
		[_veh, "Black"] call BIS_fnc_initVehicle;
	};
	if (_vehType in ["air", "autonomous"]) then {
		_sleep = FALSE;
		_newPos = [BIS_CP_targetLocationPos, BIS_CP_radius_reinforcements * 3, random 360] call BIS_fnc_relPos;
		_startingPos = _newPos;
		if (_vehType == "autonomous" && toLower getText (configFile >> "CfgVehicles" >> _reinfType >> "simulation") == "airplanex") then {
			_newPos set [2, 300];
			_veh flyInHeight 250;
		} else {
			_newPos set [2, 75];
		};
		_veh setPos _newPos;
		_veh setDir (_veh getDir BIS_CP_targetLocationPos);
	} else {
		_veh setDir _dir;
	};
	if (_vehType in ["car", "truck"]) then {
		_reinfUnits = [];
		{ _reinfUnits pushBack (selectRandom BIS_CP_enemyTroops); } forEach fullCrew [_veh, "", true];
		_reinfGrp = [[_veh, 15, random 360] call BIS_fnc_relPos, BIS_CP_enemySide, _reinfUnits] call BIS_fnc_spawnGroup;
		_grpVeh = _veh;
		_newWP = _reinfGrp addWaypoint [_grpVeh, 0];
		_newWP setWaypointType "GETIN";
		_newWP waypointAttachVehicle _grpVeh;
	} else {
		createVehicleCrew _veh;
		_reinfGrp = group effectiveCommander _veh;
		_grpVeh = vehicle leader _reinfGrp;
	};
} else {
	_reinfGrp = [position _roadSegment, BIS_CP_enemySide, _reinfType] call BIS_fnc_spawnGroup;
	_grpVeh = (position leader _reinfGrp) nearestObject "Car";
	_vehType = "truck";
	_newWP = _reinfGrp addWaypoint [_grpVeh, 0];
	_newWP setWaypointType "GETIN";
	_newWP waypointAttachVehicle _grpVeh;
};

if (_vehType != "air") then {
	[_reinfGrp, "FULL", "SAFE", "YELLOW", 1, nil] call CCP_fnc_setGroupParameters;
	_tout = time + 60;
	waitUntil {{isNull objectParent _x && alive _x} count units _reinfGrp == 0 || time > _tout};
	while {count (waypoints _reinfGrp) > 0} do {
		{deleteWaypoint _x} forEach waypoints _reinfGrp;
	};
	for [{_i = 0}, {_i < 3}, {_i = _i + 1}] do {
		_newWP = _reinfGrp addWaypoint [BIS_CP_targetLocationPos, BIS_CP_radius_core];
		_newWP setWaypointType "SAD";
	};
	_newWP = _reinfGrp addWaypoint [BIS_CP_targetLocationPos, BIS_CP_radius_core];
	_newWP setWaypointType "CYCLE";
	if (_vehType == "truck") then {
		_null = [_reinfGrp, _startingPos, _grpVeh] spawn {
			_reinfGrp = _this select 0;
			_startingPos = _this select 1;
			_grpVeh = _this select 2;
			
			_leader = leader _reinfGrp;
			[{_leader distance2D BIS_CP_targetLocationPos < BIS_CP_radius_core || !alive _leader || !canMove _grpVeh}, 10 + random 5] call BIS_fnc_CPWaitUntil;
			if (!alive _leader || !canMove _grpVeh) exitWith {};
			[_leader] joinSilent grpNull;
			_newGrp = group _leader;
			_reinfGrp leaveVehicle _grpVeh;
			{unassignVehicle _x; [_x] orderGetIn FALSE; _x allowFleeing 0} forEach units _reinfGrp;
			[_reinfGrp, nil, "AWARE", nil, nil, nil] call CCP_fnc_setGroupParameters;
			[{{vehicle _x == _grpVeh} count units _reinfGrp == 0 || !alive _leader || !canMove _grpVeh}, 1] call BIS_fnc_CPWaitUntil;
			if (!alive _leader || !canMove _grpVeh) exitWith {};
			_leader assignAsDriver _grpVeh;
			[_leader] orderGetIn TRUE;
			if (vehicle _leader == _grpVeh) then {
				_leader setPos position _grpVeh;
				_leader moveInDriver _grpVeh;
			};
			sleep 20;
			_newWP = _newGrp addWaypoint [_startingPos, 0];
			[{_grpVeh distance2D _startingPos < 50 || !alive _leader || !canMove _grpVeh}, 0.5] call BIS_fnc_CPWaitUntil;
			if (!alive _leader || !canMove _grpVeh) exitWith {};
			_grpVeh deleteVehicleCrew driver _grpVeh;
			deleteGroup _newGrp;
			deleteVehicle _grpVeh;
		};
	};
} else {
	_reinfGrp setBehaviour "CARELESS";
	_paraUnit = [[_grpVeh, 15, random 360] call BIS_fnc_relPos, BIS_CP_enemySide, BIS_CP_enemyGrp_rifleSquad] call BIS_fnc_spawnGroup;
	{
		_x assignAsCargo _grpVeh;
		[_x] orderGetIn TRUE;
		_x moveInCargo _grpVeh;
		_x allowFleeing 0;
	} forEach units _paraUnit;
	_unloadWP = _reinfGrp addWaypoint [BIS_CP_exfilPos, 100];
	_unloadWP setWaypointStatements ["TRUE", "(vehicle this) land 'GET OUT'; {unassignVehicle _x; [_x] orderGetIn FALSE} forEach ((crew vehicle this) select {group _x != group this})"];
	_newWP = _reinfGrp addWaypoint [waypointPosition _unloadWP, 0];
	_newWP setWaypointStatements ["{group _x != group this} count crew vehicle this == 0", ""];
	_newWP = _reinfGrp addWaypoint [_startingPos, 0];
	_null = [_reinfGrp, _startingPos] spawn {
		_reinfGrp = _this select 0;
		_startingPos = _this select 1;
		_heli = vehicle leader _reinfGrp;
		[{(leader _reinfGrp) distance2D _startingPos > 200 || !alive (leader _reinfGrp) || !canMove _heli}, 5] call BIS_fnc_CPWaitUntil;
		[{(leader _reinfGrp) distance2D _startingPos < 200 || !alive (leader _reinfGrp) || !canMove _heli}, 0.5] call BIS_fnc_CPWaitUntil;
		if (!alive (leader _reinfGrp) || !canMove _heli) exitWith {};
		{_heli deleteVehicleCrew _x} forEach crew _heli;
		deleteGroup _reinfGrp;
		deleteVehicle _heli;
	};
	for [{_i = 0}, {_i < 3}, {_i = _i + 1}] do {
		_newWP = _paraUnit addWaypoint [BIS_CP_exfilPos, 100];
		_newWP setWaypointType "SAD";
	};
	_newWP = _paraUnit addWaypoint [BIS_CP_exfilPos, 100];
	_newWP setWaypointType "CYCLE";
};

#ifdef BAS_CCP_DEBUG
if (isNil "BAS_CCP_reinfMarkNo") then { BAS_CCP_reinfMarkNo = 0; };
_reifMrkr = createMarker [format ["BAS_CCP_reinfMark%1", BAS_CCP_reinfMarkNo], _grpVeh];
_reifMrkr setMarkerColor (switch (BIS_CP_enemySide) do {
	case WEST: {"colorBLUFOR"};
	case EAST: {"colorOPFOR"};
	case RESISTANCE: {"colorIndependent"};
});
_mkrType = switch (true) do {
	case (_reinfType == BIS_CP_enemyVeh_MRAP): {"o_motor_inf"};
	case (_reinfType == BIS_CP_enemyVeh_Truck): {"o_support"};
	case (_reinfType == BIS_CP_enemyVeh_UAV_big): {"o_uav"};
	case (_reinfType == BIS_CP_enemyVeh_UAV_small): {"o_uav"};
	case (_reinfType == BIS_CP_enemyVeh_reinf1): {"o_armor"};
	case (_reinfType == BIS_CP_enemyVeh_reinf2): {"o_armor"};
	case (_reinfType == BIS_CP_enemyVeh_reinfAir): {"o_air"};
	default {"o_unknown"};
};
_reifMrkr setMarkerType _mkrType;
BAS_CCP_reinfMarkNo = BAS_CCP_reinfMarkNo + 1;
_null = [_grpVeh,_reifMrkr] spawn {
	_veh = _this select 0;
	_mkr = _this select 1;
	while {alive _veh && canMove _veh} do
	{
		sleep 1;
		_mkr setMarkerPos (position _veh);
	};
};
#endif

_cnt = _cnt - 1;

if (_cnt > 0) then {
	_null = [_reinfType, _cnt, _roadSegment, _grpVeh] spawn {
		_tout = time + 60;
		waitUntil {(_this select 3) distance (_this select 2) > 20 || time > _tout};
		if (time > _tout) then {
			{_grpVeh deleteVehicleCrew _x} forEach crew _grpVeh;
			deleteVehicle _grpVeh;
		};
		_this call CCP_fnc_CPSendReinforcements;
	};
};

if (_sleep) then {
	sleep 30;
};

 

The part I am trying to modify is this:

if (_vehType in ["air", "autonomous"]) then {
		_sleep = FALSE;
		_newPos = [BIS_CP_targetLocationPos, BIS_CP_radius_reinforcements * 3, random 360] call BIS_fnc_relPos;
		_startingPos = _newPos;
		if (_vehType == "autonomous" && toLower getText (configFile >> "CfgVehicles" >> _reinfType >> "simulation") == "airplanex") then {
			_newPos set [2, 300];
			_veh flyInHeight 250;
		} else {
			_newPos set [2, 75];
		};
		_veh setPos _newPos;
		_veh setDir (_veh getDir BIS_CP_targetLocationPos);
	} else {
		_veh setDir _dir;
	};

I have tried adding a Z coordinate to the _newPos Set [x,y,z] and _newPos setPosATL [0,0,2500] but I'm lacking in a deeper understanding of the functions and syntax. 

Please look over what I have presented and correct my approach.

Share this post


Link to post
Share on other sites

@Twiznak,
Check out example 3 on createVehicle

_veh = createVehicle ["ah1w", position player, [], 0, "FLY"];

Something like,

jet= createVehicle ["b_plane_fighter_01_f", player getPos [ 2400, getDir player ], [], 0, "FLY" ];

jet flyInHeightASL [2400, 2400, 2400]; // normal/combat/stealth

Have fun!

Share this post


Link to post
Share on other sites
1 hour ago, wogz187 said:

@Twiznak,
Check out example 3 on createVehicle


_veh = createVehicle ["ah1w", position player, [], 0, "FLY"];

Something like,


jet= createVehicle ["b_plane_fighter_01_f", player getPos [ 2400, getDir player ], [], 0, "FLY" ];

jet flyInHeightASL [2400, 2400, 2400]; // normal/combat/stealth

Have fun!

Hi, Thanks for replying. I am trying it out now. I will get back to you with an update soon!

Share this post


Link to post
Share on other sites

@Twiznak,
If all you want to do is spawn some jets try this,

Spoiler

you_fnc_jet=
{
jet= createVehicle ["b_plane_fighter_01_f", _this getPos [ 2400, getDir _this ], [], 0, "FLY" ];

createVehicleCrew jet;
private _grp = group jet;
jet sidechat "Air-Support Online";

{_x allowdamage False;} foreach units _grp;
jet allowDamage false;

private _wp = _grp addwaypoint [position _this,0];
	_wp setwaypointtype "LOITER";
	_wp setWaypointSpeed "NORMAL";
	_grp setBehaviour "AWARE";

jet flyInHeightASL [2400, 2400, 2400];
jet limitspeed 700;
};

Remove the lines with "allowdamage" to allow damage. Remove the "sidechat" line if it's annoying.

To call,


player call you_fnc_jet;

You may call it as many times as you please. Whatever the caller is will determine "_this". If you had an object named "flagpole" the call would be,


flagpole call you_fnc_jet;

and then flagpole is "_this".

Have fun!

Share this post


Link to post
Share on other sites
5 hours ago, wogz187 said:

@Twiznak,
If all you want to do is spawn some jets try this,

  Hide contents


you_fnc_jet=
{
jet= createVehicle ["b_plane_fighter_01_f", _this getPos [ 2400, getDir _this ], [], 0, "FLY" ];

createVehicleCrew jet;
private _grp = group jet;
jet sidechat "Air-Support Online";

{_x allowdamage False;} foreach units _grp;
jet allowDamage false;

private _wp = _grp addwaypoint [position _this,0];
	_wp setwaypointtype "LOITER";
	_wp setWaypointSpeed "NORMAL";
	_grp setBehaviour "AWARE";

jet flyInHeightASL [2400, 2400, 2400];
jet limitspeed 700;
};

Remove the lines with "allowdamage" to allow damage. Remove the "sidechat" line if it's annoying.

To call,



player call you_fnc_jet;

You may call it as many times as you please. Whatever the caller is will determine "_this". If you had an object named "flagpole" the call would be,



flagpole call you_fnc_jet;

and then flagpole is "_this".

Have fun!

Hi. Thank you. I went with a similar approach with inspiration from you 

diveBombers.sqf

_crew1 = [];
_airframe1 = [];

if (isServer) then {

_crew1 = creategroup resistance; 
_airframe1 = [getPos aas1, 180, "LIB_P47", _crew1] call BIS_fnc_spawnVehicle;

_a1wp1 = _crew1 addWaypoint [BIS_CP_targetLocationPos, 0];
_a1wp1 setWaypointType "SAD";
_a1wp1 setWaypointSpeed "FULL";

_a1wp2 = _crew1 addWaypoint [BIS_CP_targetLocationPos, 0];
_a1wp2 setWaypointType "CYCLE";
_a1wp2 setWaypointSpeed "FULL";

};

I call the script from a trigger at mission start.....

HOWEVER, 

my idea is no good. The AI pilot won't engage ground targets. Either because he can't see them or he just won't. Scripting an attack feels to forced as CAS needs to feel organic in response to player aggression. It works like that for so many other of my missions I am saying FUG IT. I'm leaving the the planes out and just adding more grenadiers, bazookas and machine gunners. Should add that extra pucker factor I was going for. I feel like my avatar is a perfect summation of this situation. Anyway, thank you for your help sir! Game on.   

Share this post


Link to post
Share on other sites

1) for non planeX you need to apply setVelocity or setForce to avoid them take a dive at first

2) you need to reveal ground targets

Share this post


Link to post
Share on other sites
13 hours ago, .kju said:

1) for non planeX you need to apply setVelocity or setForce to avoid them take a dive at first

2) you need to reveal ground targets

Hi, thanks for responding!

1. Yes, you are correct. I circumvented this by spawning the plane from an invisible fence post 1500m above the center of the map. I WANT them to start in a nose dive. Its crazy I know, but at that altitude they can pullout at level off at about 300m. In the editor or zeus, the cinematic effect of wailing  divebomber engines is lost. When your on the ground it sounds amazing! I'm happy with that BUT your second point is my point of contention.

2. Your right again. target info is shared by units with mods like ASR AI3, vcom and lambs danger. I am going to try adding  

setWaypointBehaviour "COMBAT";

to each waypoint. When I run ASR AI3 and VCOM together, the info sharing and backup calling should bring things on target.

OR

https://community.bistudio.com/wiki/reveal  I see you on there,

https://community.bistudio.com/wiki/knowsAbout. I see you on there TOO!

 

According to the info I would need to add something like

 

_crew1 knowsAbout P_1;
_crew1 Reveal [P_1, 4];

to get the plane to fire on player right from the get. But that feels more "North by Northwest" and less like a battlefield support role. What would you do think .kju? Would target info sharing handled by ASR/Lambs/Vcom be enough to get the plane to fire on ground targets? 

Share this post


Link to post
Share on other sites

@Twiznak,

Quote

 I circumvented this by spawning the plane from an invisible fence post 1500m

Helper objects are under "signs", "helpers".
This might help figure out what the jet is trying to do,

you_fnc_jetTarget=
{
_target = assignedTarget _this;
systemChat format ["%1", _target];
};

Just call it with the jet,

"jetNAME" call you_fnc_jetTarget;

Have fun!

Share this post


Link to post
Share on other sites

Depends on the specific setup and what you want to achieve.

Also you can employ reveal in various ways (non full reveal, based on distance or any other aspects)

Share this post


Link to post
Share on other sites
21 hours ago, .kju said:

Depends on the specific setup and what you want to achieve.

Also you can employ reveal in various ways (non full reveal, based on distance or any other aspects)

 

On 10/13/2019 at 5:54 PM, wogz187 said:

@Twiznak,

Helper objects are under "signs", "helpers".
This might help figure out what the jet is trying to do,


you_fnc_jetTarget=
{
_target = assignedTarget _this;
systemChat format ["%1", _target];
};

Just call it with the jet,


"jetNAME" call you_fnc_jetTarget;

Have fun!

Ok guys, with your help I have finalized the CAS script. I'm not going to amend the Combat patrol script. Rather, I am just going to call in waves of planes, 2 at a time, starting the waves when Blufor is detected opfor/resistance. I have tested it today and they fire at ground targets.

DiveBombers.sqf



for 'i' from 0 to 99 do { 

_crew1 = creategroup resistance; 
_crew2 = creategroup resistance; 
_airframe1 = [getPos air1, 180, "LIB_P47", _crew1] call BIS_fnc_spawnVehicle;
_airframe2 = [getPos air1, 180, "LIB_P47", _crew2] call BIS_fnc_spawnVehicle;
C_1 = _crew1;
publicVariable "C_1";
C_2 = _crew2;
publicVariable "C_2";

_a1wp1 = _crew1 addWaypoint [BIS_CP_targetLocationPos, 0];
_a1wp1 setWaypointType "SAD"; 
_a1wp1 setWaypointSpeed "FULL";
_a1wp1 setWaypointCombatMode "RED";
_a1wp1 setWaypointBehaviour "COMBAT";

_a1wp2 = _crew1 addWaypoint [BIS_CP_targetLocationPos, 0];
_a1wp2 setWaypointType "CYCLE"; 
_a1wp2 setWaypointSpeed "FULL";
_a1wp2 setWaypointCombatMode "RED";
_a1wp2 setWaypointBehaviour "COMBAT";

_a2wp1 = _crew2 addWaypoint [BIS_CP_targetLocationPos, 0];
_a2wp1 setWaypointType "SAD"; 
_a2wp1 setWaypointSpeed "FULL";
_a2wp1 setWaypointCombatMode "RED";
_a2wp1 setWaypointBehaviour "COMBAT";

_a2wp2 = _crew2 addWaypoint [BIS_CP_targetLocationPos, 0];
_a2wp2 setWaypointType "CYCLE"; 
_a2wp2 setWaypointSpeed "FULL";
_a2wp2 setWaypointCombatMode "RED";
_a2wp2 setWaypointBehaviour "COMBAT";

waitUntil {({alive _x} count (units C_1 + units C_2) < 1)};
sleep 600;

};

  From my tests, they perform better when operating independently. IF the players are stealthy they won't ever see the planes. Ten minutes in between waves feels pressured but not insurmountable. I am going to release  they missions tomorrow. If the players say its too much, I will make it one plane with a longer respawn interval. Anyway, i'm happy. I scripted a plane to spawn and shoot me in the face and it did. Mission accomplished! Thank you gentlemen.

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

×