Jump to content
Sign in to follow this  
cobra4v320

Random helicopter spawn not working

Recommended Posts

I'm back :yay: :yay: :yay:

I have an issue with this script below, I would like to be able to choose how many units to spawn in.

Im trying to use the: for "_i" from 0 to _maxunits do {this stuff here} command and its not working for me. Issue is highlighted in red.

/*
   Random Aircraft Spawn: v.1.0
   Created by: cobra4v320
   Special Thanks to Twirly and Demonized for the help

   Execute with:  _null = [West, "Heavy_Heli_WEST", 3, getmarkerpos "spawn", getpos player, "Patrol", 350, 10] execVM "RAS.sqf";

   	Parameter(s):
_this select 0: the side on which to spawn the vehicle
_this select 1: the type of vehicle to be spawned
[color="Red"]_this select 2: the number of units to be spawned[/color]
_this select 3: the position to spawn the vehicle
_this select 4: the position the vehicle will move to
_this select 5: the type of move either - Patrol or ATTack
_this select 6: the delay before the vehicle will be spawned
*/

//Prepare variables
private ["_Light_Heli_East","_Heavy_Heli_East","_Fixed_Wing_East","_Light_Heli_West","_Heavy_Heli_West","_Fixed_Wing_West","_Light_Heli_Guer","_type","_grpvehs","_vehicle","_grp","_grpDir","_ArmaVersion","_side","_vehicletype","_maxunits","_spwnpos","_movepos","_movetype","_distance","_delay"];

// EDIT THESE VARIABLES TO CUSTOMIZE RAS //

_ArmaVersion = 3; // what versions Arma used 	0 = arma2 only		1 = OA only 	2 = Arma2 and OA 	3 = Arma2/OA and BAF/PMC
_distance = 300;

// DO NOT MODIFY BELOW THIS LINE //

if (!isServer) exitWith {};

//Is functions module ready?
waituntil {!isnil "bis_fnc_init"};

_side = _this select 0;
_vehicletype = _this select 1;
[color="Red"]_maxunits = _this select 2;[/color]
_spwnpos = _this select 3;
_movepos = _this select 4;
_movetype = _this select 5;
_delay = _this select 6;

//initialize arrays
_Light_Heli_East = [];
_Heavy_Heli_East = [];
_Fixed_Wing_East = [];
_Light_Heli_West = [];
_Heavy_Heli_West = [];
_Fixed_Wing_West = [];
_Light_Heli_Guer = [];
_type = "";

//delay before spawning vehicle
sleep _delay;

//array of available East Aircraft
if (_side == East) then 
{
       if (_ArmaVersion == 0) then {
           _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU"];
	_Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black"];
		_Fixed_Wing_East = ["Su25_INS","Su34","Su39"];
       };
       if (_ArmaVersion == 1) then {
           _Light_Heli_East = ["Mi17_TK_EP1","UH1H_TK_EP1"];
	_Heavy_Heli_East = ["Mi24_D_TK_EP1"];
		_Fixed_Wing_East = ["Su25_TK_EP1","L39_TK_EP1"];
       };
       if (_ArmaVersion == 2) then {
           _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU","Mi17_TK_EP1","UH1H_TK_EP1"];
	_Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black","Mi24_D_TK_EP1"];
		 _Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
       }; 
if (_ArmaVersion == 3) then {
           _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU","Mi17_TK_EP1","UH1H_TK_EP1"];
	_Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black","Mi24_D_TK_EP1"];
		_Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
       };
};

//array of available West Aircraft
if (_side == West) then 
{
       if (_ArmaVersion == 0) then {
           _Light_Heli_West = ["MH60S","UH1Y"];
	_Heavy_Heli_West = ["AH1Z","AH64D"];
		_Fixed_Wing_West = ["A10","F35B","AV8B2"];
       };
       if (_ArmaVersion == 1) then {
           _Light_Heli_West = ["UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
	_Heavy_Heli_West = ["AH64D_EP1"];
		_Fixed_Wing_West = ["A10_US_EP1"];
       };
       if (_ArmaVersion == 2) then {
           _Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
	_Heavy_Heli_West = ["AH1Z","AH64D","AH64D_EP1"];
		_Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
       }; 
	if (_ArmaVersion == 3) then {
           _Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1","AW159_Lynx_BAF","BAF_Merlin_HC3_D","CH_47F_BAF"];
	_Heavy_Heli_West = ["AH1Z","AH64D","AH64D_EP1","BAF_Apache_AH1_D"];
		_Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
       };

};

//array of available Guer Aircraft
if (_side == Resistance) then 
{
       if (_ArmaVersion == 1) then {
           _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1"];		
       };
       if (_ArmaVersion == 2) then {
           _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1"];
       }; 
	if (_ArmaVersion == 3) then {
           _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1","Ka60_GL_PMC","Ka60_PMC"];
       };

};

//select random vehicle based on side
switch (_vehicletype) do 
{	
case "Heavy_Heli_WEST": {_type = _Heavy_Heli_West select floor (random count _Heavy_Heli_West)};

case "Heavy_Heli_EAST": {_type = _Heavy_Heli_East select floor (random count _Heavy_Heli_East)};

case "Light_Heli_WEST": {_type = _Light_Heli_West select floor (random count _Light_Heli_West)};

case "Light_Heli_EAST": {_type = _Light_Heli_East select floor (random count _Light_Heli_East)};

case "Fixed_Wing_WEST": {_type = _Fixed_Wing_West select floor (random count _Fixed_Wing_West)};

case "Fixed_Wing_EAST": {_type = _Fixed_Wing_East select floor (random count _Fixed_Wing_East)};

case "Light_Heli_GUER": {_type = _Light_Heli_Guer select floor (random count _Light_Heli_Guer)};
};

_grp = createGroup _side;	//create group

//create helicopters
if (_type isKindof "helicopter") then
{

  [color="Red"] for "_i" from 0 to _maxunits do {[/color]

_grp = [_spwnpos, _side, [_type]] call BIS_fnc_spawnGroup;	//create two vehicles

_grp selectLeader ((units _grp) select 0);						//select leader

_grpvehs = [];											// array to list all different vehicles in group.
_grpDir = getDir (vehicle (leader _grp));							// the direction of the leader or his vehicle.
{
_vehicle = vehicle _x; 									// the vehicle of the unit.
if (_vehicle isKindOf "Air" AND !(_vehicle in _grpvehs)) then {				// if vehicle is of Air type and not in list.
	_grpvehs = _grpvehs + [_vehicle];						// add the vehicle to the list so we know it has been processed.
	_vehicle setDir _grpDir;							// set the group direction on the vehicle.
	_vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 150];	// set the height to 150.
	_vehicle setVelocity [sin (_grpDir) * 100, cos (_grpDir) * 100, 0];  			// set speed to 150.
	_vehicle flyinheight 150;							// set vehicle to fly height
};
} foreach units _grp;
[color="Red"]};[/color]
};


if (_type isKindof "plane") then
{

  [color="Red"] for "_i" from 0 to _maxunits do {[/color]

_grp = [_spwnpos, _side, [_type]] call BIS_fnc_spawnGroup;	//create two vehicles

_grp selectLeader ((units _grp) select 0);						//select leader

_grpvehs = [];											// array to list all different vehicles in group.
_grpDir = getDir (vehicle (leader _grp));							// the direction of the leader or his vehicle.
{
_vehicle = vehicle _x; 									// the vehicle of the unit.
if (_vehicle isKindOf "Air" AND !(_vehicle in _grpvehs)) then {				// if vehicle is of Air type and not in list.
	_grpvehs = _grpvehs + [_vehicle];						// add the vehicle to the list so we know it has been processed.
	_vehicle setDir _grpDir;							// set the group direction on the vehicle.
	_vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 400];	// set the height to 150.
	_vehicle setVelocity [sin (_grpDir) * 150, cos (_grpDir) * 150, 0];  			// set speed to 150.
	_vehicle flyinheight 400;							// set vehicle to fly height
};
} foreach units _grp;
[color="Red"]};[/color]
};

//select move type
switch (_movetype) do 
{	
case "Patrol": 	{[_grp, _movepos, _distance] call bis_fnc_taskPatrol}; 			//Aircraft will cycle through waypoints
case "Attack": 	{[_grp, _movepos] call bis_fnc_taskAttack}; 				//Aircraft will SAD at designated position
};

//set group behavior
{_x setBehaviour "COMBAT"; _x SetCombatMode "RED"; _x setSpeedMode "NORMAL"} foreach units _grp;

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Hi man... welcome back from wherever!

Are you trying to spawn more than one vehicle?. So for instance if _maxunits was 5 .... then five vehicles would spawn?

Having a hard time trying to follow the code!

EDIT: Added this till I can figure exactly what you need! I think there's other stuff wrong but this is obvious to me.

Since we start counting at 0 your for statement needs to be like this to get the correct count.

for "_i" from [color="Red"][b]0[/b][/color] to [color="Red"][b](_maxunits - 1)[/b][/color] do {

or like this if we start the count at 1....

for "_i" from [color="Red"][b]1[/b][/color] to [color="Red"][b]_maxunits[/b][/color] do {

Edited by twirly

Share this post


Link to post
Share on other sites

Never went anywhere just back to ask more questions. I am going to Disneyland with the family Tuesday though. If you see a guy wearing a camelbak full of beer being chased by Disney characters thats me!!! :rolleyes:

Yeah that was my error using a zero instead of a 1. I think I will have to use bis_fnc_spawnvehicle instead as well, because the helicopters spawned are creating separate groups, one group is starting at 150m the others on the ground and then they dont move anywhere. Still testing.

What Im trying to do is have the option to spawn in more than one helicopter and not have to search through the entire script.

Having a hard time trying to follow the code!

What!!! Im all ears on how to make it easier to follow.

_grp = createGroup _side;	//create group

//create helicopters
if (_type isKindof "helicopter") then
{
for "_i" from 1 to _maxunits do {

_grp = [_spwnpos, _side, [_type]] call BIS_fnc_spawnGroup;				
};

_grp selectLeader ((units _grp) select 0);						


_grpvehs = [];											
_grpDir = getDir (vehicle (leader _grp));							
{
_vehicle = vehicle _x; 								
if (_vehicle isKindOf "helicopter" AND !(_vehicle in _grpvehs)) then {
	_grpvehs = _grpvehs + [_vehicle];
	_vehicle setDir _grpDir;
	_vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 150];
	_vehicle setVelocity [sin (_grpDir) * 100, cos (_grpDir) * 100, 0];
	_vehicle flyinheight 150;
};
} foreach units _grp;

};

---------- Post added at 07:57 AM ---------- Previous post was at 07:47 AM ----------

Okay I figured it out:

_grp = createGroup _side;	//create group

//create helicopters
if (_type isKindof "helicopter") then
{
[color="Red"]for "_i" from 1 to _maxunits do {

[_spwnpos, 180, _type, _grp] call BIS_fnc_spawnVehicle;[/color]

_grp selectLeader ((units _grp) select 0);				

_grpvehs = [];											
_grpDir = getDir (vehicle (leader _grp));							
{
_vehicle = vehicle _x; 								
if (_vehicle isKindOf "helicopter" AND !(_vehicle in _grpvehs)) then {
	_grpvehs = _grpvehs + [_vehicle];
	_vehicle setDir _grpDir;
	_vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 150];
	_vehicle setVelocity [sin (_grpDir) * 100, cos (_grpDir) * 100, 0];
	_vehicle flyinheight 150;
	[color="Red"]sleep 0.5;[/color]
};
} foreach units _grp;

[color="Red"]};[/color]
};

---------- Post added at 08:03 AM ---------- Previous post was at 07:57 AM ----------

Here is the updated script for anyone interested:

/*
   Random Aircraft Spawn: v.1.0
   Created by: cobra4v320 with Special Thanks to Twirly and Demonized for the help.

   Description: This will spawn in random aircraft based on installed ArmA Version, side, the type of aircraft selected, and the number of aircraft selected. The created vehicle(s) will either patrol or attack the selected position.

   Execute with:  _null = [West, "Heavy_Heli_WEST", 4, getmarkerpos "spawn", getpos player, "Patrol", 350, 10] execVM "RAS.sqf";

   	Parameter(s):
_this select 0: the side on which to spawn the vehicle.
_this select 1: the type of vehicle to be spawned.
_this select 2: the number of units to be spawned.
_this select 3: the position to spawn the vehicle.
_this select 4: the position the vehicle will move to.
_this select 5: the type of move either - Patrol or ATTack.
_this select 6: the distance between waypoints.
_this select 7: the delay before the vehicle will be spawned.
*/

//Prepare variables
private ["_Light_Heli_East","_Heavy_Heli_East","_Fixed_Wing_East","_Light_Heli_West","_Heavy_Heli_West","_Fixed_Wing_West","_Light_Heli_Guer","_type","_grpvehs","_vehicle","_grp","_grpDir","_ArmaVersion","_side","_vehicletype","_spwnpos","_movepos","_movetype","_distance","_delay"];

// EDIT THESE VARIABLES TO CUSTOMIZE RAS. //

_ArmaVersion = 3; // what versions Arma used. 	0 = arma2 only.		1 = OA only. 	2 = Arma2 and OA. 	3 = Arma2/OA and BAF/PMC.

// DO NOT MODIFY BELOW THIS LINE. //

if (!isServer) exitWith {};

waituntil {!isnil "bis_fnc_init"};	// Is functions module ready?

if ((count _this) < 8) exitWith {hint "Script requires at least 8 parameters!"};	// Validate parameter count.

_side 		= _this select 0;
_vehicletype 	= _this select 1;
_maxUnits 	= _this select 2;
_spwnpos	= _this select 3;
_movepos 	= _this select 4;
_movetype	= _this select 5;
_distance 	= _this select 6;
_delay 		= _this select 7;

// initialize arrays.
_Light_Heli_East = [];
_Heavy_Heli_East = [];
_Fixed_Wing_East = [];
_Light_Heli_West = [];
_Heavy_Heli_West = [];
_Fixed_Wing_West = [];
_Light_Heli_Guer = [];
_type = "";

sleep _delay;	// delay before spawning vehicle.


// array of available East Aircraft.
if (_side == East) then {

   if (_ArmaVersion == 0) then {
   _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU"];
   _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black"];
   _Fixed_Wing_East = ["Su25_INS","Su34","Su39"];
 };
   if (_ArmaVersion == 1) then {
   _Light_Heli_East = ["Mi17_TK_EP1","UH1H_TK_EP1"];
   _Heavy_Heli_East = ["Mi24_D_TK_EP1"];
   _Fixed_Wing_East = ["Su25_TK_EP1","L39_TK_EP1"];
 };
   if (_ArmaVersion == 2) then {
   _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU","Mi17_TK_EP1","UH1H_TK_EP1"];
   _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black","Mi24_D_TK_EP1"];
   _Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
 }; 
   if (_ArmaVersion == 3) then {
   _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU","Mi17_TK_EP1","UH1H_TK_EP1"];
   _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black","Mi24_D_TK_EP1"];
   _Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
 };
};

// array of available West Aircraft.
if (_side == West) then {

   if (_ArmaVersion == 0) then {
   _Light_Heli_West = ["MH60S","UH1Y"];
   _Heavy_Heli_West = ["AH1Z","AH64D"];
   _Fixed_Wing_West = ["A10","F35B","AV8B2"];
 };
   if (_ArmaVersion == 1) then {
   _Light_Heli_West = ["UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
   _Heavy_Heli_West = ["AH64D_EP1"];
   _Fixed_Wing_West = ["A10_US_EP1"];
 };
   if (_ArmaVersion == 2) then {
   _Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
   _Heavy_Heli_West = ["AH1Z","AH64D","AH64D_EP1"];
   _Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
 }; 
   if (_ArmaVersion == 3) then {
   _Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1","AW159_Lynx_BAF","BAF_Merlin_HC3_D","CH_47F_BAF"];
   _Heavy_Heli_West = ["AH1Z","AH64D","AH64D_EP1","BAF_Apache_AH1_D"];
   _Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
 };
};

// array of available Guer Aircraft.
if (_side == Resistance) then {

   if (_ArmaVersion == 1) then {
   _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1"];		
 };
   if (_ArmaVersion == 2) then {
   _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1"];
 }; 
   if (_ArmaVersion == 3) then {
   _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1","Ka60_GL_PMC","Ka60_PMC"];
 };
};

// select random vehicle based on side.
switch (_vehicletype) do {

   case "Heavy_Heli_WEST": {_type = _Heavy_Heli_West select floor (random count _Heavy_Heli_West)};
   case "Heavy_Heli_EAST": {_type = _Heavy_Heli_East select floor (random count _Heavy_Heli_East)};
   case "Light_Heli_WEST": {_type = _Light_Heli_West select floor (random count _Light_Heli_West)};
   case "Light_Heli_EAST": {_type = _Light_Heli_East select floor (random count _Light_Heli_East)};
   case "Fixed_Wing_WEST": {_type = _Fixed_Wing_West select floor (random count _Fixed_Wing_West)};
   case "Fixed_Wing_EAST": {_type = _Fixed_Wing_East select floor (random count _Fixed_Wing_East)};
   case "Light_Heli_GUER": {_type = _Light_Heli_Guer select floor (random count _Light_Heli_Guer)};
};

_grp = createGroup _side;									// create group.

if (_type isKindof "helicopter") then {								// type helicopters.
   for "_i" from 1 to _maxunits do {
   [_spwnpos, 180, _type, _grp] call BIS_fnc_spawnVehicle;					// create helicopters.
   _grp selectLeader ((units _grp) select 0);							// select leader.				
   _grpvehs = [];										// array to list all different vehicles in group.										
   _grpDir = getDir (vehicle (leader _grp));							// the direction of the leader or his vehicle.							

   {
_vehicle = vehicle _x; 									// the vehicle of the unit.							
if (_vehicle isKindOf "helicopter" AND !(_vehicle in _grpvehs)) then {			// if vehicle is of helicopter type and not in list.
	_grpvehs = _grpvehs + [_vehicle];						// add the vehicle to the list so we know it has been processed.
	_vehicle setDir _grpDir;							// set the group direction on the vehicle.
	_vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 150];	// set the height to 150.
	_vehicle setVelocity [sin (_grpDir) * 100, cos (_grpDir) * 100, 0];		// set speed to 100.
	_vehicle flyinheight 150;							// set vehicle to fly height.
	sleep 0.5;									// sleep needed so vehicles do not spawn on top of each other and crash.
};
   } foreach units _grp;
 };
};


if (_type isKindof "plane") then {								// type airplanes
   for "_i" from 1 to _maxunits do {
   [_spwnpos, 180, _type, _grp] call BIS_fnc_spawnVehicle;					// create airplanes
   _grp selectLeader ((units _grp) select 0);							// select leader
   _grpvehs = [];										// array to list all different vehicles in group.
   _grpDir = getDir (vehicle (leader _grp));							// the direction of the leader or his vehicle.

   {
_vehicle = vehicle _x; 									// the vehicle of the unit.
if (_vehicle isKindOf "plane" AND !(_vehicle in _grpvehs)) then {			// if vehicle is of plane type and not in list.
	_grpvehs = _grpvehs + [_vehicle];						// add the vehicle to the list so we know it has been processed.
	_vehicle setDir _grpDir;							// set the group direction on the vehicle.
	_vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 400];	// set the height to 400.
	_vehicle setVelocity [sin (_grpDir) * 150, cos (_grpDir) * 150, 0];  		// set speed to 150.
	_vehicle flyinheight 400;							// set vehicle to fly height.
	sleep 0.5;									// sleep needed so vehicles do not spawn on top of each other and crash.
     };
   } foreach units _grp;
 };
};

switch (_movetype) do {										// select move type.

   case "Patrol": {[_grp, _movepos, _distance] call bis_fnc_taskPatrol}; 			// Aircraft will cycle through waypoints.
   case "Attack": {[_grp, _movepos] call bis_fnc_taskAttack}; 					// Aircraft will SAD at designated position.

};

{ _x setBehaviour "COMBAT"; _x SetCombatMode "RED"; _x setSpeedMode "NORMAL"; } foreach units _grp;  // set group behavior.

// for debuging.
// hint format ["ArmA Version: %1\n Side: %2\n Type of Vehicle: %3\n # of units: %4\n Move Type: %5\n Waypoint Distance: %6\n  Delay: %7",_ArmaVersion, _side, typeof _vehicle, _maxUnits, _movetype, _distance, _delay];

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Haven't run the code but glad you got it working mate.

Are you structuring your code like that posted above or is it being reformatted when you copy it here? It's pretty messed up!

Would look better something like this....

_grp = createGroup _side;	//create group

//create helicopters
if (_type isKindof "helicopter") then {
   for "_i" from 1 to _maxunits do {
       [_spwnpos, 180, _type, _grp] call BIS_fnc_spawnVehicle;
       _grp selectLeader ((units _grp) select 0);
_grpvehs = [];
_grpDir = getDir (vehicle (leader _grp));

{
    _vehicle = vehicle _x;
    if (_vehicle isKindOf "helicopter" AND !(_vehicle in _grpvehs)) then {
        _grpvehs = _grpvehs + [_vehicle];
        _vehicle setDir _grpDir;
        _vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 150];
        _vehicle setVelocity [sin (_grpDir) * 100, cos (_grpDir) * 100, 0];
        _vehicle flyinheight 150;
        sleep 0.5;
           };
       } foreach units _grp;
   };
};

Share this post


Link to post
Share on other sites

Nope that is how Im structuring it, looks like I need to make some more changes. Thanks Twirly.

Share this post


Link to post
Share on other sites

Just easier to read for everyone. Enjoy Disneyland!

Share this post


Link to post
Share on other sites

Two problems:

1. I cannot get these vehicles to delete when destroyed or when they return to base, the problem that Im talking about is in red.

2. When the aircraft runs low on fuel or when the time on mission runs out aircraft should RTB by use of a waypoint and its not working, color is in blue.

Any ideas?

/*
   Random Aircraft Spawn: v.1.0
   Created by: cobra4v320 with Special Thanks to Twirly and Demonized for the help.

   Description: This will spawn in random aircraft based on side, the type of aircraft selected, and number of aircraft selected. The created vehicle(s) will either patrol or attack the selected position.

   Execute with:  _null = [West, "Heavy_Heli_WEST", 2, getmarkerpos "spawn", "Patrol", 10] execVM "RAS.sqf";

   	Parameter(s):
_this select 0: the side on which to spawn the vehicle.
_this select 1: the type of vehicle to be spawned.
_this select 2: the number of units to be spawned.
_this select 3: the position to spawn the vehicle.
_this select 4: the type of move either - Patrol or Attack.
*/

if (!isServer) exitWith {};

//Prepare variables
private ["_Light_Heli_East","_Heavy_Heli_East","_Fixed_Wing_East","_Light_Heli_West","_Heavy_Heli_West","_Fixed_Wing_West","_Light_Heli_Guer","_type","_newVehicle","_vehicle","_spwndir","_wp","_time","_ArmaVersion","_distance","_side","_vehicletype","_maxUnits","_spwnpos","_movetype","_delay","_mk1","_movepos","_gridPos","_grp"];

// EDIT THESE VARIABLES TO CUSTOMIZE RAS. //

_ArmaVersion = 0; // what version of Arma do you have installed. 	0 = arma2 only.		1 = OA only. 	2 = Arma2 and OA. 	3 = Arma2/OA and BAF/PMC.
_distance = 400; // distance between waypoints for patrol only.
_time = 180; // time the CAS will stay on mission before RTB.
delay = 0; // delay before spawning the aircraft.

// DO NOT MODIFY BELOW THIS LINE. //

if (CAS_Active) exitWith {hint format ["%1 CAS is already on mission!",_side]};

CAS_Active = true;
publicVariable "CAS_Active";

waituntil {!isnil "bis_fnc_init"};	// Is functions module ready?

_side = _this select 0;
_vehicletype = _this select 1;
_maxUnits = _this select 2;
_spwnpos = _this select 3;
_movetype = _this select 4;

if ((count _this) < 5) exitWith {hint "RAS.sqf script requires at least 5 parameters!"};	// Validate parameter count.
if ((count _this) > 5) then {_delay = _this select 5};

// initialize arrays.
_Light_Heli_East = [];
_Heavy_Heli_East = [];
_Fixed_Wing_East = [];
_Light_Heli_West = [];
_Heavy_Heli_West = [];
_Fixed_Wing_West = [];
_Light_Heli_Guer = [];
_type = "";

openMap true;

titleText ["(Left click) on the map where you want the vehicle to patrol.", "PLAIN"];

_mk1 = createMarker ["RAS_Marker", [0,0,0]];
"RAS_Marker" setMarkerShape "ICON";
"RAS_Marker" setMarkerType "hd_destroy";
"RAS_Marker" setMarkerColor "ColorRed";
"RAS_Marker" setMarkerText "Air Patrol Position";
onMapSingleClick {'RAS_Marker' setMarkerPos _pos, dropclick = true}; 
waitUntil {dropclick}; 
onMapSingleClick {}; 
dropclick = false;

_movepos = getmarkerpos "RAS_Marker";
_gridPos = mapGridPosition _movepos;
[West,"HQ"] sideChat format ["Coordinates received, %1 CAS is moving to position %2", _side, _gridPos];

sleep _delay;	// delay before spawning vehicle.

// array of available East Aircraft.
if (_side == East) then 
{
   if (_ArmaVersion == 0) then 
   {
       _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU"];
       _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black"];
       _Fixed_Wing_East = ["Su25_INS","Su34","Su39"];
   };
   if (_ArmaVersion == 1) then 
   {
       _Light_Heli_East = ["Mi17_TK_EP1","UH1H_TK_EP1"];
       _Heavy_Heli_East = ["Mi24_D_TK_EP1"];
       _Fixed_Wing_East = ["Su25_TK_EP1","L39_TK_EP1"];
   };
   if (_ArmaVersion == 2) then 
   {
       _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU","Mi17_TK_EP1","UH1H_TK_EP1"];
       _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black","Mi24_D_TK_EP1"];
       _Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
   }; 
   if (_ArmaVersion == 3) then 
   {
       _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU","Mi17_TK_EP1","UH1H_TK_EP1"];
       _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black","Mi24_D_TK_EP1"];
       _Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
   };
};

// array of available West Aircraft.
if (_side == West) then 
{
   if (_ArmaVersion == 0) then 
   {
       _Light_Heli_West = ["MH60S","UH1Y"];
       _Heavy_Heli_West = ["AH1Z","AH64D"];
       _Fixed_Wing_West = ["A10","F35B","AV8B2"];
   };
   if (_ArmaVersion == 1) then 
   {
      _Light_Heli_West = ["UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
      _Heavy_Heli_West = ["AH64D_EP1"];
      _Fixed_Wing_West = ["A10_US_EP1"];
   };
   if (_ArmaVersion == 2) then 
   {
       _Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
       _Heavy_Heli_West = ["AH1Z","AH64D","AH64D_EP1"];
       _Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
   }; 
   if (_ArmaVersion == 3) then 
   {
       _Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1","AW159_Lynx_BAF","BAF_Merlin_HC3_D","CH_47F_BAF"];
       _Heavy_Heli_West = ["AH1Z","AH64D","AH64D_EP1","BAF_Apache_AH1_D"];
       _Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
   };
};

// array of available Guer Aircraft.
if (_side == Resistance) then 
{
   if (_ArmaVersion == 0) exitWith
   {
       hint format ["%1 has no air support available.", _side]; deleteMarker "RAS_Marker"; CAS_Active = false; publicVariable "CAS_Active";		
   };
   if (_ArmaVersion == 1) then
   {
       _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1"];		
   };
   if (_ArmaVersion == 2) then 
   {
       _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1"];
   }; 
   if (_ArmaVersion == 3) then 
   {
       _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1","KA60_GL_PMC","KA60_PMC"];
   };
};

// select random vehicle based on type.
switch (_vehicletype) do 
{
   case "Heavy_Heli_WEST": 
   {
       _type = _Heavy_Heli_West select floor (random count _Heavy_Heli_West)
   };
   case "Heavy_Heli_EAST": 
   {
       _type = _Heavy_Heli_East select floor (random count _Heavy_Heli_East)
   };
   case "Light_Heli_WEST": 
   {
       _type = _Light_Heli_West select floor (random count _Light_Heli_West)
   };
   case "Light_Heli_EAST": 
   {
       _type = _Light_Heli_East select floor (random count _Light_Heli_East)
   };
   case "Fixed_Wing_WEST": 
   {
       _type = _Fixed_Wing_West select floor (random count _Fixed_Wing_West)
   };
   case "Fixed_Wing_EAST": 
   {
      _type = _Fixed_Wing_East select floor (random count _Fixed_Wing_East)
   };
   case "Light_Heli_GUER": 
   {
       _type = _Light_Heli_Guer select floor (random count _Light_Heli_Guer)
   };
};

_grp = createGroup _side;

if (_type isKindof "helicopter") then 
{
   for "_i" from 1 to _maxunits do 
   {
       _newVehicle = [_spwnpos, 180, _type, _grp] call BIS_fnc_spawnVehicle;					// creates the vehicle(s).
       _vehicle = _newvehicle select 0;											// select the vehicle from the array.				
       _vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 150];				// sets the vehicles start height.
       _spwndir = [_vehicle, _movepos] call BIS_fnc_relativeDirTo; 
_vehicle setdir _spwndir;
       _vehicle setVelocity [sin (_spwndir) * 80, cos (_spwndir) * 80, 0];					// sets the vehicles speed.
       _vehicle flyinheight 100;												// tells the vehicle to fly at an altitude.
       sleep 1;															// sleep so vehicles do not spawn on top of each other and crash.

   } foreach units _grp;
};

if (_type isKindof "plane") then 
{
   for "_i" from 1 to _maxunits do 
   {
       _newVehicle = [_spwnpos, 180, _type, _grp] call BIS_fnc_spawnVehicle;					// creates the vehicle(s).
       _vehicle = _newvehicle select 0;											// select the vehicle from the array.				
       _vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 400];				// sets the vehicles start height.
       _spwndir = [_vehicle, _movepos] call BIS_fnc_relativeDirTo; 
_vehicle setdir _spwndir;
       _vehicle setVelocity [sin (_spwndir) * 150, cos (_spwndir) * 150, 0];					// sets the vehicles speed.
       _vehicle flyinheight 400;												// tells the vehicle to fly at an altitude.
       sleep 1;															// sleep so vehicles do not spawn on top of each other and crash.

   } foreach units _grp;
};

switch (_movetype) do 
{										
   case "Patrol": // Aircraft will "Patrol" at designated position.
   {
    	private ["_prevPos"];
    	_prevPos = _movepos;
	for "_i" from 0 to (2 + (floor (random 3))) do
	{
		private ["_wp", "_newPos"];
		_newPos = [_prevPos, 50, _distance, 1, 0, 60 * (pi / 180), 0] call BIS_fnc_findSafePos;
		_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 "NORMAL";
				_wp setWaypointFormation "WEDGE";
			};
	};

	//Cycle back to the first position.
	private ["_wp"];
	_wp = _grp addWaypoint [_movepos, 0];
	_wp setWaypointType "CYCLE";
	_wp setWaypointCompletionRadius 20;
   };
   case "Attack": // Aircraft will "SAD" at designated position.
   {
       private ["_wp"];
      	_wp = _grp addWaypoint [_movepos, 100];
	_wp setWaypointType "SAD";
	_wp setWaypointSpeed "NORMAL";
	_wp setWaypointFormation "WEDGE";
   }; 					
};

{_x setBehaviour "COMBAT"; _x SetCombatMode "RED"; _x setSpeedMode "NORMAL"} foreach (units _grp);  // set group behavior.

while {{alive _x} count (units _grp) != 0} do
{
if ({alive _x} count (units _grp) == 0) then
{
	[West,"HQ"] sideChat format ["%1 CAS has been destroyed!", _side];		// sends radio message.
	deleteMarker "RAS_Marker";									// deletes the marker.
	[color="Red"]{deleteVehicle _x} foreach (crew _vehicle) + [_vehicle];				// deletes units and vehicles.	
	deleteGroup _grp;[/color]											// deletes the group.
};
if ((fuel _vehicle) <= 0.4 or _time == 0) then
{
	[West,"HQ"] sideChat format ["%1 CAS is returning to base.",_side];
[color="Blue"]		_wp = _grp addWaypoint [_spwnpos, 100];
	_wp setWaypointType "MOVE";
	_wp setWaypointBehaviour "CARELESS";[/color]
	_wp setWaypointStatements ["true", "[color="Red"]{deleteVehicle _x} foreach (crew _vehicle)+[_vehicle]; deleteGroup _grp; deleteMarker 'RAS_Marker'[/color] "];
};
_time = _time - 1;
sleep 1;
};

CAS_Active = false;
publicVariable "CAS_Active";

Edited by cobra4v320

Share this post


Link to post
Share on other sites

1: you cannot use local variables directly into setWaypointStatements lines, use format or replace with the allround (vehicle this), (crew (vehicle this)) etc..

also i think you need to setPos the crew out of the vehicle before deleting them, a simple _x setPos (getPos _x); deleteVehicle _x works fine.

2: maybe you just need to activate that waypoint with setCurrentWaypoint.

or the use of local variables messed it up all together.

Share this post


Link to post
Share on other sites
2: maybe you just need to activate that waypoint with setCurrentWaypoint.

Doohhhh (face palm).

/*
   Random Aircraft Spawn: v.1.0
   Created by: cobra4v320 with Special Thanks to Twirly and Demonized for the help.

   Description: This will spawn in random aircraft based on side, the type of aircraft selected, and number of aircraft selected. The created vehicle(s) will either patrol or attack the selected position.

   Execute with:  _null = [West, "Heavy_Heli_WEST", 2, getmarkerpos "spawn", "Patrol", 10] execVM "RAS.sqf";

   	Parameter(s):
_this select 0: the side on which to spawn the vehicle.
_this select 1: the type of vehicle to be spawned.
_this select 2: the number of units to be spawned.
_this select 3: the position to spawn the vehicle.
_this select 4: the type of move either - Patrol or Attack.
*/

if (!isServer) exitWith {}; // only run on the server.
if (isnil "bis_fnc_init") then {hint "RAS.sqf script requires functions module."}; // send debug message if functions module is not in game.

waituntil {!isnil "bis_fnc_init"};	// Is functions module ready?

//Prepare variables
private ["_Light_Heli_East","_Heavy_Heli_East","_Fixed_Wing_East","_Light_Heli_West","_Heavy_Heli_West","_Fixed_Wing_West","_Light_Heli_Guer","_type","_newVehicle","_vehicle","_spwndir","_wp","_time","_ArmaVersion","_distance","_side","_vehicletype","_maxUnits","_spwnpos","_movetype","_delay","_mk1","_movepos","_gridPos","_grp"];

////// EDIT THESE VARIABLES TO CUSTOMIZE RAS. //////

_ArmaVersion = 0; // what version of Arma do you have installed. 	0 = arma2 only.		1 = OA only. 	2 = Arma2 and OA. 	3 = Arma2/OA and BAF/PMC.
_distance = 500; // distance between waypoints for patrol only.
_time = 80; // time the CAS will stay on mission before RTB.
delay = 0; // delay before spawning the aircraft.

////// DO NOT MODIFY BELOW THIS LINE. //////

if (CAS_Active) exitWith {hint format ["%1 CAS is already on mission!",_side]};

_side = _this select 0;
_vehicletype = _this select 1;
_maxUnits = _this select 2;
_spwnpos = _this select 3;
_movetype = _this select 4;

if ((count _this) < 5) exitWith {hint "RAS.sqf script requires at least 5 parameters!"};	// Validate parameter count.
if ((count _this) > 5) then {_delay = _this select 5};

// initialize arrays.
_Light_Heli_East = [];
_Heavy_Heli_East = [];
_Fixed_Wing_East = [];
_Light_Heli_West = [];
_Heavy_Heli_West = [];
_Fixed_Wing_West = [];
_Light_Heli_Guer = [];
_type = "";

CAS_Active = true;
publicVariable "CAS_Active";

openMap true;

titleText ["(Left click) on the map where you want the vehicle to patrol.", "PLAIN"];

_mk1 = createMarker ["RAS_Marker", [0,0,0]];
"RAS_Marker" setMarkerShape "ICON";
"RAS_Marker" setMarkerType "hd_destroy";
"RAS_Marker" setMarkerColor "ColorRed";
"RAS_Marker" setMarkerText "Air Patrol Position";
onMapSingleClick {'RAS_Marker' setMarkerPos _pos, dropclick = true}; 
waitUntil {dropclick}; 
onMapSingleClick {}; 
dropclick = false;

_movepos = getmarkerpos "RAS_Marker";
_gridPos = mapGridPosition _movepos;
[West,"HQ"] sideChat format ["Coordinates received, %1 CAS is moving to position %2", _side, _gridPos];

sleep _delay;	// delay before spawning vehicle.

// array of available East Aircraft.
if (_side == East) then 
{
   if (_ArmaVersion == 0) then 
   {
       _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU"];
       _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black"];
       _Fixed_Wing_East = ["Su25_INS","Su34","Su39"];
   };
   if (_ArmaVersion == 1) then 
   {
       _Light_Heli_East = ["Mi17_TK_EP1","UH1H_TK_EP1"];
       _Heavy_Heli_East = ["Mi24_D_TK_EP1"];
       _Fixed_Wing_East = ["Su25_TK_EP1","L39_TK_EP1"];
   };
   if (_ArmaVersion == 2) then 
   {
       _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU","Mi17_TK_EP1","UH1H_TK_EP1"];
       _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black","Mi24_D_TK_EP1"];
       _Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
   }; 
   if (_ArmaVersion == 3) then 
   {
       _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU","Mi17_TK_EP1","UH1H_TK_EP1"];
       _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black","Mi24_D_TK_EP1"];
       _Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
   };
};

// array of available West Aircraft.
if (_side == West) then 
{
   if (_ArmaVersion == 0) then 
   {
       _Light_Heli_West = ["MH60S","UH1Y"];
       _Heavy_Heli_West = ["AH1Z","AH64D"];
       _Fixed_Wing_West = ["A10","F35B","AV8B2"];
   };
   if (_ArmaVersion == 1) then 
   {
      _Light_Heli_West = ["UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
      _Heavy_Heli_West = ["AH64D_EP1"];
      _Fixed_Wing_West = ["A10_US_EP1"];
   };
   if (_ArmaVersion == 2) then 
   {
       _Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
       _Heavy_Heli_West = ["AH1Z","AH64D","AH64D_EP1"];
       _Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
   }; 
   if (_ArmaVersion == 3) then 
   {
       _Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1","AW159_Lynx_BAF","BAF_Merlin_HC3_D","CH_47F_BAF"];
       _Heavy_Heli_West = ["AH1Z","AH64D","AH64D_EP1","BAF_Apache_AH1_D"];
       _Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
   };
};

// array of available Guer Aircraft.
if (_side == Resistance) then 
{
   if (_ArmaVersion == 0) exitWith
   {
       hint format ["%1 has no air support available.", _side]; deleteMarker "RAS_Marker"; CAS_Active = false; publicVariable "CAS_Active";		
   };
   if (_ArmaVersion == 1) then
   {
       _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1"];		
   };
   if (_ArmaVersion == 2) then 
   {
       _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1"];
   }; 
   if (_ArmaVersion == 3) then 
   {
       _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1","KA60_GL_PMC","KA60_PMC"];
   };
};

// select random vehicle based on type.
switch (_vehicletype) do 
{
   case "Heavy_Heli_WEST": 
   {
       _type = _Heavy_Heli_West select floor (random count _Heavy_Heli_West)
   };
   case "Heavy_Heli_EAST": 
   {
       _type = _Heavy_Heli_East select floor (random count _Heavy_Heli_East)
   };
   case "Light_Heli_WEST": 
   {
       _type = _Light_Heli_West select floor (random count _Light_Heli_West)
   };
   case "Light_Heli_EAST": 
   {
       _type = _Light_Heli_East select floor (random count _Light_Heli_East)
   };
   case "Fixed_Wing_WEST": 
   {
       _type = _Fixed_Wing_West select floor (random count _Fixed_Wing_West)
   };
   case "Fixed_Wing_EAST": 
   {
      _type = _Fixed_Wing_East select floor (random count _Fixed_Wing_East)
   };
   case "Light_Heli_GUER": 
   {
       _type = _Light_Heli_Guer select floor (random count _Light_Heli_Guer)
   };
};

_grp = createGroup _side;

if (_type isKindof "helicopter") then 
{
   for "_i" from 1 to _maxunits do 
   {
       _newVehicle = [_spwnpos, 180, _type, _grp] call BIS_fnc_spawnVehicle;					// creates the vehicle(s).
       _vehicle = _newvehicle select 0;											// select the vehicle from the array.				
       _vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 150];				// sets the vehicles start height.
       _spwndir = [_vehicle, _movepos] call BIS_fnc_relativeDirTo; 
  _vehicle setdir _spwndir;
       _vehicle setVelocity [sin (_spwndir) * 80, cos (_spwndir) * 80, 0];					// sets the vehicles speed.
       _vehicle flyinheight 100;												// tells the vehicle to fly at an altitude.
       _vehicle setfuel 1;
       sleep 1;															// sleep so vehicles do not spawn on top of each other and crash.

   } foreach units _grp;
};

if (_type isKindof "plane") then 
{
   for "_i" from 1 to _maxunits do 
   {
       _newVehicle = [_spwnpos, 180, _type, _grp] call BIS_fnc_spawnVehicle;					// creates the vehicle(s).
       _vehicle = _newvehicle select 0;											// select the vehicle from the array.				
       _vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 400];				// sets the vehicles start height.
       _spwndir = [_vehicle, _movepos] call BIS_fnc_relativeDirTo; 
  _vehicle setdir _spwndir;
       _vehicle setVelocity [sin (_spwndir) * 150, cos (_spwndir) * 150, 0];					// sets the vehicles speed.
       _vehicle flyinheight 400;												// tells the vehicle to fly at an altitude.
       sleep 1;															// sleep so vehicles do not spawn on top of each other and crash.

   } foreach units _grp;
};

switch (_movetype) do 
{										
   case "Patrol": // Aircraft will "Patrol" at designated position.
   {
    	private ["_prevPos"];
    	_prevPos = _movepos;
	for "_i" from 0 to (2 + (floor (random 3))) do
	{
		private ["_wp", "_newPos"];
		_newPos = [_prevPos, 50, _distance, 1, 0, 60 * (pi / 180), 0] call BIS_fnc_findSafePos;
		_prevPos = _newPos;

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

		//Set the group's speed and formation at the first waypoint.
			if (_i == 0) then
			{
				_wp setWaypointSpeed "NORMAL";
				_wp setWaypointFormation "WEDGE";
				_wp setWaypointBehaviour "AWARE";
				_wp setWaypointCombatMode "RED";

			};
	};

	//Cycle back to the first position.
	private ["_wp"];
	_wp = _grp addWaypoint [_movepos, 0];
	_wp setWaypointType "CYCLE";
	_wp setWaypointCompletionRadius 50;
   };
   case "Attack": // Aircraft will "SAD" at designated position.
   {
       private ["_wp"];
      	_wp = _grp addWaypoint [_movepos, 50];
	_wp setWaypointType "SAD";
	_wp setWaypointSpeed "NORMAL";
	_wp setWaypointFormation "WEDGE";
	_wp setWaypointBehaviour "COMAT";

	_grp setCurrentWaypoint _wp;
   }; 					
};

while {{alive _x} count (units _grp) != 0} do
{
if ({alive _x} count (units _grp) == 0) then
{
	[West,"HQ"] sideChat format ["%1 CAS has been destroyed!", _side];		// sends radio message.
	deleteMarker "RAS_Marker";									// deletes the marker.
	{deleteVehicle _x} foreach (crew _vehicle) + [_vehicle];				// deletes units and vehicles.	
	deleteGroup _grp;											// deletes the group.
};
if ((fuel _vehicle) <= 0.4 or _time == 0) then
{
	[West,"HQ"] sideChat format ["%1 CAS is returning to base.",_side];
	_wp = _grp addWaypoint [_spwnpos, 100];
	_wp setWaypointType "MOVE";
	_wp setWaypointBehaviour "CARELESS";
	_wp setWaypointStatements 
	[
		"true", "{_x setPos (getPos _x); deleteVehicle _x} foreach (crew(vehicle this)) + [vehicle this]; deleteGroup _grp; deleteMarker 'RAS_Marker'"
   		];
	_grp setCurrentWaypoint _wp;
};
_time = _time - 1;
sleep 1;
};

CAS_Active = false;
publicVariable "CAS_Active";

So when I use this it only deletes one of the helicopters and crew but not both:

{_x setPos (getPos _x); deleteVehicle _x} foreach (crew (vehicle this)) + [vehicle this]

Thanks Demonized.

---------- Post added at 07:41 PM ---------- Previous post was at 05:50 PM ----------

Okay another issue that Im having is during the while loop, its not executing this part of the script below when the group == 0. I would also like to use the getdammage command in this first statement but that is not working either.

while {{alive _x} count (units _grp) != 0} do
{
[color="Red"]	if ({alive _x} count (units _grp) == 0 or (getdammage _vehicle) >= 0.7) then
{
	[West,"HQ"] sideChat format ["%1 CAS has been destroyed!", _side];		// sends radio message.
	deleteMarker "RAS_Marker";									// deletes the marker.
	{deleteVehicle _x} foreach (crew _vehicle) + [_vehicle];				// deletes units and vehicles.	
	deleteGroup _grp;											// deletes the group.
};[/color]
if ((fuel _vehicle) <= 0.4 or _time == 0) then
{
	[West,"HQ"] sideChat format ["%1 CAS is returning to base.",_side];
	_wp = _grp addWaypoint [_spwnpos, 100];
	_wp setWaypointType "MOVE";
	_wp setWaypointBehaviour "CARELESS";
	_wp setWaypointStatements 
	[
		"true", "{_x setPos (getPos _x); deleteVehicle _x} foreach (crew(vehicle this)) + [vehicle this]; deleteGroup _grp; deleteMarker 'RAS_Marker'"
   		];
	_grp setCurrentWaypoint _wp;
};
_time = _time - 1;
sleep 1;
};

Edited by cobra4v320

Share this post


Link to post
Share on other sites

I have the vehicles all deleteing now using a separate script:

deleteGroup.sqf

_group = group _this; //Retrive the group from the squad leader (trigger activator)
{
  if (_x != vehicle _x && driver (vehicle _x) == _x) then
  { //the unit is in a vehicle (other than its own body) and is the driver
     deleteVehicle (vehicle _x); //delete the unit's vehicle
  };

  deleteVehicle _x; //delete the unit

} forEach units _group; //for every member of the group

deleteGroup _group; //delete the now empty group

New RAS.sqf (still a WIP)

/*
   Random Aircraft Spawn: v.1.0
   Created by: cobra4v320 with Special Thanks to Twirly and Demonized for the help.

   Description: This will spawn in random aircraft based on side, the type of aircraft selected, and number of aircraft selected. The created vehicle(s) will either patrol or attack the selected position.

   Execute with:  _null = [West, "Heavy_Heli_WEST", 2, getmarkerpos "spawn", "Patrol", 10] execVM "RAS.sqf";

   	Parameter(s):
_this select 0: the side on which to spawn the vehicle.
_this select 1: the type of vehicle to be spawned.
_this select 2: the number of units to be spawned.
_this select 3: the position to spawn the vehicle.
_this select 4: the type of move either - Patrol or Attack.
*/

if (!isServer) exitWith {}; // only run on the server.
if (isnil "bis_fnc_init") then {hint "RAS.sqf script requires functions module."}; // send debug message if functions module is not in game.

waituntil {!isnil "bis_fnc_init"};	// Is functions module ready?

//Prepare variables
private ["_side","_delay","_Light_Heli_East","_Heavy_Heli_East","_Fixed_Wing_East","_Light_Heli_West","_Heavy_Heli_West","_Fixed_Wing_West","_Light_Heli_Guer","_type","_newVehicle","_vehicle","_spwndir","_wp","_time","_ArmaVersion","_distance","_vehicletype","_maxUnits","_spwnpos","_movetype","_mk1","_movepos","_gridPos","_grp"];

////// EDIT THESE VARIABLES TO CUSTOMIZE RAS. //////

_ArmaVersion = 0; // what version of Arma do you have installed. 	0 = arma2 only.		1 = OA only. 	2 = Arma2 and OA. 	3 = Arma2/OA and BAF/PMC.
_distance = 500; // distance between waypoints for patrol only.
_time = 600; // time the CAS will stay on mission before RTB.
_delay = 0; // delay before spawning the aircraft.

////// DO NOT MODIFY BELOW THIS LINE. //////

if (CAS_Active) exitWith {hint format ["%1 CAS is already on mission!",_side]};

_side = _this select 0;
_vehicletype = _this select 1;
_maxUnits = _this select 2;
_spwnpos = _this select 3;
_movetype = _this select 4;

if ((count _this) < 5) exitWith {hint "RAS.sqf script requires at least 5 parameters!"};	// Validate parameter count.
if ((count _this) > 5) then {_delay = _this select 5};

// initialize arrays.
_Light_Heli_East = [];
_Heavy_Heli_East = [];
_Fixed_Wing_East = [];
_Light_Heli_West = [];
_Heavy_Heli_West = [];
_Fixed_Wing_West = [];
_Light_Heli_Guer = [];
_type = "";

CAS_Active = true;
publicVariable "CAS_Active";

openMap true;

titleText ["(Left click) on the map where you want the vehicle to patrol.", "PLAIN"];

_mk1 = createMarker ["RAS_Marker", [0,0,0]];
"RAS_Marker" setMarkerShape "ICON";
"RAS_Marker" setMarkerType "hd_destroy";
"RAS_Marker" setMarkerColor "ColorRed";
"RAS_Marker" setMarkerText "Air Patrol Position";
onMapSingleClick {'RAS_Marker' setMarkerPos _pos, dropclick = true}; 
waitUntil {dropclick}; 
onMapSingleClick {}; 
dropclick = false;

_movepos = getmarkerpos "RAS_Marker";
_gridPos = mapGridPosition _movepos;
[_side,"HQ"] sideChat format ["Coordinates received, %1 CAS is moving to position %2", _side, _gridPos];

sleep _delay;	// delay before spawning vehicle.

// array of available East Aircraft.
if (_side == East) then 
{
   if (_ArmaVersion == 0) then 
   {
       _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU"];
       _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black"];
       _Fixed_Wing_East = ["Su25_INS","Su34","Su39"];
   };
   if (_ArmaVersion == 1) then 
   {
       _Light_Heli_East = ["Mi17_TK_EP1","UH1H_TK_EP1"];
       _Heavy_Heli_East = ["Mi24_D_TK_EP1"];
       _Fixed_Wing_East = ["Su25_TK_EP1","L39_TK_EP1"];
   };
   if (_ArmaVersion == 2) then 
   {
       _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU","Mi17_TK_EP1","UH1H_TK_EP1"];
       _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black","Mi24_D_TK_EP1"];
       _Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
   }; 
   if (_ArmaVersion == 3) then 
   {
       _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU","Mi17_TK_EP1","UH1H_TK_EP1"];
       _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black","Mi24_D_TK_EP1"];
       _Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
   };
};

// array of available West Aircraft.
if (_side == West) then 
{
   if (_ArmaVersion == 0) then 
   {
       _Light_Heli_West = ["MH60S","UH1Y"];
       _Heavy_Heli_West = ["AH1Z","AH64D"];
       _Fixed_Wing_West = ["A10","F35B","AV8B2"];
   };
   if (_ArmaVersion == 1) then 
   {
      _Light_Heli_West = ["UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
      _Heavy_Heli_West = ["AH64D_EP1"];
      _Fixed_Wing_West = ["A10_US_EP1"];
   };
   if (_ArmaVersion == 2) then 
   {
       _Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
       _Heavy_Heli_West = ["AH1Z","AH64D","AH64D_EP1"];
       _Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
   }; 
   if (_ArmaVersion == 3) then 
   {
       _Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1","AW159_Lynx_BAF","BAF_Merlin_HC3_D","CH_47F_BAF"];
       _Heavy_Heli_West = ["AH1Z","AH64D","AH64D_EP1","BAF_Apache_AH1_D"];
       _Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
   };
};

// array of available Guer Aircraft.
if (_side == Resistance) then 
{
   if (_ArmaVersion == 0) exitWith
   {
       hint format ["%1 has no air support available.", _side]; deleteMarker "RAS_Marker"; CAS_Active = false; publicVariable "CAS_Active";		
   };
   if (_ArmaVersion == 1) then
   {
       _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1"];		
   };
   if (_ArmaVersion == 2) then 
   {
       _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1"];
   }; 
   if (_ArmaVersion == 3) then 
   {
       _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1","KA60_GL_PMC","KA60_PMC"];
   };
};

// select random vehicle based on type.
switch (_vehicletype) do 
{
   case "Heavy_Heli_WEST": 
   {
       _type = _Heavy_Heli_West select floor (random count _Heavy_Heli_West)
   };
   case "Heavy_Heli_EAST": 
   {
       _type = _Heavy_Heli_East select floor (random count _Heavy_Heli_East)
   };
   case "Light_Heli_WEST": 
   {
       _type = _Light_Heli_West select floor (random count _Light_Heli_West)
   };
   case "Light_Heli_EAST": 
   {
       _type = _Light_Heli_East select floor (random count _Light_Heli_East)
   };
   case "Fixed_Wing_WEST": 
   {
       _type = _Fixed_Wing_West select floor (random count _Fixed_Wing_West)
   };
   case "Fixed_Wing_EAST": 
   {
      _type = _Fixed_Wing_East select floor (random count _Fixed_Wing_East)
   };
   case "Light_Heli_GUER": 
   {
       _type = _Light_Heli_Guer select floor (random count _Light_Heli_Guer)
   };
};

_grp = createGroup _side;

if (_type isKindof "helicopter") then 
{
   for "_i" from 1 to _maxunits do 
   {
  _newVehicle = [_spwnpos, 180, _type, _grp] call BIS_fnc_spawnVehicle;					// creates the vehicle(s).
       _vehicle = _newVehicle select 0;											// select the vehicle from the array.				
       _vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 150];				// sets the vehicles start height.
       _spwndir = [_vehicle, _movepos] call BIS_fnc_relativeDirTo; 
  _vehicle setdir _spwndir;
       _vehicle setVelocity [sin (_spwndir) * 80, cos (_spwndir) * 80, 0];					// sets the vehicles speed.
       _vehicle flyinheight 100;												// tells the vehicle to fly at an altitude.
       sleep 1;															// sleep so vehicles do not spawn on top of each other and crash.

   } foreach (units _grp);
};

if (_type isKindof "plane") then 
{
   for "_i" from 1 to _maxunits do 
   {
       _newVehicle = [_spwnpos, 180, _type, _grp] call BIS_fnc_spawnVehicle;					// creates the vehicle(s).
       _vehicle = _newvehicle select 0;											// select the vehicle from the array.				
       _vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 400];				// sets the vehicles start height.
       _spwndir = [_vehicle, _movepos] call BIS_fnc_relativeDirTo; 
  _vehicle setdir _spwndir;
       _vehicle setVelocity [sin (_spwndir) * 150, cos (_spwndir) * 150, 0];					// sets the vehicles speed.
       _vehicle flyinheight 400;												// tells the vehicle to fly at an altitude.
       sleep 1;															// sleep so vehicles do not spawn on top of each other and crash.

   } foreach (units _grp);
};

_grp selectLeader ((units _grp) select 0);
_leader = leader _grp;

Varray = []; 
{if !((vehicle _x) in Varray) then {Varray = Varray + [vehicle _x]}} foreach (units _grp); 
vehicleCount = "air" countType Varray;

switch (_movetype) do 
{										
   case "Patrol": // Aircraft will "Patrol" at designated position.
   {
    	private ["_prevPos"];
    	_prevPos = _movepos;
	for "_i" from 0 to (2 + (floor (random 3))) do
	{
		private ["_wp", "_newPos"];
		_newPos = [_prevPos, 50, _distance, 1, 0, 60 * (pi / 180), 0] call BIS_fnc_findSafePos;
		_prevPos = _newPos;

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

		//Set the group's speed and formation at the first waypoint.
			if (_i == 0) then
			{
				_wp setWaypointSpeed "NORMAL";
				_wp setWaypointFormation "WEDGE";
				_wp setWaypointBehaviour "AWARE";
				_wp setWaypointCombatMode "RED";

			};
	};

	//Cycle back to the first position.
	private ["_wp"];
	_wp = _grp addWaypoint [_movepos, 0];
	_wp setWaypointType "CYCLE";
	_wp setWaypointCompletionRadius 50;
   };
   case "Attack": // Aircraft will "SAD" at designated position.
   {
       private ["_wp"];
      	_wp = _grp addWaypoint [_movepos, 50];
	_wp setWaypointType "SAD";
	_wp setWaypointSpeed "NORMAL";
	_wp setWaypointFormation "WEDGE";
	_wp setWaypointBehaviour "COMAT";
	_grp setCurrentWaypoint _wp;
   }; 					
};

while {{alive _x} count (units _grp) != 0} do
{
[color="Red"]if (vehicleCount == 0) then
{
	[_side,"HQ"] sideChat format ["%1 CAS has been destroyed!", _side];		// sends radio message.
	deleteMarker "RAS_Marker";									// deletes the marker.
	{if (_x != vehicle _x && driver (vehicle _x) == _x) then {deleteVehicle (vehicle _x)}; deleteVehicle _x} forEach units _grp; deleteGroup _grp;	// deletes units and vehicles.	
};[/color]
if ((fuel _vehicle) <= 0.4 or _time == 0) then
{
	[_side,"HQ"] sideChat format ["%1 CAS is returning to base.",_side];
	_wp = _grp addWaypoint [_spwnpos, 100];
	_wp setWaypointType "MOVE";
	_wp setWaypointBehaviour "CARELESS";
	_wp setWaypointStatements ["true", "[color="Lime"]this execVM 'deleteGroup.sqf';[/color] deleteMarker 'RAS_Marker'"];
	_grp setCurrentWaypoint _wp;
};
_time = _time - 1;
sleep 1;
};

CAS_Active = false;
publicVariable "CAS_Active";

I still have an issue with the lines in red. It is not executing that part of the script when the vehicles are destroyed. I was trying {alive _x} count (units _grp) == 0 and that was not working either.

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Can anyone throw me a bone here? :confused:

The part of the script that does not work is below, I have been testing for several hours and cannot figure this part out. What in red is where the issue is, after the group gets below 1 unit alive it should deletemarker, send a radio message then delete the units and the group (not in the script yet).

while { {alive _x} count (units _grp) > 1} do
{
[color="Red"]	if ( {alive _x} count (units _grp) <= 1 ) then
{
	[_side,"HQ"] sideChat format ["%1 CAS has been destroyed!", _side];		// sends radio message.
	deleteMarker "RAS_Marker";									// deletes the marker.	
               //delete vehicle and delete group stuff goes here.
};[/color]
if ((fuel _vehicle) <= 0.4 or _time == 0) then
{
	[_side,"HQ"] sideChat format ["%1 CAS is returning to base.",_side];
	_wp = _grp addWaypoint [_spwnpos, 100];
	_wp setWaypointType "MOVE";
	_wp setWaypointBehaviour "CARELESS";
	_wp setWaypointStatements ["true", "this execVM 'deleteGroup.sqf'; deleteMarker 'RAS_Marker'"];
	_grp setCurrentWaypoint _wp;
};
_time = _time - 1;
sleep 1;
};

Share this post


Link to post
Share on other sites

Okay so I have everything working except for one part, where I spawn in another script listed in red. I want this part of the script to exit when either the time on mission runs out or when both aircraft are destroyed. My first time messing with the spawn inside of a script, Im guessing the problem has something to do with the mission scope?

/*
   Random Aircraft Spawn: v.1.0
   Created by: cobra4v320 with Special Thanks to Twirly and Demonized for the help.

   Description: This will spawn in random aircraft based on side, the type of aircraft selected, and number of aircraft selected. The created vehicle(s) will either patrol or attack the selected position.

   Execute with:  _null = [West, "Heavy_Heli_WEST", getmarkerpos "spawn", "Patrol", 10] execVM "RAS.sqf";

   	Parameter(s):
_this select 0: the side on which to spawn the vehicle.
_this select 1: the type of vehicle to be spawned.
_this select 2: the position to spawn the vehicle.
_this select 3: the type of move either - Patrol or Attack.
*/

// Only run on the server everybody else exit.
if (!isServer) exitWith {};

// Is functions module ready?
waituntil {!isnil "bis_fnc_init"};

//Prepare variables
private ["_spwnPos","_moveType","_delay","_Light_Heli_East","_Heavy_Heli_East","_Fixed_Wing_East","_Light_Heli_West","_Heavy_Heli_West","_Fixed_Wing_West","_Light_Heli_Guer","_type","_newAircraft1","_aircraft1","_spwnDir","_newAircraft2","_aircraft2","_wp","_ArmaVersion","_distance","_time","_side","_vehicletype","_mk1","_movePos","_gridPos","_grp"];

////// EDIT THESE VARIABLES TO CUSTOMIZE RAS. //////
_ArmaVersion = 0; // What version of Arma do you have installed. 	0 = arma2 only.		1 = OA only. 	2 = Arma2 and OA. 	3 = Arma2/OA and BAF/PMC.
_distance = 600; // Distance between waypoints - patrol only.
_time = 600; // Time the CAS will stay on mission before RTB.
_delay = 0; // Delay before spawning the aircraft.

////// DO NOT MODIFY BELOW THIS LINE. //////
_side = _this select 0;
_vehicletype = _this select 1;
if (count _this > 2) then {_spwnPos = _this select 2} else {_spwnPos = (getPos Player)};
if (count _this > 3) then {_moveType = _this select 3} else {_moveType = "Patrol"};
if (count _this > 4) then {_delay = _this select 4};

// Exits the script if it is already running.
if (CAS_Active) exitWith {[_side,"HQ"] sideChat format ["%1 CAS is already on mission!",_side]};

// Tells everyone that the script is active.
CAS_Active = true;
publicVariable "CAS_Active";

// Initialize the arrays.
_Light_Heli_East = [];
_Heavy_Heli_East = [];
_Fixed_Wing_East = [];
_Light_Heli_West = [];
_Heavy_Heli_West = [];
_Fixed_Wing_West = [];
_Light_Heli_Guer = [];
_type = "";

titleText ["(Left click) on the map where you want the vehicle to patrol.", "PLAIN"];

// Creates the marker where the aircraft will move to. 
_mk1 = createMarkerLocal ["RAS_Marker", [0,0,0]];
_mk1 setMarkerShapeLocal "ICON";
_mk1 setMarkerTypeLocal "hd_destroy";
_mk1 setMarkerColorLocal "ColorRed";
_mk1 setMarkerTextLocal "Close Air Support";

// When you click on the map it will place the new marker at that location.
onMapSingleClick {'RAS_Marker' setMarkerPosLocal _pos, dropClick = true}; 
waitUntil {dropClick}; 
onMapSingleClick {}; 
dropClick = false;

_movePos = getmarkerpos "RAS_Marker";

// Used below in sidechat to give the grid coordinates of the new marker location.
_gridPos = mapGridPosition _movePos;
[_side,"HQ"] sideChat format ["Coordinates received, %1 CAS is moving to position %2", _side, _gridPos];
// Waits until player closes map before spawning the aircraft.
waitUntil{!visibleMap};
// Closes the title text from above.
titleText ["", "PLAIN"];

// Delay before spawning vehicle.
sleep _delay;

// Array of available East Aircraft.
if (_side == East) then 
{
   if (_ArmaVersion == 0) then 
   {
       _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU"];
       _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black"];
       _Fixed_Wing_East = ["Su25_INS","Su34","Su39"];
   };
   if (_ArmaVersion == 1) then 
   {
       _Light_Heli_East = ["Mi17_TK_EP1","UH1H_TK_EP1"];
       _Heavy_Heli_East = ["Mi24_D_TK_EP1"];
       _Fixed_Wing_East = ["Su25_TK_EP1","L39_TK_EP1"];
   };
   if (_ArmaVersion == 2) then 
   {
       _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU","Mi17_TK_EP1","UH1H_TK_EP1"];
       _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black","Mi24_D_TK_EP1"];
       _Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
   }; 
   if (_ArmaVersion == 3) then 
   {
       _Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU","Mi17_TK_EP1","UH1H_TK_EP1"];
       _Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black","Mi24_D_TK_EP1"];
       _Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
   };
};

// Array of available West Aircraft.
if (_side == West) then 
{
   if (_ArmaVersion == 0) then 
   {
       _Light_Heli_West = ["MH60S","UH1Y"];
       _Heavy_Heli_West = ["AH1Z","AH64D"];
       _Fixed_Wing_West = ["A10","F35B","AV8B2"];
   };
   if (_ArmaVersion == 1) then 
   {
      _Light_Heli_West = ["UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
      _Heavy_Heli_West = ["AH64D_EP1"];
      _Fixed_Wing_West = ["A10_US_EP1"];
   };
   if (_ArmaVersion == 2) then 
   {
       _Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
       _Heavy_Heli_West = ["AH1Z","AH64D","AH64D_EP1"];
       _Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
   }; 
   if (_ArmaVersion == 3) then 
   {
       _Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1","AW159_Lynx_BAF","BAF_Merlin_HC3_D","CH_47F_BAF"];
       _Heavy_Heli_West = ["AH1Z","AH64D","AH64D_EP1","BAF_Apache_AH1_D"];
       _Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
   };
};

// Array of available Guer Aircraft.
if (_side == Resistance) then 
{
   if (_ArmaVersion == 0) exitWith
   {
       [_side,"HQ"] sideChat format ["%1 has no air support available.", _side]; deleteMarkerLocal "RAS_Marker"; CAS_Active = false; publicVariable "CAS_Active";		
   };
   if (_ArmaVersion == 1) then
   {
       _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1"];		
   };
   if (_ArmaVersion == 2) then 
   {
       _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1"];
   }; 
   if (_ArmaVersion == 3) then 
   {
       _Light_Heli_Guer = ["Mi17_UN_CDF_EP1","UH1H_TK_GUE_EP1","KA60_GL_PMC","KA60_PMC"];
   };
};

// Select random vehicle based on type selected above.
switch (_vehicletype) do 
{
   case "Heavy_Heli_WEST": 
   {
       _type = _Heavy_Heli_West select floor (random count _Heavy_Heli_West)
   };
   case "Heavy_Heli_EAST": 
   {
       _type = _Heavy_Heli_East select floor (random count _Heavy_Heli_East)
   };
   case "Light_Heli_WEST": 
   {
       _type = _Light_Heli_West select floor (random count _Light_Heli_West)
   };
   case "Light_Heli_EAST": 
   {
       _type = _Light_Heli_East select floor (random count _Light_Heli_East)
   };
   case "Fixed_Wing_WEST": 
   {
       _type = _Fixed_Wing_West select floor (random count _Fixed_Wing_West)
   };
   case "Fixed_Wing_EAST": 
   {
      _type = _Fixed_Wing_East select floor (random count _Fixed_Wing_East)
   };
   case "Light_Heli_GUER": 
   {
       _type = _Light_Heli_Guer select floor (random count _Light_Heli_Guer)
   };
};

_grp = createGroup _side;

// For the helicopters, needed to spawn at a lower altitude and slower speed.
if (isServer and _type isKindof "helicopter") then 
{
  _newAircraft1 = [_spwnPos, 180, _type, _grp] call BIS_fnc_spawnVehicle;				// creates the aircraft.
       _aircraft1 = _newAircraft1 select 0;										// select the vehicle from the array.				
       _aircraft1 setPos [getPos _aircraft1 select 0, getPos _aircraft1 select 1, 100];			// sets the aircrafts start height.
       _spwnDir = [_aircraft1, _movePos] call BIS_fnc_relativeDirTo; 
  _aircraft1 setDir _spwnDir;												// Sets the aircraft direction.
       _aircraft1 setVelocity [sin (_spwnDir) * 50, cos (_spwnDir) * 50, 0];					// sets the aircraft starting speed.
       _aircraft1 flyinheight 100;												// tells the aircraft to fly at an altitude.
       sleep 1;															// sleep so aircraft does not spawn on top of each other and crash.

  _newAircraft2 = [_spwnPos, 180, _type, _grp] call BIS_fnc_spawnVehicle;				// same info as above.
       _aircraft2 = _newAircraft2 select 0;			
       _aircraft2 setPos [getPos _aircraft2 select 0, getPos _aircraft2 select 1, 100];
       _spwnDir = [_aircraft2, _movePos] call BIS_fnc_relativeDirTo; 
  _aircraft2 setDir _spwnDir;
       _aircraft2 setVelocity [sin (_spwnDir) * 50, cos (_spwnDir) * 50, 0];
       _aircraft2 flyinheight 100;
};

// For the jets, needed to spawn at higher altitude with faster speeds.
if (isServer and _type isKindof "plane") then 
{
       _newAircraft1 = [_spwnPos, 180, _type, _grp] call BIS_fnc_spawnVehicle;				// Same info as above.
       _aircraft1 = _newAircraft1 select 0;				
       _aircraft1 setPos [getPos _aircraft1 select 0, getPos _aircraft1 select 1, 400];
       _spwnDir = [_aircraft1, _movePos] call BIS_fnc_relativeDirTo; 
  _aircraft1 setDir _spwnDir;
       _aircraft1 setVelocity [sin (_spwnDir) * 180, cos (_spwnDir) * 180, 0];
       _aircraft1 flyinheight 400;
       sleep 1;

       _newAircraft2 = [_spwnPos, 180, _type, _grp] call BIS_fnc_spawnVehicle;					// Same info as above.
       _aircraft2 = _newAircraft2 select 0;				
       _aircraft2 setPos [getPos _aircraft2 select 0, getPos _aircraft2 select 1, 400];
       _spwnDir = [_aircraft2, _movePos] call BIS_fnc_relativeDirTo; 
  _aircraft2 setDir _spwnDir;
       _aircraft2 setVelocity [sin (_spwnDir) * 180, cos (_spwnDir) * 180, 0];
       _aircraft2 flyinheight 400;
};

// Selects the type of move, either a patrol or attack.
switch (_moveType) do 
{										
case "Patrol": // Aircraft will "Patrol" at designated position.
   	{
	[_grp,_movePos,_distance] call BIS_fnc_taskPatrol;		
  	};
   	case "Attack": // Aircraft will "SAD" at designated position.
   	{
	[_grp,_movePos] call BIS_fnc_taskAttack;
   	};
};

[color="Red"]CASdone = false;
[_time, _aircraft1, _aircraft2] spawn 
{			
_time = _this select 0;
_aircraft1 = _this select 1;
_aircraft2 = _this select 2;

while {_time != 0 or !(alive _aircraft1) and !(alive _aircraft2)} do 
{
	_time = _time - 1;
	sleep 1;
	//hintsilent format ["Time left on Mission: %1", _time];
};
   if (_time == 0 or !(alive _aircraft1) and !(alive _aircraft2)) exitWith {CASdone = true};
};[/color]

// While the crew is alive or the time is not at zero it will do the loop below until one of the conditions are met, then exit the script and end.
while {{alive _x} count (units _grp) != 0 or !(CASdone) or !(alive _aircraft1) and !(alive _aircraft2)} do
{
   if (!(isEngineOn  _aircraft1) and !(isEngineOn _aircraft2) or !(alive _aircraft1) and !(alive _aircraft2)) exitWith
{
	[_side,"HQ"] sideChat format ["%1 CAS has been destroyed!", _side];
	sleep 30;
	{deleteVehicle _x} forEach (units _grp); deleteVehicle _aircraft1; deleteVehicle _aircraft2; deletegroup _grp;
};
if ((fuel _aircraft1) <= 0.3 or (fuel _aircraft2) <= 0.3) exitWith
{
	[_side,"HQ"] sideChat format ["%1 CAS is low on fuel, returning to base.",_side];
	_wp = _grp addWaypoint [_spwnpos, 0];
	_wp setWaypointType "MOVE";
	_wp setWaypointBehaviour "CARELESS";
	_wp setWaypointSpeed "FULL";
	_wp setWaypointStatements ["true", "this execVM 'deleteGroup.sqf'"];
	_grp setCurrentWaypoint _wp;
};
if (CASdone) exitWith
{
	[_side,"HQ"] sideChat format ["%1 CAS is returning to base.",_side];
	_wp = _grp addWaypoint [_spwnpos, 0];
	_wp setWaypointType "MOVE";
	_wp setWaypointBehaviour "CARELESS";
	_wp setWaypointSpeed "FULL";
	_wp setWaypointStatements ["true", "this execVM 'deleteGroup.sqf'"];
	_grp setCurrentWaypoint _wp;
};
sleep 1;
};

// Deletes the marker for use again.
deleteMarkerLocal "RAS_Marker";

// Tells everyone that the script is no longer running.
CAS_Active = false;
publicVariable "CAS_Active";

Edited by cobra4v320

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  

×