Jump to content
Sign in to follow this  
cc_kronus

Help with script "never fly alone"

Recommended Posts

Hi, I'm quite new to this forum. I recently discovered ARMA2 a few months ago and got caught by it.

i'm doing my best to help my squad to arrange some missions for our server. the problem is that when I got beyond placing units on the map and saw the scripts and their language, I realized that I am completely out of my depth and I have absolutely no idea what I'm doing. Unfortunately I don't have the time to learn the language and code properly, so I thought that maybe here I could find some help for something we are trying to do.

One of the issues wse face is that players on the role of pilots, use the helicopters to bring other players to the area of operations. Most of the times they get shot down during an extraction as the pilot is alone in the chopper and it is a sitting duck during the extraction. The sentence "Ah! wish I had gunners!" has been heard a lot.

The purpose of the script we are trying to create is that a human player in pilot role will jump on one of the available aircraft.

The script will ask the pilot if he needs a crew.

If the pilot selects to request a crew, then the script will determine the type of helicopter or aircraft he is flying, spawn a top notch crew and allocate crewmembers in the right slots in the aircraft. making the pilot the group leader.

When the mission is completed and the pilot lands at base, he will get prompted to dismiss the crew (delete them) in which case he will be prompted again if he wants to request a crew or, in case that none of the crew is injured or KIA, decide to keep them in the chopper for the next flight.

After a lot of searching in this and other forums and finding pieces and bits, I've tried to put together a script, but as said before, I do not dominate at all the code and don't have much idea of what I am doing. i would really appreciate if you could help me to make it work.

there is a trigger under each aircraft. the purpose of the trigger is to determine that the chopper is "alive" with a player inside.

Activation: Bluefor

several times

present

cond:

("air" countType thislist  > 0) 

Init:

player = (thislist select 0); 0=[player] execVM "scripts\helocrew\crewin.sqf";

CREWIN.SQF

_helo = _this;
_helotype = typeof _this;
_spawnpoint = getMarkerPos "pilotspawn";
_grp = createGroup west;



if (_helotype == UH1Y) then 
{
   _pilot1 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot1=this", 1, "Lieutenant"];
   _pilot1 setskill 1;
   _pilot2 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot2=this", 1, "sergeant"];
   _pilot2 setskill 1;
   _pilot3 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot3=this", 1, "sergeant"];
   _pilot3 setskill 1;

   player = leader _grp;

   pilot1 assignasgunner _helo;
   pilot1 moveinturret [_helo, [2]]; 
   pilot2 assignasgunner _helo;
   pilot2 moveinturret [_helo, [0]];
   pilot3 assignasgunner _helo;
   pilot3 moveinturret [_helo, [1]];
   hint "Crew is in the aircraft";
};

if (_helotype == UH60M_EP1) then
{
   _pilot4 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot4=this", 1, "Lieutenant"];
   _pilot4 setskill 1;
   _pilot5 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot5=this", 1, "sergeant"];
   _pilot5 setskill 1;
   _pilot6 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot6=this", 1, "sergeant"];
   _pilot6 setskill 1;

   player = leader _grp;

   pilot4 assignascargo _helo;
   pilot4 moveincargo [_helo, 12]; 
   pilot5 assignasgunner _helo;
   pilot5 moveinturret [_helo, [0]];
   pilot6 assignasgunner _helo;
   pilot6 moveinturret [_helo, [1]];
   hint "Crew is in the aircraft";
};

};

if (_helotype == CH_47F_EP1) then
{
   _pilot7 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot7=this", 1, "Lieutenant"];
   _pilot7 setskill 1;
   _pilot8 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot8=this", 1, "sergeant"];
   _pilot8 setskill 1;
   _pilot9 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot9=this", 1, "sergeant"];
   _pilot9 setskill 1;
   _pilot10 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot10=this", 1, "sergeant"];
   _pilot10 setskill 1;

   player = leader _grp;

   pilot7 assignascargo _helo;
   pilot7 moveincargo [_helo, 0]; 
   pilot8 assignasgunner _helo;
   pilot8 moveinturret [_helo, [0]];
   pilot9 assignasgunner _helo;
   pilot9 moveinturret [_helo, [1]];
   pilot10 assignasgunner _helo;
   pilot10 moveingunner _helo,;

   hint "Crew is in the aircraft";
};    


//next two a/c are only included for eyecandy & inmersion purposes

if (_helotype == C130J_US_EP1 ) then

{
   _pilot11 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot11=this", 1, "Lieutenant"];
   _pilot11 setskill 1; 
   _pilot11 addweapon "ACE_PARACHUTEROUNDPACK";
   _pilot12 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot12=this", 1, "sergeant"];
   _pilot12 setskill 1;
   removeallweapons _pilot12; 
   _pilot12 addweapon "ACE_PARACHUTEROUNDPACK";

   player = leader _grp;

   pilot11 assignascargo _helo;
   pilot11 moveincargo [_helo, 0]; 
   pilot12 assignascargo _helo;
   pilot12 moveincargo [_helo, 2];

   hint "Crew is in the aircraft";
};


if (_helotype == MV22 ) then

{
   _pilot13 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot13=this", 1, "Lieutenant"];
   _pilot13 setskill 1; 
   _pilot13 addweapon "ACE_PARACHUTEROUNDPACK";
   _pilot14 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "pilot12=this", 1, "sergeant"];
   _pilot14 setskill 1;
   removeallweapons _pilot14; 
   _pilot14 addweapon "ACE_PARACHUTEROUNDPACK";

   player = leader _grp;

   pilot13 assignascargo _helo;
   pilot13 moveincargo [_helo, 0]; 
   pilot14 assignascargo _helo;
   pilot14 moveincargo [_helo, 23];

   hint "Crew is in the aircraft";
};

this removeaction crewin;

There are another set of triggers in the helipads and ramp parkings to detect when the aircraft shut down engines. :

Activation: Bluefor

several times

present

cond:

("air" countType thislist  > 0) && !(EngineOn _this) 

Init:

player = (thislist select 0); 0=[player] execVM "scripts\helocrew\crewout.sqf";

CREWOUT.SQF

_helo = _this;

//if helicopter did not carry crew there is no crew to delete
if (count crew _unit == 0)) exitwith {}; 

_callout = _helo addaction ["Dismiss Crew",1];

if (_callout ==1) then
{
   {deleteVehicle _x} forEach crew _helo;

    hint "Crew has been dismissed";

    _this removeaction _callout;
};

I realize that this may be full of errors and gaps and that also there may be another, better way of doing what i want. Any help will be appreciated

************************************** SOLVED *****************************************

Go to this post to access the script.

http://forums.bistudio.com/showthread.php?144596-Help-with-script-quot-never-fly-alone-quot&p=2277083&viewfull=1#post2277083

Edited by CC_Kronus
solved. added link to script

Share this post


Link to post
Share on other sites

phew - there is much wrong there (there were also a few things wrong in this post! - all updated and working - tested):

-see wiki for syntax references: http://community.bistudio.com/wiki/Category:Scripting_Commands_ArmA2

-don't start execVM's with a number handle

-Is there a reason behind naming every crew member? Can't see why it's necessary:

-init: lines are completely wrong should be: handle = (thislist select 0) execVM "script.sqf"; (thislist select 0) gets the relevant unit as said below don't reassign player

-if (_helotype == UH1Y) then - typeOf returns a string - should be "UH1Y"

- in crewout your addAction has no filename see http://community.bistudio.com/wiki/addAction

- if (_callout ==1) then - _callout must be defined somewhere (can't use an addaction to do it)

_callout = 1; if (_callout ==1) then {};

-rather than triggers - an eventHandler might be better for MP?

to add EH to all blufor helicopters with crew at beginning of mission, script will only work when driver gets in - init.sqf:

{if (side _x == WEST && _x isKindOf "Helicopter") then {_x addEventHandler ["GetIn", "if ((_this select 2) == driver (_this select 0)) then {[(_this select 0),(_this select 2)] execVM 'crewin.sqf'}"];};} forEach vehicles;
{if (side _x == WEST && _x isKindOf "Helicopter") then {_x addEventHandler ["GetOut", "if ((_this select 1) == 'driver') then {[(_this select 0),(_this select 2)] execVM 'crewout.sqf'}"];};} forEach vehicles;

1st one above could also have condition:

{if (side _x == CIVILIAN && _x isKindOf "Helicopter ") then {};

to only add for helicopters with no crew.

crewin.sqf

_vehicle = _this select 0;
 _driver = _this select 1;
   _class = typeOf _vehicle;

action1 = _vehicle addaction [("<t color=""#ee6600"">" + ("Recruit Crew") +"</t>"), "crewmaker.sqf",_class, 1, false, true,"","isEngineOn _target && driver _target == _this"];
//addaction is only available to driver when engine is on

hint "crewIn";

crewout.sqf

_vehicle = _this select 0;
 _driver = _this select 1;
   hint "crewOut";
     _vehicle removeAction action1; //remove the action when pilot gets out

//more code here

crewmaker.sqf

 
_vehicle = _this select 0;
 _caller = _this select 1;
   _id = _this select 2;
     _helotype = _this select 3; //_class passed in addAction arguments

player sidechat format["%1", _helotype];
 hint "crewMaker";

_vehicle removeAction _id; //remove the action once it is activated

//make crew here

You will also need to check locality issues with all the above - the vehicle will move from the server to the player's client when the player gets in so you might need conditions to check where the scripts run with isServer, isLocal , isDedicated etc. see:

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

http://community.bistudio.com/wiki/6thSense.eu:EG

One concern is the AI you create - it migth be best to have them join the players group as you create them so the player and the AI are all in the same locality?

Edited by Mattar_Tharkari
found errors - all working now - added example mission

Share this post


Link to post
Share on other sites

-don't start execVM's with a number handle

It's fine as long as you don't need the actual script handle.

OP, "player" is a command that refers to the object unit of the client, don't try to reassign it.

Share this post


Link to post
Share on other sites

^ init fields if you still want to try to use triggers:

handle = (thislist select 0) execVM "script.sqf";

(thislist select 0) gets the relevant unit, don't reassign player

Share this post


Link to post
Share on other sites

Regarding you not wanting to spend too much time learning the language, you could save some time by keeping it simple. Like spawning the helo already with the crew (minus pilot). Is there any valid reason why you would need an action to dismiss or request crew?

Regards,

David

Edited by Iceman77

Share this post


Link to post
Share on other sites

@ Matthar Tharkari

Thanks for your guidance. I will implement it tonight and will let you know. I did decide to name pilots because I read somewhere that it was better, but if it does not make sense, then, you are totally right, why naming them? I will look for some examples on creating crews without naming them.

@cuel

Thanks, will keep it in mind. As said before, I am new into this and don't understand much of what I am doing.

@ Iceman77

Thanks for your proposal. You are right, spawning a crewed chopper looked like the easiest way, In fact I already spawned helos with full crew and ejected+deleted the pilot, but then one of the gunners jumped out of his place and ran to get into the pilot's place!!! it was a sort of musical chairs game for the pilot place! Unfortunately I have no idea on how to glue the gunner to his position on a spawned chopper with full crew minus the pilot.

Also, I want to clarify something. It is not that I do not want to learn the language. I have responsabilities in real life that prevent me to devote much time to this. I wish I could spend time on this, because being able to handle this looks like real fun, but unfortunately I can't.

As said before, any help to solve this issue, even if it means facing it from a totally different angle, will be highly appreciated.

Share this post


Link to post
Share on other sites

AssignAsGunner

MoveInTurret

MoveInGunner

Should be able to do it with those. Also, demon has a script/workaround for assignAsTurret I think

---------- Post added at 03:28 ---------- Previous post was at 03:25 ----------

or you could have the gunners/crew into their own separate group from the pilot + assignasgunner, maybe that would work too.

Edited by Iceman77

Share this post


Link to post
Share on other sites

@ Iceman77

Thanks for your proposal. You are right, spawning a crewed chopper looked like the easiest way, In fact I already spawned helos with full crew and ejected+deleted the pilot, but then one of the gunners jumped out of his place and ran to get into the pilot's place!!! it was a sort of musical chairs game for the pilot place! Unfortunately I have no idea on how to glue the gunner to his position on a spawned chopper with full crew minus the pilot.

That sort of behaviour is always due to 1 thing - the group leader giving commands. You see, he knows the helicopter should have a pilot and he knows best!

To stop that you need to make them all join the player's group with the player as leader after you have deleted the AI pilot:

_spawnPos = [getPosATL _caller select 0,getPosATL _caller select 1, 500];
 _dir = getDir _caller;
   _vehArray = [_spawnPos, _dir, "UH60M_EP1", WEST] call bis_fnc_spawnvehicle; //you need a functions module (F7) on the map - see notes on createCentre or it will spawn empty
_heli= _vehArray select 0;
 _pilot = driver _heli;
   deleteVehicle _pilot;
     _caller moveInDriver _heli;
{[_x] joinSilent group _caller} forEach crew _heli - [_caller]; //useful item that for running things on the crew excepting the player
 group _caller selectLeader _caller;

/*Warning - In Multiplayer the selectLeader command has to be executed on the client where the group is actually local - note on wiki.
Should be ok as when the player enters the vehicle, the vehicle and crew become local? */

http://community.bistudio.com/wiki/Category:ArmA_2:_Functions

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

Or: this works on a group if you move them into a building and makes them stay in the buidling positions, (not sure if it will work while the group is in a vehicle), the group leader always rearranges them back into formation so:

_pilot = driver _heli;
 _grp = group _pilot;
   _lst = units _grp;
     _ldr = leader _grp;
{[_x] joinsilent grpNull;} forEach _lst -[_ldr]; //each unit gets it's own group and can't then be commanded to move elsewhere

//later you can merge them back into the original group
waitUntil {var_enemyAttack}; // var_enemyAttack = true; in a trigger activated by opfor
{[_x] joinsilent _grp;} forEach _lst -[_ldr];

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

I have tested Mattar_Tharkari's first post solution. Everything goes OK until it arrives to

 if (_helotype == "UH1Y") then {  

Then the script stops.

in crewin.sqf

it was set that

_class = typeOf _vehicle;

so in crewmaker.sqf

_helotype = _this select 3; //_class passed in addAction arguments 

Any idea of what I am doing wrong?

Share this post


Link to post
Share on other sites

_helotype = _this select 3; //_class passed in addAction arguments

are there any other variables passed as you will need to extract the right one.

_helotype = (_this select 3) select x;

x would be the position in the array [a,b,c]

_avar = (_this select 3) select 1;

would return b in this example

Share this post


Link to post
Share on other sites

Just tested it and found a few errors - sorry!

Use this for empty helicopters - empty helos are side civilian till someone gets in:

{if (side _x == civilian && _x isKindOf "Helicopter") then {_x addEventHandler ["GetIn", "if ((_this select 2) == driver (_this select 0)) then {nul = [(_this select 0),(_this select 2)] execVM 'crewin.sqf'}"];}} forEach vehicles;
{if (side _x == civilian && _x isKindOf "Helicopter") then {_x addEventHandler ["GetOut", "if ((_this select 1) == 'driver') then {nul = [(_this select 0),(_this select 2)] execVM 'crewout.sqf'}"];}} forEach vehicles;

In the addaction I left the "" in around the argument so it will be passing "_class" each time lol - remove them:

action1 = _vehicle addaction [("<t color=""#ee6600"">" + ("Recruit Crew") +"</t>"), "crewmaker.sqf",_class, 1, false, true,"","isEngineOn _target && driver _target == _this"];

Also make the handle on the addAction global so getting out removes it as well - my 1st post updated with correct code plus hints that show all is working.

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

Matthar_Tharkari, it almost works.

The script works sweetly on the "crew in" part of it. I get the action, get the crew in, and all, but...

is there any way to prevent the action to appear again if the crew is already in the chopper. (eg. the pilot disembarks the manned helicopter for whatever reason - with the crew in- and then reimbarks again, he gets again the option to order another crew) I was thinking on an argument similar to

if (count crew _unit >= 1)) exitwith { hint " This aircraft has a crew already " }; 

but when tried to insert it, not only the hint did not appear but it disrupted the script. Also, I am not sure if this should go in the crewin.sqf or in the crewmaker.sqf

neverhteless the main issue appears on the second part.

The event handler waits until the player exits the plane to adress to the script, and it adresses to it allright , nevertheless there must be something i did wrong because I can't make the call out action appear and i get the hint " crew dismissed".

_vehicle = _this select 0;
_driver = _this select 1;

//if (count crew _unit == 0)) exitwith {}; // this should work to prevent the action to appear if the helicopter is already empty, right?

_callout = _vehicle addaction ["Dismiss Crew",1];
_callout = 1; 

if (_callout ==1) then 
{
   {deleteVehicle _x} forEach crew _vehicle;

    hint "Crew has been dismissed";

     _vehicle removeAction action1; //remove the action when pilot gets out
};

Honestly, I am quite lost as to why this is happening. (or better said, it is not happening as expected)

Any idea?

Share this post


Link to post
Share on other sites

To delete them they need to be out of the vehicle, you also don't want to force the player out.

_vehicle = _this select 0;
_driver = _this select 1;

//if (count crew _unit == 0)) exitwith {}; // this should work to prevent the action to appear if the helicopter is already empty, right?

_callout = _vehicle addaction ["Dismiss Crew",1];
_callout = 1; 

if (_callout ==1) then 
{
   {_x action ["getout",_vehicle];sleep 0.1;deleteVehicle _x } foreach crew _vehicle -[player];

    hint "Crew has been dismissed";

     _vehicle removeAction action1; //remove the action when pilot gets out
};

Edited by F2k Sel

Share this post


Link to post
Share on other sites

What do you have in crewOut.sqf? that removeAction should work?

If not then you need to broadcast it with either:

_id = _this select 2;
[nil, _object, "per", rREMOVEACTION, _id] call RE;

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

or

[-2, {_id = _this select 2; _object removeAction _id;},_this] call CBA_fnc_GlobalExecute;

https://dev-heaven.net/docs/cba/files/network/fnc_globalExecute-sqf.html

You will need the CBA addon

_callout = _vehicle addaction ["Dismiss Crew",1];

RE this - I am unfamiliar with this - what does it do exactly? Is it correct syntax in the 1st place?

What I would do is:

_callout = _vehicle addaction ["Dismiss Crew","dismiss.sqf"];

//dismiss.sqf:

_object = _this select 0;
_caller = _this select 1;
_id = _this select 2;
{moveOut _x; deleteVehicle _x;} foreach (crew _object);
_object removeAction _id;

If you are deleting and creating the crew based on the 2 EH's not sure why you neeed another option? It can all be done with in the 2 EH's?

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

FsK Sel

What do you mean you don't want to force the player out? the file crewout.sqf is activated by a "getout" event handler, so the pilot has -theorically- to be out. Your solution does not bring up the action needed to dismiss the crew. What I don't understand is why I still get the message " the crew has been dismissed" when I get out of the helicopter If I did not select the action (in fact, the crew is still in the helicopter)

sorry, mattar, I cannot follow you. Where should those lines go? (have CBA and ACE).

The getout.sqf is right now:

_vehicle = _this select 0;
_driver = _this select 1;

//if (count crew _unit == 0)) exitwith {}; // this should work to prevent the action to appear if the helicopter is already empty, right?

_callout = _vehicle addaction ["Dismiss Crew",1];
_callout = 1; 

if (_callout ==1) then 
{
   {deleteVehicle _x} forEach crew _vehicle;

    hint "Crew has been dismissed";

     _vehicle removeAction action1; //remove the action when pilot gets out
};

Share this post


Link to post
Share on other sites

It doesn't make sense:

_vehicle = _this select 0;
_driver = _this select 1;
//if (count crew _unit == 0)) exitwith {}; // this should work to prevent the action to appear if the helicopter is already empty, right?
_callout = _vehicle addaction ["Dismiss Crew",1];
_callout = 1; 
if (_callout ==1) then 
{
   {deleteVehicle _x} forEach crew _vehicle;
    hint "Crew has been dismissed";
     _vehicle removeAction action1; //remove the action when pilot gets out
};

is the same as:

_vehicle = _this select 0;
_driver = _this select 1;

//if (count crew _unit == 0)) exitwith {}; // this should work to prevent the action to appear if the helicopter is already empty, right?

   {deleteVehicle _x} forEach crew _vehicle;
    hint "Crew has been dismissed";
     _vehicle removeAction action1; //remove the action when pilot gets out

The _callout is pointless as it doesn't do anything??? You may as well run the script allth eway through in the 1st place.

This will not work BTW, you can't delete crew while they are sitting in the vehicle - you need to move them out of the vehicle in someway 1st, moveOut/getOut/setPosATL etc:

{deleteVehicle _x} forEach crew _vehicle;

It needs to be:

{moveOut _x; deleteVehicle _x} forEach crew _vehicle;

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

OK

I finally got it working.

First of all, thanks to those who have brought their ideas in this thread and specially to Mattar_Tharkari. His excellent help has been key to make this happen.

Here is the script in case anybody want to use it to crew with AI the aircraft piloted by human players.

1.- Create a folder in your mission called scripts and inside it create another folder called helocrew

In the init.sqf insert

{if (side _x == civilian && _x isKindOf "Helicopter") then {_x addEventHandler ["GetIn", "if ((_this select 2) == driver (_this select 0)) then {nul = [(_this select 0),(_this select 

2)] execVM 'scripts\helocrew\crewin.sqf'}"];}} forEach vehicles;

create a file called crewin.sqf and copy this code there

_vehicle = _this select 0;
 _driver = _this select 1;
   _class = typeOf _vehicle;


if (count crew _vehicle < 2) then {

action1 = _vehicle addaction [("<t color=""#ee6600"">" + ("Request Crew") +"</t>"), "scripts\helocrew\crewmaker.sqf",_class, 1, false,true,"","isEngineOn _target && driver _target == 

_this"]; //addaction is only available to driver when engine is on
hint "Start Engine for Crew Options";


} else {

hint "This aircraft is already crewed. To dismiss the crew, land and stop the engine";

action2 = _vehicle addaction [("<t color=""#ee6600"">" + ("Dismiss Crew") +"</t>"), "scripts\helocrew\crewout.sqf",_class, 1, false,true,"","!isEngineOn  _target && driver _target == 

_this"]; //addaction is only available to driver when engine is off

};

Create a file called crewmaker.sqf and paste this code in it.

 
_vehicle = _this select 0;
 _caller = _this select 1;
   _id = _this select 2;
     _helotype = _this select 3; 

player sidechat format["%1", _helotype];

_vehicle removeAction _id; //remove the action once it is activated
_spawnpoint = getMarkerPos "pilotspawn";
_grp = createGroup west;

//each type of helicopter has a different crew configuration. If you want a type of chopper handled exclusively by humans, just delete the code group for that type of chopper.

if (_helotype == "UH1Y") then { 

_pilot1 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this assignasgunner _vehicle; this moveinturret [_vehicle, [2]];this setskill 1", 1, "Lieutenant"];
_pilot2 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this assignasgunner _vehicle; this moveinturret [_vehicle, [0]];this setskill 1", 1, "sergeant"];
_pilot3 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this assignasgunner _vehicle; this moveinturret [_vehicle, [1]];this setskill 1", 1, "sergeant"];

hint "Crew is in the aircraft";


};

if (_helotype == "UH60M_EP1") then
{
_pilot4 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this moveincargo [_vehicle, 12]; this setskill 1", 1, "Lieutenant"];
_pilot5 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this assignasgunner _vehicle; this moveinturret [_vehicle, [0]];this setskill 1", 1, "sergeant"];
_pilot6 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this assignasgunner _vehicle; this moveinturret [_vehicle, [1]];this setskill 1", 1, "sergeant"];

hint "Crew is in the aircraft";

};

if (_helotype == "CH_47F_EP1") then
{

_pilot7 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this moveincargo [_vehicle, 0]; this setskill 1", 1, "Lieutenant"];
_pilot8 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this assignasgunner _vehicle; this moveinturret [_vehicle, [0]];this setskill 1", 1, "sergeant"];
_pilot9 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this assignasgunner _vehicle; this moveinturret [_vehicle, [1]];this setskill 1", 1, "sergeant"];
_pilot10 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this assignasgunner _vehicle; this moveingunner _vehicle; this setskill 1", 1, "sergeant"];

hint "Crew is in the aircraft";

};    

if (_helotype == "MH6J_EP1") then
{

_pilot11 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this moveincargo [_vehicle, 0]; this setskill 1", 1, "Lieutenant"];

hint "Crew is in the aircraft";

}; 

if (_helotype == "AH6J_EP1") then
{

_pilot12 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this moveincargo [_vehicle, 0]; this setskill 1", 1, "Lieutenant"];

hint "Crew is in the aircraft";

}; 

if (_helotype == "AH64D_EP1") then
{

_pilot13 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this assignasgunner _vehicle; this moveinturret [_vehicle, [0]];this setskill 1", 1, "Lieutenant"];

hint "Crew is in the aircraft";

}; 

if (_helotype == "AH1Z") then
{

_pilot13 = "US_Soldier_Pilot_EP1" createUnit [_spawnpoint, _grp, "this assignasgunner _vehicle; this moveinturret [_vehicle, [0]];this setskill 1", 1, "Lieutenant"];

hint "Crew is in the aircraft";

}; 


_vehicle removeAction _id;
sleep 5;
hint "To dismiss the crew, land and stop the engine";

action2 = _vehicle addaction [("<t color=""#ee6600"">" + ("Dismiss Crew") +"</t>"), "scripts\helocrew\crewout.sqf",_class, 1, false,true,"","!isEngineOn  _target && driver _target == 

_this"]; 

create a file called crewout.sqf and copy this code there

_vehicle = _this select 0;
_driver = _this select 1;
_action2 = _this select 2;

{moveOut _x; deleteVehicle _x;} foreach (crew _vehicle);

_vehicle removeAction _action2;
hint "Crew has been dismissed";

put crewin.sqf, crewout.sqf and crewmaker.sqf in the folder called Helocrew in the scripts folder.

I am not sure if it works better, but in order to improve efficiency, in the editor, select the empty chopers that you expect to man with this script and choose "actual" as age info and move the efficiency slide all the way to the right.

How does it work?

When a Human player jumps into the sit of a empty helicopter, an action appears in his option menu. He can then request a crew for his aircraft. The script does an automatic identification of the type of helicopter and delivers an adequate full crew (copilot and where applicable, gunners ) to the helicopter. The gunners will detect enemy threats, announce them to the pilot and open fire.

In order to get rid of the crew (or if one or more of the crew have been injured or killed, or just because in the next flight human players will man the guns), the pilot will have to land and after switching off the engine, a option appears in the option menu to dismiss the crew. At this point the pilot can choose to select no action and leave the crew waiting in the helicopter (eg. if they are not injured), or dismiss them and off they will go.

Upon boarding the chopper again, the pilot will again be prompted if he wants to recruit a fresh crew, or in case that the helicopter is already crewed, he will be informed of that fact and the option to order another crew will not appear.

This is my first clumpsy attempt for a script and summarizes all my poor skills at scripting. It undoubtely can be modified or improved (eg. making the crew spawn in a tent near the helicopter line and have them running to the chopper, or from the chopper to the tent when they are dismissed. make the crew join the pilot, delete crew survivors in case of crash, etc....). Please, feel free to do any changes you see fit, but it would be good if you posted the improvements in this post so everybody can benefit of them.

Enjoy!.

Edited by CC_Kronus

Share this post


Link to post
Share on other sites

Well done! Always room for improvement though - I wondered if there was a game function that would make things easier for you, turns out there is:

If you sit in the pilots seat and put this in a radio trigger it fills the empty crew spaces and joins them to your group - all in 1 line lol. (functions module required on map)

nul = [vehicleName, group player] call BIS_fnc_spawnCrew;

if you add that to the eventHandlers:

for empty helicopters:

{if (side _x == Civilian && _x isKindOf "Helicopter") then {
_x addEventHandler ["GetIn", "if ((_this select 2) == driver (_this select 0)) then {[(_this select 0), group player] call BIS_fnc_spawnCrew; hint 'crew spawned';}"];};} forEach vehicles;

{if (side _x == Civilian && _x isKindOf "Helicopter") then {
_x addEventHandler ["GetOut", "if ((_this select 1) == 'driver') then {{moveOut _x; deleteVehicle _x} forEach crew (_this select 0); hint 'crew deleted';}"];};} forEach vehicles;

Better method: for all vehicles with a driver position and cfg side WEST (will work even if empty):

{if (getNumber(configFile >> "CfgVehicles" >> (typeOf _x) >> "hasDriver")==1 && getNumber(configFile >> "CfgVehicles" >> (typeOf _x) >> "side") == 1) then {
_x addEventHandler ["GetIn", "if ((_this select 2) == driver (_this select 0)) then {[(_this select 0), group player] call BIS_fnc_spawnCrew; hint 'crew spawned';}"];};} forEach vehicles;

{if (getNumber(configFile >> "CfgVehicles" >> (typeOf _x) >> "hasDriver")==1 && getNumber(configFile >> "CfgVehicles" >> (typeOf _x) >> "side") == 1) then {
_x addEventHandler ["GetOut", "if ((_this select 1) == 'driver') then {{moveOut _x; deleteVehicle _x} forEach crew (_this select 0); hint 'crew deleted';}"];};} forEach vehicles;

In the config "side"=0 is opfor, "side" = 1 is blufor, "side" = 2 is guer, "side" = 3 is civ

Never drive / fly alone again lol!

Example mission - has the functions viewer on radio alpha as well so you can look through the BIS functions

https://dl.dropbox.com/u/37698503/BIS_fnc_spawnCrew.Shapur_BAF.zip

Edited by Mattar_Tharkari

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  

×