Jump to content
Sign in to follow this  
Howard

Spawning an active flying aircraft with a trigger..

Recommended Posts

Hey.

I'm trying to make 2 hostile jets spawn at a certain point on the map in the air when a trigger is activated, I want them to sort of ambush the player and I have to do it like this because if I just put them to circle in a corner of a map you might be able to see them on the radar.

Share this post


Link to post
Share on other sites

GroupA10 = CreateGroup West;
A10CAS = createVehicle ["A10", [(getMarkerPos "A10Spawn") select 0,(getMarkerPos "A10Spawn") select 1,100], [], 0, "FLY"];
A10Pilot = GroupA10 createUnit ["USMC_Soldier_Pilot", [0,0,1], [], 0, "CAN_COLLIDE"];
A10Pilot moveInDriver A10CAS;
wp1 = GroupA10 addWaypoint [(getmarkerpos "A10Target"), 0];
wp1 setWaypointSpeed "NORMAL";
wp1 setWaypointType "SAD";

place a marker called a10spawn on the map: this is where the a10 would spawn in.

place another marker on the map called a10target: this is where the plane will fly to when it spawns in.

If you do not want an a10 here are the classnames.

Edited by cobra4v320

Share this post


Link to post
Share on other sites

I edited the script so it would fly a su-25. Can anyone tell me why whenever I trigger it the jet spawns and then crashes into the ground, like it has no pilot or the engine is off or something?

GroupSu25_Ins = CreateGroup Independent;

Su25_InsCAS = createVehicle ["Su25_Ins", [(getMarkerPos "Su25_InsSpawn") select 0,(getMarkerPos "Su25_InsSpawn") select 1,100], [], 0, "FLY"];

Su25_InsPilot = GroupSu25_Ins createUnit ["Ins_Soldier_Pilot", [0,0,1], [], 0, "CAN_COLLIDE"];

Su25_InsPilot moveInDriver Su25_InsCAS;

wp1 = GroupSu25_Ins addWaypoint [(getmarkerpos "Su25_InsTarget"), 0];

wp1 setWaypointSpeed "NORMAL";

wp1 setWaypointType "SAD";

Share this post


Link to post
Share on other sites

That probably means the driver isn't in the vehicle. Try adding Su25_InsPilot assignAsDriver Su25_InsCAS; before the move in command, see if that helps.

Does anyone know what CAN_COLLIDE does? I havent seen that before.

Following is a copy + paste from a mission script of mine:

helo2 = createVehicle ["UH1Y", _spawn, [], 0, "FLY"];
_pilot = _helo2Group createUnit ["USMC_Soldier_Pilot", _spawn, [], 0, "NONE"];
_pilot assignAsDriver helo2;
_pilot moveindriver helo2;

Share this post


Link to post
Share on other sites

The crashing is occurring because when the empty aircraft is spawned the engine is off and and it has no forward speed even if there is a pilot present it essentially falls out of the sky. I've posted a method for spawning AI choppers in the air here: http://forums.bistudio.com/showpost.php?p=1370382&postcount=24 but planes are a different beast altogether.

1. What you are going to need to do is make sure the engines on the moment the aircraft is spawned so need to add a line of code:

plane engineON true; (http://community.bistudio.com/wiki/engineOn)

2. SetPos the just created aircraft so its in the air eg.

plane setPos [(getPos plane) select 0, (getPos plane) select 1, 500]; (this would make the aircraft 500 metres off the ground from where it spawned)

or conversely spawn the plane in the air as you have done in your example.

3. You are also going to have to give the plane some forward momentum so that its flying until the engines power-up and the pilot can take control (for choppers, at least, this can take about 20 seconds after they spawn and the engines are turned on).

To do this use the setVelocity command (http://community.bistudio.com/wiki/setVelocity). A couple of things about this:

* make sure the aircraft is heading in the direction of the waypoints before setting the velocity otherwise it will tumble through the air (can use setDir to do this once the plane is spawned).

* Also make sure you give a vertical element to the setVelocity vector to give the airplane an upward momentum as this will help keep the plane in the air until the engines fire-up.

so something like:

plane setVelocity [500, 0, 20];

I think this is for a plane travelling due north with an upward momentum of 20 metres per second. If its travelling a different direction other than due south (which I think maybe -500) you will have to play around with sin and cos and multiply by the speed you want, but you're going to have to experiment.

You may also want to set the flyinheight of the aircraft for once the pilot takes control (http://community.bistudio.com/wiki/flyInHeight).

Edited by norrin

Share this post


Link to post
Share on other sites

norrin, are you sure?

I have never had that problem so long as I don't set the spawn position height. Thats a much more elegant solution. Try placing an empty jet in the editor, set to FLY. You will see that indeed, it does fly (for quite a while, till it crashes).

Try my code sample above and you will see it is fine. You only get into problems if you set the spawn HEIGHT as above ground. If the engine spawns something as FLY, you should give a standard marker position reference and let the game engine do the rest.

---------- Post added at 02:42 PM ---------- Previous post was at 02:37 PM ----------

...when the empty aircraft is spawned the engine is off and and it has no forward speed ...

Nope, an aircraft spawned with the special placement setting set to FLY (as shown above) will spawn with the engine on, and forward speed according to the normal speed of the vehicle, regardless of whether there is a pilot or not. You don't need to do anything clever if you use that.

Share this post


Link to post
Share on other sites

Thanks Rocket never thought of that as I've always mistakenly spawned off the ground, will definitely give it a try. :)

Edited by norrin

Share this post


Link to post
Share on other sites
Thanks Rocket never thought of that as I've always mistakenly spawned off the ground, will definitely give it a try. :)

Hey, whatever I can help you out with ... I'm all for! Your respawn script is what makes my missions!

Share this post


Link to post
Share on other sites

@Rocket, I'm learning new and better ways to do things all the time. If you knew the headaches this particular problem had caused me in the past - I really am an idiot at times, I get so tied up in scripting solutions that I sometimes forget or overlook the fact that there are much better, more efficient and simpler ways of doing things. Thanks again mate :)

Share this post


Link to post
Share on other sites

Before you guys do more rocket science to just spawn a plane and a pilot... :)

Place the functions module in the editor.

_vec_array = [markerPos "some_marker", random 360, "A10", west] call BIS_fnc_spawnVehicle;

That's it. Paramters and return values:

Parameter(s):

_this select 0: desired position (Array).

_this select 1: desired azimuth (Number).

_this select 2: type of the vehicle (String).

_this select 3: side or existing group (Side or Group).

Returns:

Array:

0: new vehicle (Object).

1: all crew (Array of Objects).

2: vehicle's group (Group).

The function will add the correct crew members, fill up all crew positions and will spawn aircrafts in the air, aka flying.

Xeno

Share this post


Link to post
Share on other sites
Before you guys do more rocket science to just spawn a plane and a pilot... :)

Place the functions module in the editor.

_vec_array = [markerPos "some_marker", random 360, "A10", west] call BIS_fnc_spawnVehicle;

That's it. Paramters and return values:

Parameter(s):

_this select 0: desired position (Array).

_this select 1: desired azimuth (Number).

_this select 2: type of the vehicle (String).

_this select 3: side or existing group (Side or Group).

Returns:

Array:

0: new vehicle (Object).

1: all crew (Array of Objects).

2: vehicle's group (Group).

The function will add the correct crew members, fill up all crew positions and will spawn aircrafts in the air, aka flying.

Xeno

Damn you BIS, stop making this scripting business so easy. Soon anybody will be able to do it! :p

Thanks Xeno :)

Share this post


Link to post
Share on other sites

You already know this I'm sure, but for the rest.

Put a "Functions" module, no need for synchronisation.

Put a radio alpha trigger

and in its "on activation" put:

waituntil {!isnil "bis_fnc_init"};[] call bis_fnc_help;

Now you're able to browse all predefined functions from the config, missions and campaign.

Read more on:

http://community.bistudio.com/wiki/Functions_Library

[edit]

And Norrin, please don't be so hard on yourself, you and the other scripting wizards surely inspired the BIS ppl when doing the scripts now available in modules.

Especially your Revive script.

Still not seeing any killer bunnies tho' :)

Edited by Taurus

Share this post


Link to post
Share on other sites

thanks for the help I fixed my problem, but how would I go about grouping a newly spawned vehicle with multiple triggers? Basically I want it so that when the jet flies over triggers it causes an IED script to go off, like a carpet bomb. Maybe there is a command to check if the jet is present within the trigger area?

Share this post


Link to post
Share on other sites
Before you guys do more rocket science to just spawn a plane and a pilot... :)

Place the functions module in the editor.

_vec_array = [markerPos "some_marker", random 360, "A10", west] call BIS_fnc_spawnVehicle;

That's it. Paramters and return values:

Parameter(s):

_this select 0: desired position (Array).

_this select 1: desired azimuth (Number).

_this select 2: type of the vehicle (String).

_this select 3: side or existing group (Side or Group).

Returns:

Array:

0: new vehicle (Object).

1: all crew (Array of Objects).

2: vehicle's group (Group).

The function will add the correct crew members, fill up all crew positions and will spawn aircrafts in the air, aka flying.

Xeno

Yeah, this works fine, however I would need bit more arrays to this.

I want to create a new task for downing the spawned aircraft.

How does one add setIdentity with this?

Or could I use some other condition for trigger which detects when the spawned aircraft is killed?

Share this post


Link to post
Share on other sites

This is what I use on my uAV script to delete it, and the crew whenever the UAV is shot down.

What are you trying to accomplish?

MyUAV = _vec_array select 0;

MyUAV setVehicleInit "this SetVehicleVarName ""MyUAV"";this addMagazine ""4Rnd_Sidewinder_AV8B"";this addWeapon ""SidewinderLaucher""; this disableAI ""AUTOTARGET"" ; this disableAI ""TARGET"" ; this setCombatMode ""BLUE"";this setBehaviour ""careless"";uavMod synchronizeObjectsAdd [xvec2, xvec1, MyUAV]";
MyUAV addEventHandler ["killed", {sleep 20; {deletevehicle _x} foreach (crew MyUAV)+[MyUAV]}];

Share this post


Link to post
Share on other sites
This is what I use on my uAV script to delete it, and the crew whenever the UAV is shot down.

What are you trying to accomplish?

MyUAV = _vec_array select 0;

MyUAV setVehicleInit "this SetVehicleVarName ""MyUAV"";this addMagazine ""4Rnd_Sidewinder_AV8B"";this addWeapon ""SidewinderLaucher""; this disableAI ""AUTOTARGET"" ; this disableAI ""TARGET"" ; this setCombatMode ""BLUE"";this setBehaviour ""careless"";uavMod synchronizeObjectsAdd [xvec2, xvec1, MyUAV]";
MyUAV addEventHandler ["killed", {sleep 20; {deletevehicle _x} foreach (crew MyUAV)+[MyUAV]}];

Just to spawn a Mi-24_V with BIS_fnc_spawnVehicle and have an identity in it so I can add a new task to destroy it.

So no deleting, only to identify it with a VehicleVarName.

Your code looks just what I need. But will it work in same trigger as creating the chopper or would it be better in separate sqf?

Share this post


Link to post
Share on other sites

here is the code I used in an older mission to spawn 3 flying a10's

_grp = createGroup west;
_wp = _grp addWaypoint [getPos Armor1, 0];
[_grp, 0] setWaypointType "SAD";
[_grp, 0] setWaypointCompletionRadius 200;
for [{_x = 0}, {_x <= 2}, {_x = _x + 1}] do
{
	_a10 = "A10" createVehicle [(getMarkerPos "PlaneSpawn" select 0), (getMarkerPos "PlaneSpawn" select 1), 250];
	_a10 setPos [(getPos _a10 select 0) + (_x * 40), getPos _a10 select 1, 250];
	_a10 engineOn true;
	_a10 setDir 290;
	_dir = 290;
	_speed = 500;
	_a10 setVelocity [(sin _dir * _speed),(cos _dir * _speed), 0];

	"USMC_Soldier_Pilot" createUnit [getMarkerPos "PlaneSpawn", _grp];
	(units _grp select _x) moveInDriver _a10;
	(units _grp select _x) setSkill 1;
	(units _grp select _x) flyInHeight 250;
};

Been tested and works

If someone wants to clean it up from the magic numbers and add parameters to it for a sqf function like, be my guest.

Edited by Bellicosity

Share this post


Link to post
Share on other sites

Great script. One question: how do you replace spawned plane once it is destroyed?

So I want 2 A10 spawned and spawned (flying in air) 5 times once destroyed?

Thanks for your help.

Share this post


Link to post
Share on other sites

Save the a10's into an array, something like this (NOT TESTED):

if (isServer) then
{
count = 0;
while { count < 5 } do
{
	A10s = [];
	_grp = createGroup west;
	_wp = _grp addWaypoint [getPos Armor1, 0];
	[_grp, 0] setWaypointType "SAD";
	[_grp, 0] setWaypointCompletionRadius 200;
	for [{_x = 0}, {_x <= 2}, {_x = _x + 1}] do
	{
		_a10 = "A10" createVehicle [(getMarkerPos "PlaneSpawn" select 0), (getMarkerPos "PlaneSpawn" select 1), 250];
		_a10 setPos [(getPos _a10 select 0) + (_x * 40), getPos _a10 select 1, 250];
		_a10 engineOn true;
		_a10 setDir 290;
		_dir = 290;
		_speed = 500;
		_a10 setVelocity [(sin _dir * _speed),(cos _dir * _speed), 0];

		"USMC_Soldier_Pilot" createUnit [getMarkerPos "PlaneSpawn", _grp];
		(units _grp select _x) moveInDriver _a10;
		(units _grp select _x) setSkill 1;
		(units _grp select _x) flyInHeight 250;

		A10s = A10s + [_a10];			
	};

	waitUntil { {alive _x } count A10s == 0 };
	count = count + 1;
};
};

Share this post


Link to post
Share on other sites

Hi there.

I've ready every post I can find regarding spawning aircraft during a mission, assigning them waypoints etc.

Have manged to get a Mi24 to spawn and attack an area, and an A10 to do the same.

I'm now working on getting 3 C130J's to spawn (adapting the A10 script here) on a trigger (which works), and also a load of troops to spawn inside them (so far only scripted the first C130J, but don't think it's working) - and when they follow their waypoints past another trigger, it executes para.sqs. Which doesn't work.

please have a look at the code I butchered, and see if there are any glaring errors!

(very new to using sqs files....)

GroupC130J = createGroup West;
wp1 = GroupC130J addWaypoint [getPos C130JWaypoint, 0];
[GroupC130J, 0] setWaypointType "MOVE";
[GroupC130J, 0] setWaypointCompletionRadius 200;
[GroupC130J, 0] setWaypointFormation "WEDGE";
for [{_x = 0}, {_x <= 2}, {_x = _x + 1}] do
{
	_C130J = "C130J" createVehicle [(getMarkerPos "C130JSpawn" select 0), (getMarkerPos "C130JSpawn" select 1), 250];
	_C130J setPos [(getPos _C130J select 0) + (_x * 40), getPos _C130J select 1, 250];
	_C130J engineOn true;
	_C130J setDir 270;
	_dir = 290;
	_speed = 500;
	_C130J setVelocity [(sin _dir * _speed),(cos _dir * _speed), 0];

	"USMC_Soldier_Pilot" createUnit [getMarkerPos "C130JSpawn", GroupC130J];
	(units GroupC130J select _x) moveInDriver _C130J;
	(units GroupC130J select _x) setSkill 1;
	(units GroupC130J select _x) flyInHeight 250;
};
player1 moveincargo C130J;
Groupsquad1 = createGroup west;
wp1 = Groupsquad1 addWaypoint [getMarkerPos "castle", 0];
[GroupC130J, 0] setWaypointType "SAD";
[GroupC130J, 0] setWaypointCompletionRadius 200;
for [{_x = 0}, {_x <= 25}, {_x = _x + 1}] do
{
                _squad1 = "USMC_Soldier£ createUnit [getMarkerPos "C130JSpawn", Groupsquad1];
                (units Groupsquad1 select _x) moveInCargo C130J;
};

Any help appreciated.

~Z~

Share this post


Link to post
Share on other sites

Hey zach72,

This is how I would do it:

Put this in init.sqf

nul= [] execVM "C130.sqf";

create a file save as C130.sqf in mission folder:

 if (isServer) then {

GrpC130=CreateGroup WEST;
C1= createvehicle ["C130J",[(getmarkerpos "C1Spawn") select 0, 	(getmarkerpos "C1Spawn") select 1,0], [],0,"FLY"];
C1 flyinHeight 250;

Pilot1=GrpC130 createunit ["USMC_Soldier_Pilot", [0,0,1], [], 0, 	"CAN_COLLIDE"];
Pilot1 moveInDriver C1;
Pilot1 flyInHeight 250;
A1 moveincargo [c1,5];



C2= createvehicle ["C130J",[(getmarkerpos "C2Spawn") select 0, 	(getmarkerpos "C2Spawn") select 1,0], [],0,"FLY"];
C2 flyInHeight 250;

Pilot2=GrpC130 createunit ["USMC_Soldier_Pilot", [0,0,1], [], 0, 	"CAN_COLLIDE"];
Pilot2 moveInDriver C2;
Pilot2 flyInHeight 250;


C3= createvehicle ["C130J",[(getmarkerpos "C3Spawn") select 0, 	(getmarkerpos "C3Spawn") select 1,0], [],0,"FLY"];
C3 flyInHeight 250;

Pilot3=GrpC130 createunit ["USMC_Soldier_Pilot", [0,0,1], [], 0, 	"CAN_COLLIDE"];
Pilot3 moveInDriver C3;
Pilot3 flyInHeight 250;




wp0=GrpC130 addwaypoint [(getmarkerpos "wp0") ,200];
wp0 setwaypointspeed "FULL";
wp0 setwaypointtype "MOVE";
wp0 setWaypointFormation "WEDGE";

wp1=GrpC130 addwaypoint [(getmarkerpos "wp1") ,200];
wp1 setwaypointspeed "FULL";
wp1 setwaypointtype "MOVE";
wp1 setWaypointFormation "WEDGE";


squad1=creategroup WEST;	


for [{_i = 0}, {_i <= 24}, {_i = _i + 1}] do

{
_unit= squad1 createUnit ["USMC_Soldier", [0,0,2], [], 0, "form"];
};

{_x moveInCargo c1} foreach units squad1;



squad2=creategroup WEST;	


for [{_i = 0}, {_i <= 24}, {_i = _i + 1}] do

{
_unit= squad2 createUnit ["USMC_Soldier", [0,0,2], [], 0, "form"];
};

{_x moveInCargo c2} foreach units squad2;


squad3=creategroup WEST;	


for [{_i = 0}, {_i <= 24}, {_i = _i + 1}] do

{
_unit= squad3 createUnit ["USMC_Soldier", [0,0,2], [], 0, "form"];
};

{_x moveInCargo c3} foreach units squad3;
};

I noticed you had moved a unit player in, the way I have done it is to place a unit in the Editor as player named A1 and put in the C130.sqf

 A1 moveincargo [C1,5]

where 5 is the position in the plane.

Also in the editor put 5 markers (or more for more waypoints). 3 in a line reasonable close to each other where the planes will spawn ( I put the markers in order C3spawn, C1spawn, C2spawn so the planes are already in formation when they spawn). and a marker over the drop zone for the first waypoint and a marker for the deletewaypoint. put a trigger some way before the drop zone, in the on act

_xhandle=[squad1,C1] execVM  "jump.sqf"; _xhandle=[squad2,C2] execVM  "jump.sqf";_xhandle=[squad3,C3] execVM  "jump.sqf"; _xhandle=[A1,C1] execVM  "jump.sqf";

create a file save as jump.sqf in mission folder

if (isServer) then {
_group =  _this select 0;
_vehicle = _this select 1;

sleep 2;

{
unassignvehicle _x;
_x action ["EJECT", _vehicle];
sleep 0.5
} foreach units _group;
};

if you want the jump to take place during the game call the code in a trigger, maybe slow the planes to limited over the drop zone to to keep the drop tighter and put a deleteVehicle trigger over the last waypoint to get rid of the planes. Hope this helps.

Share this post


Link to post
Share on other sites

awesome! works a treat thanks. had a bit of trouble with the trigger to make them jump, then came upon a West Present with condition this and (alive C1);

many, many thanks.

Now just to work out why a string of waypoints held up by a trigger won't let them go when triggered- real basic stuff!

~Z~

Share this post


Link to post
Share on other sites

how would you set up a map click to spawn an aircraft and than delete it after it reaches the maker and bombs?

Edited by spartanx

Share this post


Link to post
Share on other sites
Before you guys do more rocket science to just spawn a plane and a pilot... :)

Place the functions module in the editor.

_vec_array = [markerPos "some_marker", random 360, "A10", west] call BIS_fnc_spawnVehicle;

That's it. Paramters and return values:

Parameter(s):

_this select 0: desired position (Array).

_this select 1: desired azimuth (Number).

_this select 2: type of the vehicle (String).

_this select 3: side or existing group (Side or Group).

Returns:

Array:

0: new vehicle (Object).

1: all crew (Array of Objects).

2: vehicle's group (Group).

The function will add the correct crew members, fill up all crew positions and will spawn aircrafts in the air, aka flying.

Xeno

Ok so everyone seems to say that this works, but I can't figure out how?

I am new to scripting, but I guess that I am supposed to put this text into the module and have a marker called something that matches what I've put in the markerPos, like "airspawn".

The problem is that I can't understand how to use this, how do I even place a marker that's usable in the first place?

Becouse all I am doing now is just putting the text "_vec_array = [markerPos "airspawn", 90, "A10", west] call BIS_fnc_spawnVehicle;" inte the modules init box, placing a marker from the markers menu (F6) and naming it "airspawn".

I guess I'll have to place the marker in the air with something like "setMarkerPos [x,y,100]" but I've got no idea how to do that, as there is no init box or anything when placing a marker.. I am not even sure if thats the right way to create a marker for this purpose.

As I said I am really terrible at scripting and I would be very greatful if someone could explain this step by step, thank you so much in advance :o

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  

×