Jump to content
Sign in to follow this  
cobra4v320

Random helicopter spawn not working

Recommended Posts

I cannot get this to work I know I'm missing something simple. Depending on what you choose you will get a random EAST/WEST HEAVY/LIGHT helicopter.

Its not giving me any errors either.

Script is executed with _nul = [West, "Heavy_Heli_WEST", getmarkerpos "spawn", getpos player, 20] execVM "Aircraft_Spawn.sqf"

/*
   Random Aircraft Spawn v.1.0
   by cobra4v320

   Execute with  _null = [West, "Heavy_Heli_WEST", getmarkerpos "spawn", getpos player, 20] execVM "Aircraft_Spawn.sqf";
*/

if (!isServer) exitWith {};

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

_side = _this select 0;
_sidetype = _this select 1;
_spwnpos = _this select 2;
_movepos = _this select 3;
_delay = _this select 4;

//delay before spawning vehicle
sleep _delay;

//array of available East helicopters
_Light_Heli_East = ["UH1H_TK_EP1","Mi17_TK_EP1","Mi17_rockets_RU"];
_Heavy_Heli_East = ["Mi24_D_TK_EP1","Ka52Black"];

//array of available West helicopters
_Light_Heli_West = ["UH60M_EP1","UH1Y","CH_47F_EP1","MH6J_EP1"];
_Heavy_Heli_West = ["AH64D_EP1","AH1Z","AH6J_EP1"];

//array of available East jets
_Fixed_Wing_East = ["Su25_TK_EP1","L39_TK_EP1","Su34","Su39"];

//array of available West jets
_Fixed_Wing_West = ["A10_US_EP1","F35B","AV8B2"];

//create random position
_rDir = round (random 360); // random direction
_rDist = 200 + (round (random 100)); // random distance (between 200-300 meters)
_rPos = [(_spwnpos select 0) + (sin _rDir) * _rDist, (_spwnpos select 1) + (cos _rDir) * _rDist, (_spwnpos select 2) + 100]; // new 3D position

//Prepare variables
private ["_type","_grp","_veh","_heli","_picture"];

//select random vehicle based on side
switch (_sidetype) 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);};
};

//create group
_grp = createGroup _side;

//create vehicle
_aircraft = [_rPos, 245, _type, _grp] call BIS_fnc_spawnVehicle;
_veh = _aircraft select 0;

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

//create waypoints
[_grp, _movepos, 350 + round (random 100)] call bis_fnc_taskPatrol;

//set group behavior
_veh flyInHeight 100;
_grp setBehaviour "COMBAT";
_grp SetCombatMode "RED";

//bling bling
_picture = getText (configFile >> "cfgVehicles" >> typeOf _veh>> "picture");
hint parseText format["
<img size='7'color='#888888' image='%3'/><br/>
Side %1 has spawned a %2",_Side, typeof _veh, _picture];

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Make sure you have a Functions module on your map in the editor.

Share this post


Link to post
Share on other sites

Functions Module is on the map that is one of the first things I checked when it didnt work.

Share this post


Link to post
Share on other sites

Make HeavyWEST,HeavyEAST etc strings and it will work. HeavyWEST has no value!

So your switch statement looks like this.....

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

case [b]"HeavyWEST"[/b]: {
	_type = _HeavyWest select floor (random count _HeavyWest);
};
case [b]"HeavyEAST"[/b]: {
	_type = _HeavyEast select floor (random count _HeavyEast);
};
case [b]"LightWEST"[/b]: {
	_type = _LightWest select floor (random count _LightWest);
};
case [b]"LightEAST"[/b]: {
	_type = _LightEast select floor (random count _LightEast);
};
};

...and is called with this....

_nul = [West, [b]"HeavyWEST"[/b], getmarkerpos "spawn", getpos player, 20] execVM "helispawn.sqf";

Edited by twirly
Fixed an error

Share this post


Link to post
Share on other sites

Awesome that did the trick, I knew it was something I wasn't seeing. Thank you Twirly. First post updated.

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Cool mate...glad it's working!

Share this post


Link to post
Share on other sites

I'm still having some issues with this script, currently no vehicles are spawning in. I am not receiving any errors either.

Two other issues I have not been able to figure out with this script:

1. I have been playing with the typeof and isKindof commands, I want to be able to set the vehicle spawn height based on whether or not it is a jet or helicopter.

2. After spawning the vehicle I want it to fly at a certain height based on what type of aircraft it is.

Script is in the spoiler

/*

Random Aircraft Spawn: v.1.0

Created by: cobra4v320

Execute with: _null = [West, "Heavy_Heli_WEST", getmarkerpos "spawn", getpos player, 350, 10] execVM "Aircraft_Spawn.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 position the vehicle will patrol to

_this select 4: the distance between waypoints

_this select 5: the delay before the vehicle will be spawned

*/

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

// 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;

_spwnpos = _this select 2;

_movepos = _this select 3;

_distance = _this select 4;

_delay = _this select 5;

//delay before spawning vehicle

sleep _delay;

//create random position

_rDir = round (random 360); // random direction

_rDist = 200 + (round (random 100)); // random distance (between 200-300 meters)

_rPos = [(_spwnpos select 0) + (sin _rDir) * _rDist, (_spwnpos select 1) + (cos _rDir) * _rDist, (_spwnpos select 2) + 200]; // new 3D position

//array of available East helicopters

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"];

};

if (_ArmaVersion == 1) then {

_Light_Heli_East = ["Mi17_TK_EP1","UH1H_TK_EP1"];

_Heavy_Heli_East = ["Mi24_D_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"];

};

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"];

};

};

//array of available West helicopters

if (_side == West) then

{

if (_ArmaVersion == 0) then {

_Light_Heli_West = ["MH60S","UH1Y"];

_Heavy_Heli_West = ["AH1Z","AH64D"];

};

if (_ArmaVersion == 1) then {

_Light_Heli_West = ["UH60M_EP1","AH6J_EP1","CH_47F_EP1"];

_Heavy_Heli_West = ["AH64D_EP1"];

};

if (_ArmaVersion == 2) then {

_Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1"];

_Heavy_Heli_West = ["AH1Z","AH64D","AH64D_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"];

};

};

//array of available East jets

if (_side == East) then

{

if (_ArmaVersion == 0) then {

_Fixed_Wing_East = ["Su25_INS","Su34","Su39"];

};

if (_ArmaVersion == 1) then {

_Fixed_Wing_East = ["Su25_TK_EP1","L39_TK_EP1"];

};

if (_ArmaVersion == 2) then {

_Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];

};

if (_ArmaVersion == 3) then {

_Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];

};

};

//array of available West jets

if (_side == West) then

{

if (_ArmaVersion == 0) then {

_Fixed_Wing_West = ["A10","F35B","AV8B2"];

};

if (_ArmaVersion == 1) then {

_Fixed_Wing_West = ["A10_US_EP1"];

};

if (_ArmaVersion == 2) then {

_Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];

};

if (_ArmaVersion == 3) then {

_Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];

};

};

//Prepare variables

private ["_type","_grp"];

//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);

};

};

//create group

_grp = createGroup _side;

//create two vehicles

_grp = [_rPos, _side, [_type, _type],[[-5,-5],[15,15]]] call BIS_fnc_spawnGroup;

//select group leader

_grp selectLeader ((units _grp) select 0);

//create random patrol route

[_grp, _movepos, _distance] call bis_fnc_taskPatrol;

//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

I'd say you need to manipulate _rPos prior to calling BIS_fnc_spawnGroup, depending whether your _type isKindOf "Helicopter" or "Plane".

And right after the spawn command: {_x flyinheight 100} foreach units _grp;

if (_type iskindof "Helicopter") then
{
_rPos = [(_rPos select 0),(_rPos select 1), 200];
_grp = [_rPos, _side, [_type, _type],[[-5,-5],[15,15]]] call BIS_fnc_spawnGroup;
{_x flyinheight 120} foreach units _grp;
};
if (_type iskindof "Plane") then
{
_rPos = [(_rPos select 0),(_rPos select 1), 800];
_grp = [_rPos, _side, [_type, _type],[[-5,-5],[15,15]]] call BIS_fnc_spawnGroup;
{_x flyinheight 500} foreach units _grp;
};

Out the top of my head :P

Share this post


Link to post
Share on other sites

Hi mate. You need to initialise any arrays that you are are using in any if's, switch's etc before they will work.

Try adding....

_Light_Heli_East = [];
_Heavy_Heli_East = [];
_type = [];
etc...

.... for any arrays before the statement where you use them. Tested and working.

Use isKindOf to choose between helos and planes and set the flyInHeight. You also need to get the actual vehicle using vehicle and leader on the group returned by BIS_fnc_spawnGroup.

if (vehicle leader _grp isKindOf "Plane") then {vehicle leader _grp flyInHeight 200};

if (vehicle leader _grp isKindOf "Helicopter") then {vehicle leader _grp flyInHeight 100};

The aircraft will follow the terrain though....they won't fly flat. No way around that really.

You can also use a switch statement for that stuff above.

While running the code I realised that you could sort of "boil it down" some.... you only need to check for EAST or WEST once and put all the relevant stuff for each array in each of those checks.

Another thing man...try to use the code tags next time... I had to reformat all your code before being able to read it!

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites

Thanks Twirly and Strangelove, it is now working for me, I moved all of the east/west arrays under the two different sides and added the empty arrays at the beginning of the script. I was using _type isKindof "helicopter" and it wasnt working because nothing was spawning in. :o

The only part that is not working is in red, it is not spawning the aircraft in at the proper height.


/*
Random Aircraft Spawn: v.1.0
Created by: cobra4v320

Execute with: _null = [West, "Heavy_Heli_WEST", getmarkerpos "spawn", getpos player, 350, 10] execVM "Aircraft_Spawn.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 position the vehicle will patrol to
_this select 4: the distance between waypoints
_this select 5: the delay before the vehicle will be spawned

*/

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


// 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;
_spwnpos = _this select 2;
_movepos = _this select 3;
_distance = _this select 4;
_delay = _this select 5;

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

//delay before spawning vehicle
sleep _delay;


if (_side == East) then
{
//array of available East helicopters
if (_ArmaVersion == 0) then {
_Light_Heli_East = ["Mi17_INS","Mi17_rockets_RU"];
_Heavy_Heli_East = ["Mi24_P","Mi24_V","Ka52","Ka52Black"];
};
if (_ArmaVersion == 1) then {
_Light_Heli_East = ["Mi17_TK_EP1","UH1H_TK_EP1"];
_Heavy_Heli_East = ["Mi24_D_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"];
};
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"];
};

//array of available East aircraft
if (_ArmaVersion == 0) then {
_Fixed_Wing_East = ["Su25_INS","Su34","Su39"];
};
if (_ArmaVersion == 1) then {
_Fixed_Wing_East = ["Su25_TK_EP1","L39_TK_EP1"];
};
if (_ArmaVersion == 2) then {
_Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
};
if (_ArmaVersion == 3) then {
_Fixed_Wing_East = ["Su34","Su39","Su25_TK_EP1","L39_TK_EP1"];
};
};

if (_side == West) then
{
//array of available West helicopters
if (_ArmaVersion == 0) then {
_Light_Heli_West = ["MH60S","UH1Y"];
_Heavy_Heli_West = ["AH1Z","AH64D"];
};
if (_ArmaVersion == 1) then {
_Light_Heli_West = ["UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
_Heavy_Heli_West = ["AH64D_EP1"];
};
if (_ArmaVersion == 2) then {
_Light_Heli_West = ["MH60S","UH1Y","UH60M_EP1","AH6J_EP1","CH_47F_EP1"];
_Heavy_Heli_West = ["AH1Z","AH64D","AH64D_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"];

//array of available west jets
if (_ArmaVersion == 0) then {
_Fixed_Wing_West = ["A10","F35B","AV8B2"];
};
if (_ArmaVersion == 1) then {
_Fixed_Wing_West = ["A10_US_EP1"];
};
if (_ArmaVersion == 2) then {
_Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
};
if (_ArmaVersion == 3) then {
_Fixed_Wing_West = ["A10","F35B","AV8B2","A10_US_EP1"];
};
};
};

//Prepare variables
private ["_vehicletype","_type","_grp"];

//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);
};
};

//create random 3D position
[color="Red"]if (_type isKindof "helicopter") then
{
_rPos = [(_spwnpos select 0), (_spwnpos select 1), (_spwnpos select 2) + 250];
} else {
_rPos = [(_spwnpos select 0), (_spwnpos select 1), (_spwnpos select 2) + 400];
};[/color]

//create group
_grp = createGroup _side;

//create two vehicles
_grp = [_rPos, _side, [_type, _type],[[0,0],[100,-100]]] call BIS_fnc_spawnGroup;

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

//create random patrol route
[_grp, _movepos, _distance] call bis_fnc_taskPatrol;

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

if (vehicle leader _grp isKindOf "Plane") then {vehicle leader _grp flyInHeight 400} else {vehicle leader _grp flyInHeight 250};
[/Code]

Also what do you mean by code tags? :o

Edited by cobra4v320

Share this post


Link to post
Share on other sites

If its not spawning in at the proper height, what height is it spawning at?

Code tags are [ code ] [ / code ] without the spaces.

Share this post


Link to post
Share on other sites

Around 50 meters off the ground, the normal height when placing a helicopter in the editor set to "fly".

I have tried this below and a number of other ways, still not spawning at height.

_rPos = [(_spwnpos select 0),(_spwnpos select 1),(_spwnpos select 2)+200];

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Edit: Woops. I suck at simple math. Nevermind :)

Move the marker around, may be the terrain. Couldn't hurt to try.

Edited by Grimes [3rd ID]

Share this post


Link to post
Share on other sites
_rPos = [(_spwnpos select 0),(_spwnpos select 1),(_spwnpos select 2)+200];
_vehicle ..............(create the vehicle)....;
_vehicle flyInHeight 200;

Share this post


Link to post
Share on other sites

Thanks Demonized, but Im using bis_fnc_spawngroup.

This does not work:

_rPos = [(_spwnpos select 0),(_spwnpos select 1),(_spwnpos select 2)+200];
_grp = [_rPos, _side, [_type, _type],[[-5,-5],[15,15]]] call BIS_fnc_spawnGroup;

Im thinking I will need to just not use spawngroup and just use bis spawnvehicle then bis spawncrew.

Edited by cobra4v320

Share this post


Link to post
Share on other sites

{
_vehicle = vehicle _x;
if (_vehicle isKindOf "Air") then {_vehicle flyInHeight 200};
} foreach units _grp1;

---------- Post added at 10:13 PM ---------- Previous post was at 10:11 PM ----------

ah , spawngroup spawns vehicles on ground no matter. use spawn vehicle for air, and just make them all join your group.

Share this post


Link to post
Share on other sites

My jets and helicopters are spawning at 50 meters flying forward using bis_fnc_spawngroup. Just cant figure out how to setpos them.

If I cant figure it out then I'm using bis_fnc_spawnvehicle I guess.

My flyinheight works perfect though.

if (vehicle leader _grp isKindOf "Plane") then {vehicle leader _grp flyInHeight 450};
if (vehicle leader _grp isKindOf "helicopter") then {vehicle leader _grp flyInHeight 150};

I have also been playing with the bis_fnc_spawngroup list of relative positions but it doesnt give the option for height???

_grp = [_spwnpos, _side, [[color="Red"]_type[/color], [color="RoyalBlue"]_type[/color]],[[color="Red"][0,0][/color],[color="RoyalBlue"][100,-100][/color]]] call BIS_fnc_spawnGroup;

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Once you get the vehicle that was created using vehicle leader _grp then you can setPos and setDir that vehicle...no worries.

(vehicle leader _grp) [b]setPos[/b] [ x, y, 100];  //Height is 100...x and y are whatever

(vehicle leader _grp) [b]setDir[/b] _whateverdir;

Hope that helps.

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites

Awesome that works for the group leader but how about his wingman?

I have tried:

{_x setPos [(_spwnpos select 0), (_spwnpos select 1), (_spwnpos select 2) + 400]} foreach units _grp

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Wow!... It's starting to get complicated! :) ... now you will need code to determine the vehicles in the group.

_grpvehs = [];

for "_i" from 0 to ((count units _grp)-1) do {
   _veh = vehicle (units _grp select _i);
  if (not (_veh isKindOf "Man") and not (_veh in _grpvehs)) then {
   _grpvehs set [count _grpvehs,_veh];
  };
  sleep 0.01;
};

So now.... instead of using vehicle leader _grp on the group returned from BIS_fnc_spawnGroup... run the code above on the group to get all the vehicles into the array _grpvehs.

See if you can figure out the next move!

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites

You are awesome Twirly. Okay so I have them spawning at height and now I have them spawning at speed, or at least the group leader is. Still needs some more work.

if (_type isKindof "helicopter") then
{
//create two vehicles
_grp = [_spwnpos, _side, [_type, _type],[[0,0],[100,-100]]] call BIS_fnc_spawnGroup;

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

_grpvehs = [];

for "_i" from 0 to ((count units _grp)-1) do {
   _veh = vehicle (units _grp select _i);
  if (not (_veh isKindOf "Man") and not (_veh in _grpvehs)) then {
   _grpvehs set [count _grpvehs,_veh];
  };
  sleep 0.01;
};
//set aircraft position, fly height, and speed
{_x setPos [(_spwnpos select 0), (_spwnpos select 1), (_spwnpos select 2) + 150]} foreach _grpvehs;
	_spwndir = [(vehicle leader _grp), _movepos] call BIS_fnc_relativeDirTo; 
		{_x setdir _spwndir} foreach _grpvehs;
			{_x setVelocity [sin(_spwndir)*100,cos(_spwndir)*100,0]} foreach _grpvehs;
				vehicle leader _grp flyInHeight 150;

};

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Try something like this....

if (_type isKindof "helicopter") then {

//create two vehicles
_grp = [_spwnpos, _side, [_type, _type],[[0,0],[100,-100]],[],[],[],[], random 360] call BIS_fnc_spawnGroup;

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

_grpvehs = [];

for "_i" from 0 to ((count units _grp)-1) do {

    _veh = vehicle (units _grp select _i);

	if (not (_veh isKindOf "Man") and not (_veh in _grpvehs)) then {

	   _grpvehs set [count _grpvehs,_veh];
  		};

 		sleep 0.01;
};

_spwndir = [(vehicle leader _grp), _movepos] call BIS_fnc_relativeDirTo; 

for "_i" from 0 to ((count _grpvehs)-1) do {

	(_grpvehs select _i) setPos [_spwnpos select 0, _spwnpos select 1, 150];

	(_grpvehs select _i) setDir _spwndir;

	(_grpvehs select _i) setVelocity [sin(_spwndir)*100,cos(_spwndir)*100,0];

	(_grpvehs select _i) flyInHeight 150;

	sleep 0.5; //maybe gives enough time so they don't end up on each other!

};

};

I probably have that _spwndir in the wrong place but you can figure that out.

If you wanted to use foreach instead of the for .... this is how.

{ _x setPos [_spwnpos select 0, _spwnpos select 1, 150]; 
_x setDir _spwndir;
_x setVelocity [sin(_spwndir)*100,cos(_spwndir)*100,0];
_x flyInHeight 150;
sleep 0.5;
} foreach _grpvehs;

EDIT: I don't think you need the setvelocity if the aircraft are already created and flying... unless you specifically want the speed set at 100 for some reason.

Edited by twirly
Added some text

Share this post


Link to post
Share on other sites

guys, it seems you are overcomplicating this with alot of unneccesary stuff, making it look advanced and all that but no need to make it difficult.

this works just the same way and is much easier to read and understand aswell as more userfriendly.

_grpvehs = [];													// array to list all different vehicles in group.
_grpDir = getDir (vehicle (leader _grp1));								// 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)*150,cos(_grpDir)*150,0];  			// set speed to 150.
};
} foreach units _grp1;

Edited by Demonized

Share this post


Link to post
Share on other sites
EDIT: I don't think you need the setvelocity if the aircraft are already created and flying... unless you specifically want the speed set at 100 for some reason.

Twirly the jets were spawning in flying then they are setpos so they are then standing still, so adding the speed helps fix that problem.

Thank you Twirly and Demonized. :notworthy:

Here is the working script:

/*
   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", getmarkerpos "spawn", getpos player, 350, 10] execVM "Aircraft_Spawn.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 position the vehicle will patrol to
_this select 4: the distance between waypoints
_this select 5: the delay before the vehicle will be spawned

*/

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


// 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;
_spwnpos = _this select 2;
_movepos = _this select 3;
_movetype = _this select 4;
_distance = _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 = [];
_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"];
       };

};

//Prepare variables
private ["_type","_grp"];

//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)};
};

_grp = createGroup _side;	//create group

//create two vehicles
if (_type isKindof "helicopter") then
{
_grp = [_spwnpos, _side, [_type, _type],[[0,0],[100,-100]]] 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;
};


if (_type isKindof "plane") then
{
_grp = [_spwnpos, _side, [_type, _type],[[0,0],[100,50]]] 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;
};

//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

Added a switch with the option to use:

bis_fnc_taskpatrol - will patrol several waypoints

bis_fnc_taskattack - will SAD at designated position

Fixed: Jets were not spawning in because they were not setup properly in the "if (armaversion == 0) area.

/*
   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", getmarkerpos "spawn", getpos player, "Patrol", 350, 10] execVM "Aircraft_Spawn.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 position the vehicle will patrol to
_this select 4: the type of patrol - Patrol, ATTack
_this select 5: 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","_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 and OA and BAF
_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;
_spwnpos = _this select 2;
_movepos = _this select 3;
_movetype = _this select 4;
_delay = _this select 5;

//initialize arrays
_Light_Heli_East = [];
_Heavy_Heli_East = [];
_Fixed_Wing_East = [];
_Light_Heli_West = [];
_Heavy_Heli_West = [];
_Fixed_Wing_West = [];
_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"];
       };

};

//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)};
};

_grp = createGroup _side;	//create group

//create two vehicles
if (_type isKindof "helicopter") then
{
_grp = [_spwnpos, _side, [_type, _type],[[0,0],[100,-100]]] 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;
};


if (_type isKindof "plane") then
{
_grp = [_spwnpos, _side, [_type, _type],[[0,0],[100,50]]] 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;
};

//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;


If anyone has any ideas on how to improve or optimize please let me know, Im still learning.

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  

×