Jump to content
Sign in to follow this  
Raddik

Aircraft w/Crew Spawn Script

Recommended Posts

All,

This script when called will spawn an aircraft however many times you wish, with a crew and waypoint. It's great for missions where you need to have an aircraft spawn multiple times but eventually stop. The aircraft will fly towards the named waypoint and search and destroy. Once it's destroyed it will respawn and again fly towards the waypoint. The script cleans up each cycle by deleting the units and aircraft to make it as light as possible on your rig/server. Best of all and the ultimate reason for it's creation is it's compatible with dedicated servers! :yay: That mean no multiple vehicle spawning on your dedicated box. This was only possible with a great amount of help from Wiper as he wrote the code. It's used on my Uber Air Combat mission to create a Coop & Multiplayer frenetic air combat experience. I have posted a link below as well as the code itself with some instructions on how to use it. Everything is based around spawning a Russian SU25 (SU34 for a classname) 7 times. For those of you with a lick of experience it will be self explanatory.

Download Link:

http://www.raddik.com/storage/arma2/SU2501.zip

// Credits to Wiper on bistudio.com forums for helping me with this! ~Raddik

private["_delay"];

SU2501SPAWN_Pos=[(getmarkerpos "SU2501SPAWN") select 0,(getmarkerpos "SU2501SPAWN") select 1,((getmarkerpos "SU2501SPAWN")select 2)+100];

waituntil {!isNil "bis_fnc_init"};

_delay=5;

GroupEAIR10 = createGroup east;

SU2501Count= 0;

SU2501= objNull;

while{SU2501Count < 7}do{ // Change '7' to how many times you want the vehicle to respawn

if(isServer)then{

if(!alive SU2501)then{

sleep _delay; // seconds to delay the deletion after vehicle is killed

{deletevehicle _x}foreach crew vehicle SU2501; // deletes all mebers of the vehicle crew

deletevehicle SU2501;

SU2501= ([sU2501SPAWN_Pos, 0, "SU39", GroupEAIR10] call BIS_fnc_spawnVehicle) select 0;

SU2501 setVehicleVarName "SU2501";

wp1= GroupEAIR10 addWaypoint [(getmarkerpos "SU2501TARGET"), 0];

wp1 setWaypointSpeed "FULL";

wp1 setWaypointType "SAD";

SU2501Count= SU2501Count+1;

publicvariable "SU2501Count";

publicvariable "SU2501";

};

};

sleep 10; // delay to save system performance and give pause to the next spawn;

};

sleep 1;

First, create a spawn point for the aircraft. Name it and replace 'SU2501SPAWN' in the script with it. Next, create a waypoint, name it, and again replace 'SU2501TARGET' in the script with it. Change the '7' by the 'while{SU2501Count < 7}' with the number of times you would like the aircraft to spawn. Next, replace 'SU39' with whatever vehicle classname you wish to use. Each time you duplicate this script for a different vehicle make sure you make the group name and waypoints unique. Finally, call the script from your init.sqf or a trigger and enjoy.

While it's extremely simple, I decided to post it anyway since I was looking for something this noob friendly a few weeks ago.

Regards,

Raddik

Share this post


Link to post
Share on other sites

Curious question: why do you use publicvariable? I dont really see the point of running the loop on all clients when the content of the loop is only running on the server.

Share this post


Link to post
Share on other sites

Great script Raddik, thanks for sharing.

I am having "technical" diffuculty spawning F35B.

Could you please point out what I am doing wrong?

private["_delay"];

F35SPAWN_Pos=[(getmarkerpos "F35BSPAWN") select 0,(getmarkerpos "F35BSPAWN") select 1,((getmarkerpos "F35BSPAWN")select 2)+100];

waituntil {!isNil "bis_fnc_init"};

_delay=5;

GroupWAIR1 = createGroup west;

F35BCount= 0;

F35B= objNull;

while{F35Count < 2}do{

if(isServer)then{

if(!alive F35B)then{

sleep _delay; // seconds to delay the deletion after vehicle is killed

{deletevehicle _x}foreach crew vehicle F35B; // deletes all mebers of the vehicle crew

deletevehicle F35B;

F35B= ([F35BSPAWN_Pos, 0, "F35B", GroupWAIR1] call BIS_fnc_spawnVehicle) select 0;

F35B setVehicleVarName "F35B";

wp1= GroupWAIR1 addWaypoint [(getmarkerpos "F35BTARGET"), 0];

wp1 setWaypointSpeed "FULL";

wp1 setWaypointType "SAD";

F35BCount= F35BCount+1;

publicvariable "F35BCount";

publicvariable "F35B";

};

};

sleep 30; // delay to save system performance;

};

sleep 1;

Share this post


Link to post
Share on other sites

@CaptainBravo

Are you calling this from your init.sqf or from a trigger?

I think your problem might be early on where you have:

F35SPAWN_Pos

It should be:

F35BSPAWN_Pos

Best of luck.

Raddik

Share this post


Link to post
Share on other sites

Not sure if you caught this one yet, but...

F35BCount= 0;

while{F35Count < 2}do{

Might help to fix the F35Count, make it F35BCount. ;)

Share this post


Link to post
Share on other sites

I'm having the same problem with this script as I had with the problem I described in this thread.

In short, the jets/helicopters start too close to the ground, and eventually crash. Over water the crash occurs about 2 seconds after spawning.

However, if I put

SU2501 setVelocity [-100, 0, 0] //Sets SU2501 velocity to 100kph in a west direction

in the script after the SetVehicleVarname command it seems to work just fine.

How was this script working without that setVelocity command I am wondering? What am I missing?

Share this post


Link to post
Share on other sites

You shouldnt really need to set velocity as the BIS spawn vehicle script does that automatically for aircrafts...

Tried starting the jets/helos higher up?

In my AI spawn script the helicopters spawn at the same position they are placed default when "flying" and I havent noticed any tendancy to crash, they seem to fly just fine.

Share this post


Link to post
Share on other sites

Murklor is correct, this bit of code...

((getmarkerpos "F35BSPAWN")select 2)+100

...spawns the aircraft at a safe height.

Also, Vapor did catch another typo. Did that fix your issue? If not, you must make sure there is at least one unit alive on the side (west, east, etc.) you are spawning an aircraft for (in this context anyway). It seems the game engine needs a place to spawn the plane and crew before moving it to the position you specify. I remember having an issue with the script not working until I placed on Russian unit on the map somewhere...use the same logic if you are using this for the Marines.

@CaptainBravo I'm going to check out the sample you sent me right now.

Raddik

---------- Post added at 03:36 PM ---------- Previous post was at 03:28 PM ----------

@CaptainBravo The typo Vapor found was your first issue, the second was the one I mentioned in the above post. I placed an unplayable Marine on the map and wala...your aircraft spawns without crashing.

Let me know how it goes.

Raddik

Edited by Raddik

Share this post


Link to post
Share on other sites

Thanks, you guys were right, the typo along with the missing marine fixed it, thanks so much for a great script.

Only question is how do you fire script through a trigger?

What I am trying to do is an escort mission where 2 fighter jets escorting a civ plane get intercepted when they enter an area (trig activates script and spawn enemy planes to intercept) (I assume if you replace traget marker name with civ plane, enemy planes will persue civ plane?).

Thanks for script and help.

Share this post


Link to post
Share on other sites

Simple, just set a variable to say false, then do a simple while loop that checks if the variable is true every 1-10 or whatever seconds and after that have your plane spawn.

The trigger would set the variable to true.

Keep in mind that you need to constantly update the waypoint if you want a plane to chase it, or you'll have a plane doing SAD in one area of the map while the target plane has long since flown past.

Share this post


Link to post
Share on other sites

Well yeah, a S&D marker will be fine, as long as it's large enough, and you remove all ground based weapons (lgbs etc) maybe even the cannon.

Maybe script in a dotarget comand.

Share this post


Link to post
Share on other sites

Thank you for the info. I am a bit new to scripting and not sure how to set variable. Can you not just spwan 2 plans by triggor once enemy has entered triggor with Destroy or Search and Destroy WP?

Thanks for your help.

Share this post


Link to post
Share on other sites

I need to spawn a transport plane for either opfor or guerrillas later in the game. So I used your script to create a c130j and had it land at the airport. It worked just fine except when it got shot down by opfor. I was able to create an empty in the editor and put in a guerrilla pilot and none of the shilka's that I put around the airport took a shot at him. I tried spawning it as side east and side resistance but it still didn't work.

// Credits to Wiper on bistudio.com forums for helping me with this! ~Raddik


c130j1SPAWN_Pos=[(getmarkerpos "c130j1SPAWN") select 0,(getmarkerpos "c130j1SPAWN") select 1,((getmarkerpos "c130j1SPAWN")select 2)+100];

waituntil {!isNil "bis_fnc_init"};

GroupEAIR10 = createGroup resistance;

c130j1= ([c130j1SPAWN_Pos, 0, "c130j", GroupEAIR10] call BIS_fnc_spawnVehicle) select 0;
c130j1 setVehicleVarName "c130j1";
wp1= GroupEAIR10 addWaypoint [(getmarkerpos "c130j1TARGET"), 0];
wp1 setWaypointSpeed "FULL";
wp1 setWaypointType "getout";

I also tried spawning it without the use of the function module but couldn't figure out how to get the empty above ground.I have a script that I used to create units without the function module since they are units that don't come with the game but I couldn't quite figure out how to implement the createvehicle with "flying" instead of "form" or to get it to spawn in the air.

heavy1= Creategroup resistance;

_Unit1= heavy1 createUnit ["terrorist1",[(getMarkerPos "start") select 0,(getMarkerPos "start") select 1,0],[],0,"FORM"];

for [{_i = 0}, {_i <= 4}, {_i = _i + 1}] do
{
_Unit2= heavy1 createUnit ["terrorist2",[(getMarkerPos "start") select 0,(getMarkerPos "start") select 1,0],[],0,"FORM"];
};

_Unit3= heavy1 createUnit ["terrorist9",[(getMarkerPos "start") select 0,(getMarkerPos "start") select 1,0],[],0,"FORM"];

_Unit4= heavy1 createUnit ["terrorist6",[(getMarkerPos "start") select 0,(getMarkerPos "start") select 1,0],[],0,"FORM"];

_Unit5= heavy1 createUnit ["terrorist5",[(getMarkerPos "start") select 0,(getMarkerPos "start") select 1,0],[],0,"FORM"];

_unit3 setunitrank "CORPORAL";

_unit1 setunitrank "SERGEANT";

_unit1=leader heavy1;

sleep 5;

wp1 = heavy1 addwaypoint [getmarkerpos "attack", 0];
wp1 setwaypointtype "move";
wp1 setWaypointSpeed "FULL";

Any ideas?

Share this post


Link to post
Share on other sites

Hey shanawa. Have you set the loyalty of the independent forces in the mission editor? It is by default set to make them friendly to BluFor.

Raddik

Share this post


Link to post
Share on other sites
Hey shanawa. Have you set the loyalty of the independent forces in the mission editor? It is by default set to make them friendly to BluFor.

Raddik

Yup. I've tried independent friendly to everyone and just opfor. I also tried changing "GroupEAIR10 = createGroup resistance;" to "GroupEAIR10 = createGroup east;" and they still get shot down.

So I made the group side east and had the c130 eject. If I placed myself as USMC he shot me, if I was OPFOR or resistance he greeted me . If I placed USMC ai he shot them and they didn't shoot back , OPFOR ai shot him and got a message to hold fire your shooting at friendlies while I was an OPFOR . resistance ai don't shoot him because i have them set to friendly all, when I change them to friendly OPFOR they shoot.

So basically with the function module he thinks he's switch sides but everyone still sees him as a USMC.

Edited by shanawa

Share this post


Link to post
Share on other sites

I figured out how to do it. I added a setcaptive to make him a hostage so no one shoots him.

// Credits to Wiper on bistudio.com forums for helping me with this! ~Raddik


c130j1SPAWN_Pos=[(getmarkerpos "c130j1SPAWN") select 0,(getmarkerpos "c130j1SPAWN") select 1,((getmarkerpos "c130j1SPAWN")select 2)+100];

waituntil {!isNil "bis_fnc_init"};

GroupEAIR10 = createGroup resistance;

c130j1= ([c130j1SPAWN_Pos, 0, "c130j", GroupEAIR10] call BIS_fnc_spawnVehicle) select 0;
c130j1 setVehicleVarName "c130j1";
[color="Red"]c130j1 setcaptive true;[/color]
wp1= GroupEAIR10 addWaypoint [(getmarkerpos "c130j1TARGET"), 0];
wp1 setWaypointSpeed "FULL";
wp1 setWaypointType "getout";

Share this post


Link to post
Share on other sites

I know this is an old post; But I just checked it out using exactly your script & even if you lift the spawn hight they just fly into the ground as if there is no pilot on board???? Is there an update.

Share this post


Link to post
Share on other sites

It will work but you need a unit of that side already on the map or you can update the script like this.

By adding createcenter East; it allows the script to work if no units of that side are present on the map.

null=[sU2501SPAWN] execvm "spawn_air.sqf"

save as spawn_air.sqf

// Credits to Wiper on bistudio.com forums for helping me with this! ~Raddik

private["_delay"];

SU2501SPAWN_Pos=[(getmarkerpos "SU2501SPAWN") select 0,(getmarkerpos "SU2501SPAWN") select 1,((getmarkerpos "SU2501SPAWN")select 2)+100];

createcenter East;

waituntil {!isNil "bis_fnc_init"};

_delay=5;

GroupEAIR10 = createGroup east;
SU2501Count= 0;
SU2501= objNull;

while{SU2501Count < 7}do{ // Change '7' to how many times you want the vehicle to respawn
if(isServer)then{
if(!alive SU2501)then{
sleep _delay; // seconds to delay the deletion after vehicle is killed
{deletevehicle _x}foreach crew vehicle SU2501; // deletes all mebers of the vehicle crew
deletevehicle SU2501;
SU2501= ([sU2501SPAWN_Pos, 0, "SU39", GroupEAIR10] call BIS_fnc_spawnVehicle) select 0;
SU2501 setVehicleVarName "SU2501";
wp1= GroupEAIR10 addWaypoint [(getmarkerpos "SU2501TARGET"), 0];
wp1 setWaypointSpeed "FULL";
wp1 setWaypointType "SAD";
SU2501Count= SU2501Count+1;

publicvariable "SU2501Count";
publicvariable "SU2501";
};
};
sleep 10; // delay to save system performance and give pause to the next spawn;
};

sleep 1; 


Share this post


Link to post
Share on other sites

Just a note as an alt type script that you can use, this script

AI vehicle respawn patrol area using UPS

http://www.armaholic.com/page.php?id=6543

does about the same thing as Aircraft w/Crew Spawn Script.

Even tho the script is for vehicles specifically it works for choppers and planes as well.

For planes set them up before the runway so they can taxi, for choppers you can put them anywhere.

Share this post


Link to post
Share on other sites

Thanks a lot F2k sel that worked:yay: Is there any way to make them more aggressive at the target waypoint or up the skill level of the spawned aircraft do you know? I have not acatually seem it open fire yet put a few live ground targets on a test map, It gets fired on but wont so far seem to fire back or attack on "SAD" setting, which is :(

---------- Post added at 09:13 PM ---------- Previous post was at 09:09 PM ----------

[/color]

Just a note as an alt type script that you can use, this script

AI vehicle respawn patrol area using UPS

http://www.armaholic.com/page.php?id=6543

does about the same thing as Aircraft w/Crew Spawn Script.

Even tho the script is for vehicles specifically it works for choppers and planes as well.

For planes set them up before the runway so they can taxi, for choppers you can put them anywhere.

Thanks Gunter. I have used the ups spawn before but I was looking for a way to spawn aircraft already in flight, to stop players (when they get to know where the enemy aircraft are) from destroying them on the ground:rolleyes:

Edited by jgaz-uk
Addition

Share this post


Link to post
Share on other sites

If it's not engaging then place a unit on the map of the same side, there's a bug in createcentre which I forgot about.

You can try adding this to the script after the waypoints

SU2501 setspeedMode "limited";
su2501 setskill 1;

I'm not sure it will have any effect though.

Share this post


Link to post
Share on other sites

I put a spare pilot on the map & adjusted his skill level that seems to work :)

Last Question; can more than one aircraft at a time (2 or 4) be spawned?

Share this post


Link to post
Share on other sites
I put a spare pilot on the map & adjusted his skill level that seems to work :)

Last Question; can more than one aircraft at a time (2 or 4) be spawned?

I would say no, the script's only written for one aircraft at a time.

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  

×