Jump to content
Sign in to follow this  
fadly1979

Spawn vehicle mid air.

Recommended Posts

After many hours of experimenting, i finally crack the code. now i can spawn unit in mid air. here's the way. this to create a vehicle 100 meters on top of an object named _object. Create a trigger of your choice and in On Act box write this script :

first we need to create a vehicle

_vehicle = "vehicle" createVehicle getPos _object;

i've been trying exhaustively to use an array in the getpos part

_vehicle = "vehicle" createVehicle [getPos _object select 0, getPos _object select 1, 100];

but it doesn't work. Googling produce nothing, just a lot of normal on the ground spawning. Then a break came a few minutes ago. i tried this code

_vehicle = "vehicle" createVehicle getPos _object; _vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 100];

and IT WORK LIKE A CHARM!!!

Sorry guys for my bragging but after banging my head on this problem for many hours, finding a solution is like the greatest achievement of mankind.

Share this post


Link to post
Share on other sites

Nice you can get something to work! I'm stuck with several things that will not at the moment.

That array:

[getPos _vehicle select 0, getPos _vehicle select 1, 100];

As far as I understand it equates to x,y and z coordinates

getPos _vehicle select 0, = x

getPos _vehicle select 1, = y

getPos _vehicle select 2, = z

If you substitute a value like you have done above - it returns that position in meters from the original possition.

Share this post


Link to post
Share on other sites

@fadly1979.... When you spawn a jet like this does it actually fly?...or just crash in a burning heap?

Share this post


Link to post
Share on other sites
@fadly1979.... When you spawn a jet like this does it actually fly?...or just crash in a burning heap?

You can use

createVehicle array

command. For example.

_vehicle = createVehicle ["vehicle" , (getPos _object), [], 0, "FLY"] 

this will create a vehicle that spawn in a flying mode. or better yet

_vehicle = group createunit ["vehicle" , (getPos _object), [], 0, "FLY"]

Which will create a piloted vehicle instead of empty vehicle.

---------- Post added at 12:41 PM ---------- Previous post was at 12:17 PM ----------

Nice you can get something to work! I'm stuck with several things that will not at the moment.

That array:

[getPos _vehicle select 0, getPos _vehicle select 1, 100];

As far as I understand it equates to x,y and z coordinates

getPos _vehicle select 0, = x

getPos _vehicle select 1, = y

getPos _vehicle select 2, = z

If you substitute a value like you have done above - it returns that position in meters from the original possition.

Yes it is. i made a LAPES mission where a vehicle spawn at the same position, direction and speed of a C-130. the problem is, when i did that, the spawned vehicle will collided with the plane and both were destroyed. So i make it so the vehicle will spawn a few metres under the plane's belly. here the example code.

_vehicle setPos [getPos plane select 0, getPos plane select 1, (getPos plane select 2)-3];

it will spawn the vehicle 3 metres under the plane's belly so it won't collided.

Edited by fadly1979

Share this post


Link to post
Share on other sites

_vehicle = group createunit ["vehicle" , (getPos _object), [], 0, "FLY"]

Which will create a piloted vehicle instead of empty vehicle.

I feel silly now lol...i was creating air support for a mission and manually created every unit that was supposed to pilot the aircraft and placed them in...lol...i dont know why I skimmed over that when reading createunit, it does the same thing either way, I just did it more explicit

Share this post


Link to post
Share on other sites
I feel silly now lol...i was creating air support for a mission and manually created every unit that was supposed to pilot the aircraft and placed them in...lol...i dont know why I skimmed over that when reading createunit, it does the same thing either way, I just did it more explicit

Can you actually create a piloted / crewed vehicle with that alone?

I put this in an sqf and it doesn't work

private ["_mortar2"];
_mortar2 = group player createUnit ["M252_US_EP1", position player, [], 15,"NONE"];

All the examples I have seen use it to create the crew then add them to the vehicle with moveInDriver etc.

Share this post


Link to post
Share on other sites
Can you actually create a piloted / crewed vehicle with that alone?

I put this in an sqf and it doesn't work

private ["_mortar2"];
_mortar2 = group player createUnit ["M252_US_EP1", position player, [], 15,"NONE"];

All the examples I have seen use it to create the crew then add them to the vehicle with moveInDriver etc.

well what about that isn't working exactly? does it just not execute? or does it not spawn crew with it?

I haven't tested the above code (havent played arma in a week or two) but the reason for specifying a group is to place the created unit inside of the group specified...which you can't do with an empty unit, only living units. So, I don't see why it wouldn't work.

if it just doesnt work altogether, then i suggest removing layers of complexity to identify the problem. For example: create a trigger that is supposed to create a unit directly in front of you 3 seconds after the mission starts. if it doesnt spawn your unit, then the command is the problem. A common problem with that is specifying an object that isnt in the game...not saying that youre object you specified isnt correct, but try another unit just to screw around. For example if youre playing vanilla arma2, and youre trying to use a mortar from the expansion, obviously that's not going to work. Another reason it won't work is if you don't specify a group, which isn't the case here since you specified the player's group, but just food for thought

in any case, as i said above, it does the same thing regardless, just creating each unit individually is much more explicit (i.e. you can control rank/skill/initial loadout/etc of every unit inside the vehicle). Also, you can place opfor units in blufor vehicles, blufor units in civilian vehilces, etc etc. using the createUnit command as listed above which should create the crew, is if you want just basic options for the crew and what not.

Edited by GDICommand

Share this post


Link to post
Share on other sites
well what about that isn't working exactly? does it just not execute? or does it not spawn crew with it?

I haven't tested the above code (havent played arma in a week or two) but the reason for specifying a group is to place the created unit inside of the group specified...which you can't do with an empty unit, only living units. So, I don't see why it wouldn't work.

if it just doesnt work altogether, then i suggest removing layers of complexity to identify the problem. For example: create a trigger that is supposed to create a unit directly in front of you 3 seconds after the mission starts. if it doesnt spawn your unit, then the command is the problem. A common problem with that is specifying an object that isnt in the game...not saying that youre object you specified isnt correct, but try another unit just to screw around. For example if youre playing vanilla arma2, and youre trying to use a mortar from the expansion, obviously that's not going to work. Another reason it won't work is if you don't specify a group, which isn't the case here since you specified the player's group, but just food for thought

in any case, as i said above, it does the same thing regardless, just creating each unit individually is much more explicit (i.e. you can control rank/skill/initial loadout/etc of every unit inside the vehicle). Also, you can place opfor units in blufor vehicles, blufor units in civilian vehilces, etc etc. using the createUnit command as listed above which should create the crew, is if you want just basic options for the crew and what not.

It executes -

-Does not spawn vehicle,

-Does not spawn crew,

you can sometimes see the mortar spawn for a fraction of second then it disappears - no AI crew. Arma2 + OA 1.57

I have no trouble creating AI with it - when you specify a vehicle it does not work. Tried it with an AH64D too?

Test it and let me know if it works for you?

Share this post


Link to post
Share on other sites
It executes -

-Does not spawn vehicle,

-Does not spawn crew,

you can sometimes see the mortar spawn for a fraction of second then it disappears - no AI crew. Arma2 + OA 1.57

I have no trouble creating AI with it - when you specify a vehicle it does not work. Tried it with an AH64D too?

Test it and let me know if it works for you?

I tried it, and THEN I went to the api for guidance lol. it turns out you can't use this for vehicles. so the way that we did it before (creating each unit individually, and then placing them in the vehicle) was the correct (and only) way to do it. So fadly1979 was just posting without actually knowing what he was talking about. I just assumed he was speaking from previous knowledge

createUnit_array

Share this post


Link to post
Share on other sites

_vcl = "vehicle" createVehicle position player;

_vcl setPos [(getPos _vcl select 0),(getPos _vcl select 1),(getPos _vcl select 2) + 200];

"unit" createUnit [position player,"_pilot = this"];

_pilot moveindriver _vcl;

_vel = velocity _vcl;

_dir = direction _vcl;

_speed = 150;

_vcl setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+(cos _dir*_speed),(_vel select 2)];

this is just another way to do it aswell

it will not work with choppers tho

Share this post


Link to post
Share on other sites
this is just another way to do it aswell

it will not work with choppers tho

i think youre confused...thats the only way to do it (minus the setting velocity, using FLY as the special when you create the vehicle takes care of most everything you would want to do , unless youre looking at setting a speed that isnt default, then the rest isnt neccessary)

Share this post


Link to post
Share on other sites

Xeno is right - the BIS spawnfunction is the best way to do this now. I am still learning scripting so wanted to do it the hard way 1st.

My way of doing things:

//create group and aircraft
_F35Bgrp1 = createGroup west;
_F35Bveh = createVehicle ["F35B", position player, [], 5000, "FLY"];

//create pilot and move in aircraft
_F35Bpilot = _F35Bgrp1 createUnit ["US_Soldier_Pilot_EP1", [0,0,1], [], 0, "CAN_COLLIDE"];
_F35Bpilot moveInDriver _F35Bveh;

//create 1st wp
_wp0 = _F35Bgrp1 addWaypoint [position player, 0];
[_F35Bgrp1, 0] setWaypointType "SAD";
[_F35Bgrp1, 0] setWaypointSpeed "FULL";
[_F35Bgrp1, 0] setWaypointCombatMode "RED";

I like the above because of the random behaviour. It will start 5000m away and arrive from a random direction and patrol the area around the player in a random manner without too much specific scripting.

Lots more lines than BIS spawnfunction but it's fun getting it right!

You can use a laser designator with the above and it will drop GBU 12s on second pass.

--------------------------------------------------------------------------

My full random CAS script - can be called with a radio trigger when you need it. The F35B will head to your position and patrol. You or the JTAC need to laser designate targets for him.

The JTAC is a little work shy - he needs to be within 475m to show any interest in targeting things with the laser designator. Select him and press 2 to select a specific target for him or he might wonder between targets and the jet will not lock on.

As usual the pilot will only drop bombs on the second pass. (can be 1st pass if you add code to target specific items but this is designed to be used anywhere, against any vehicles) edit: shock! the F35B will drop on the 1st pass if circunstances are right!

The F35B will leave and be deleted after all enemies within 500m are dead.

//cas.sqf

//F35B GBU12 only - CAS Range max 500m

//Lock FAC on target - select FAC and '2' - target - target

//Trigger cond: _xhandle = [this] execVM "cas.sqf";

if (!isServer) exitWith {};

//Create FAC - Joint Terminal Attack Controller

_jtac = Alpha createUnit ["BAF_Soldier_FAC_MTP", position player, [], 10, "FORM"];

_jtac removeWeapon "BAF_L85A2_UGL_Holo";

_jtac selectWeapon "Laserdesignator";

[_jtac] join Alpha;

_jtac move position player;

hint "JTAC WIDOW-07 and TOPMAN-01 CAS on station";

sleep 10;

hint "TOPMAN-01 inbound - 60seconds!";

sleep 35;

hint "TOPMAN-01 inbound - Paint Target!";

_F35Bgrp1 = createGroup west;

_F35Bveh = createVehicle ["F35B", position player, [], 5000, "FLY"];

//create pilot and move in jet

_F35Bpilot = _F35Bgrp1 createUnit ["US_Soldier_Pilot_EP1", [0,0,1], [], 0, "CAN_COLLIDE"];

_F35Bpilot moveInDriver _F35Bveh;

_F35Bpilot = driver _F35Bveh;

_F35Bpilot setSkill 1;

_F35Bpilot setUnitRank "LIEUTENANT";

addSwitchableUnit _F35Bpilot;

//Removes all weapons and adds GBU 12s and extra flares.

//Remove if you want original weapons.

_F35Bveh setVehicleAmmo 0.0;

{_F35Bveh removeMagazines _x} forEach (magazines _F35Bveh);

{_F35Bveh removeWeapon _x} forEach (weapons _F35Bveh);

{_F35Bveh addMagazine "2Rnd_GBU12"} forEach [1,2,3,4];

_F35Bveh addWeapon "BombLauncherF35";

{_F35Bveh addMagazine "120Rnd_CMFlare_Chaff_Magazine"} forEach [1,2,3,4];

_F35Bveh addWeapon "CMFlareLauncher";

_F35Bveh setFuel 1;

_F35Bgrp1 setCombatMode "RED";

//create 1st wp

_wp0 = _F35Bgrp1 addWaypoint [position player, 0];

[_F35Bgrp1, 0] setWaypointType "SAD";

[_F35Bgrp1, 0] setWaypointSpeed "FULL";

[_F35Bgrp1, 0] setWaypointCombatMode "RED";

//create 2nd wp

_wp1 = _F35Bgrp1 addWaypoint [(getMarkerPos "wp1"), 100];

[_F35Bgrp1, 1] setWaypointType "MOVE";

[_F35Bgrp1, 1] setWaypointSpeed "NORMAL";

[_F35Bgrp1, 1] setWaypointBehaviour "CARELESS";

[_F35Bgrp1, 1] setWaypointCombatMode "RED";

//create 3rd wp

_wp2 = _F35Bgrp1 addWaypoint [(getMarkerPos "wp2"), 100];

[_F35Bgrp1, 2] setWaypointType "MOVE";

[_F35Bgrp1, 2] setWaypointSpeed "FULL";

[_F35Bgrp1, 2] setWaypointBehaviour "CARELESS";

[_F35Bgrp1, 2] setWaypointCombatMode "RED";

//Helo is removed from game

[_F35Bgrp1, 2] setWaypointStatements ["true", "deletevehicle (vehicle this);{deleteVehicle _x} forEach units group this;hint 'TOPMAN-01 exiting AO';"];

RTB_action = {

private ["_F35Bgrp1","_F35Bpilot","_wp1","_F35Bveh","_jtac"];

[_F35Bgrp1, 0] setWaypointType "MOVE";

_F35Bpilot = driver _F35Bveh;

_F35Bpilot domove (getWPPos _wp1);

hint "CAS complete - TOPMAN-01 RTB";

sleep 3;

hint "CAS complete - WIDOW-07 out";

};

//create trigger - the jet will leave when all

//enemy within a 500m radius are dead.

_F35Btrg1 = createTrigger["EmptyDetector",getPos player];

_F35Btrg1 setTriggerArea[500,500,0,false];

_F35Btrg1 setTriggerActivation["East","NOT PRESENT",false];

//All East dead SAD behaviour cancelled send jet to next WP

_F35Btrg1 setTriggerStatements ["this", "_nul = [] spawn RTB_action;", ""];

_F35Btrg1 synchronizeTrigger [_wp0];

Edited by PELHAM

Share this post


Link to post
Share on other sites

You can also create an empty vehicle and spawn in the entire crew seperately by using

[_vehicle, _group,false,"","US_Soldier_Pilot_EP1"] call BIS_fnc_spawnCrew

This is good to use if you are going to use a US crew in a enemy vehicle like the UH-1H.

Edited by cobra4v320

Share this post


Link to post
Share on other sites

I'm creating a video where I want to spawn a few meteors with a trigger. Do I need to write a script or do I write something in the condition/on act boxes of a trigger?

Share this post


Link to post
Share on other sites

you can use BIS_fnc_spawnGroup to spawn a vehicle with crew in it already, I have not tried it with aircraft but I know it works for vehicles. I am using it in one of my projects.

Share this post


Link to post
Share on other sites
you can use BIS_fnc_spawnGroup to spawn a vehicle with crew in it already, I have not tried it with aircraft but I know it works for vehicles. I am using it in one of my projects.

it works perfectly fine on any type vehicle, land/air/sea.

Share this post


Link to post
Share on other sites

Hi all i am new to the forums so please be gentle : )

I have been playing around with Pelhams script as seen above with the i44 mod to get a C47A to spawn with a pilot and all seems to be fine but i want to set it to no fleeing so it will ignor the flak inplacement on the ground. i have this

//create group and aircraft

_C47Agrp1 = createGroup west;

_C47Aveh = createVehicle ["I44_Plane_A_C47A_AAF", spawn1, [], 300, "FLY"];

//create pilot and move in aircraft

_C47Apilot = _C47Agrp1 createUnit ["I44_Man_A_AAF_Pilot_M1911A1", [0,0,1], [], 0, "CAN_COLLIDE"];

_C47Apilot moveInDriver _C47Aveh;

//create 1st wp

WP1 = getmarkerPos "WP1";

_wp0 _C47Agrp1 addWaypoint [ _wp1, 0];

[_C47Agrp1, 0] setWaypointType "MOVE";

[_C47Agrp1, 0] setWaypointSpeed "FULL";

[_C47Agrp1, 0] setWaypointCombatMode "GREEN";

C47veh allowfleeing 0;

C47pilot allowfleeing 0;

C47grp1 allowfleeing 0;

i have put 3 in as i have had no luck with any of them on their own, i have also tried to put it in a trigger but with no luck.

Any advice would be apreciated as i am a scripting noob and am just trying to pick up what i can from picking others scripts apart. Also how would i delete the plane and pilot when they get to the WP and restart it all over again.

Basicaly i am trying to put together a mission where the player is sent in with a small unit to take out the AA positions while small waves of planes fly over the target area. I tried lots of dofire's etc in an attempt to take the planes out of the picture but nothing worked. Having the planes there would be preferable tho.

Also dosn't seem to want to follow WP just goes to bottom left corner of map

Ps: Thanks to the whole comunity for all the increadible "stuff" you have all made avalable. Makes the whole ARMA experience so much more ; )

Edited by Bejmo

Share this post


Link to post
Share on other sites

There were a few errors, try this.

//create group and aircraft
_C47Agrp1 = createGroup west;
_C47Aveh = createVehicle ["I44_Plane_A_C47A_AAF",spawn1, [], 300, "FLY"];

//create pilot and move in aircraft
_C47Apilot = _C47Agrp1 createUnit ["I44_Man_A_AAF_Pilot_M1911A1", [0,0,1], [], 0, "CAN_COLLIDE"];
_C47Apilot moveInDriver _C47Aveh;


//create 1st wp
_wp1 = getmarkerPos "WP1";
_wp0 = _C47Agrp1 addWaypoint [ _wp1, 0];
[_C47Agrp1, 0] setWaypointType "MOVE";
[_C47Agrp1, 0] setWaypointSpeed "FULL";
[_C47Agrp1, 0] setWaypointCombatMode "GREEN";

// either of these should work
driver _C47Aveh allowfleeing 0;
_C47Apilot allowfleeing 0;
// _C47grp1 allowfleeing 0;

Share this post


Link to post
Share on other sites

Ledgend thank you very much and my wife thanks you LOL she was about to turn the pc off to stop me from going bald he he. It's allways so simple in the end :bounce3:

Ok back to mission making........actualy bed might be a good idea chips are gone coke is gone and i have an assignment due on monday :j:

Edited by Bejmo

Share this post


Link to post
Share on other sites

"_F35Bveh = createVehicle ["F35B", position player, [], 5000, "FLY"];"

i know this thread is old but i just have to ask a few things. i feel this line of code wont have its altitude working unless you change "FLY" into "NO_COLLISION" .. this have been a problem for me. whatever you do with that 5000 it gets overwritten with 100 or so. but using "NO_COLLISION" to have it exactly where you spawned it will have it dropping until the pilot can recover from the stall. what i am to do is spawn it in mid air @2000 with engines ON and speed as if he was already flying there.

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  

×