Jump to content
Sign in to follow this  
A-SUICIDAL

Switching littlebird attack chopper passenger into driver seat?

Recommended Posts

Out of the handful of vehicles in my mission, I have one Littlebird attack chopper and sometimes the pilot accidentally kills a teammate or civilian with rockets or minigun fire - and the pilot then gets punished and ejected and sent to jail for a couple of minutes. What I would like to do is switch the co-pilot into the driver seat before the chopper crashes. I just need to do this for this one vehicle, none of the other birds in my mission offer the ability for a pilot to fire weapons. The AI are disabled in this mission, so I don't need to worry about ai really, but it would be fun to test it with ai and see it actually work. Anyway, lets say player "s1" is the driver of littlebird1 and when he gets tossed into jail there is a publicVariable "s1_inJail" that fires right away. So I have a script that first checks to see who did the wrongful kill, then it checks to see what vehicle the killer was in and depending on if it's player s1 through s14, it will execute the corresponding script, so...

if (s1 == driver littlebird1) then {[] execVM "check_littlebird1.sqf";};

So the first thing I assume I need to do is waitUntil "s1_inJail" is ready to be used as a condition. But then I need to somehow get a list of units "s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14" that could possibly be in the cargo seat of littlebird1, and then do something like the following.

check_littlebird1.sqf


waitUntil {s1_inJail};

// now I need to somehow get a list of possible units s2-s14 that might be in the cargo seat of littlebird1
// and then switch that unit into the pilot seat - hopefully before the chopper crashes and ruins any chance of the passenger being able to eject.

if ((s1_inJail) && (_unit in littlebird1)) then {

unassignVehicle _unit;
   	doGetOut _unit;
   	sleep 1;
_unit assignAsDriver littlebird1;
[_unit] orderGetIn true;
_unit moveInDriver littlebird1;
littlebird1 engineOn true;
};

Now I tried doing this so many different ways.

I'm sure I was close a few times, but I just couldn't get it working

- and dealing with passenger seats is sometimes tricky, especially when you can use commands like:

gunner _veh

driver _veh

but there is no... cargo _veh

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

Yeah, that was the first thing I tried, but it didn't seem to work. I thought that maybe it was because the guy sitting in the passenger seat was never actually assigned to the cargo of the vehicle. But I think once he is forced out of the vehicle, he then suddenly becomes assigned to the vehicle somehow. Maybe that's why ai commanders are always telling me to get back in a vehicle that I just hopped in-and-out of for a moment - with no intention of getting back in.

Anyway, I tried again to use the script that you suggested and now suddenly it seems to be working. I'm guessing I must have made a typo the first time around because the script you posted looks identical to what my first attempt looked like.

This seems to be working fine. There's actually almost no delay between the pilot leaving the vehicle and the passenger automatically switching to his seat. So that's good. I might try to use this for my other choppers in the event of the pilot getting shot and killed. I mean come on, in real life, if a blackhawk pilot gets shot and killed, you can bet your ass somebody is going to take his seat fast. Some how I can't picture a bunch of guys in cargo just saying F-it, lets just go down with the ship. Or maybe a script that ejects all crew in the event that the pilot died, nah, I like the first idea better.

waitUntil {s1_inJail};

_list = assignedCargo littlebird1;
_unit = _list select 0;

unassignVehicle _unit;
doGetOut _unit;
sleep 1;
_unit assignAsDriver littlebird1;
[_unit] orderGetIn true;
_unit moveInDriver littlebird1;
littlebird1 engineOn true;

Thank you Mattar_Tharkari :)

Share this post


Link to post
Share on other sites

I'm having trouble getting this same thing to work for an attack chopper with gunner seat.

So let's say I am flying either an "AH64D_EP1", "AH64D", or an "AH1Z" and I use manual fire and kill a teammate, then my punish script start running and just before it forces me out of the chopper and teleports me into jail, I want to first check if the vehicle to see if there is anybody in the gunner seat and prepare to switch him into the driver seat after I am no longer in the chopper.

In the example above I use a specific condition (s1_inJail), and I refer to the vehicle by name "littlebird1", but I don't want to use a bunch of scripts specific to each player s1-s14 and I don't want to use chopper names either, so in my punish script I added this:

_veh = (vehicle _killer);

if (_veh isKindOf "AH6J_EP1") then {
null = [_killer] execVM "cargo_check.sqf";
};

cargo_check.sqf:

_killer = _this select 0;
_veh = (vehicle player);

if (driver _veh == _killer) then {
waitUntil {driver _veh != _killer};
};

_list = assignedCargo _veh;
_unit = _list select 0;

doGetOut _unit;
sleep 0.5;
_unit moveInDriver _veh;
_veh engineOn true;

if ((local _unit) && (!isServer)) then {

5 cutText ["YOU ARE NOW THE PILOT","PLAIN DOWN",2];
sleep 5;
5 cutText ["","PLAIN DOWN",2];
};

When I tested this, the ai in cargo did switch to the driver seat. I'm not sure if the message worked correctly or not, my guess is that I might have wrote that part wrong.

So now I try to do the same for the attack choppers that have gunner seats, but I can't get it to work.

if ((_veh isKindOf "AH64D_EP1") OR (_veh isKindOf "AH64D") OR (_veh isKindOf "AH1Z")) then {
null = [_killer] execVM "gunner_check.sqf";
};

gunner_check.sqf


_killer = _this select 0;
_veh = (vehicle player);

if (driver _veh == _killer) then {

waitUntil {driver _veh != _killer};
};

_list = assignedGunner _veh;
_unit = _list select 0;

doGetOut _unit;
sleep 0.5;
_unit moveInDriver _veh;
_veh engineOn true;

if (local _unit2 && !isServer) then {

5 cutText ["YOU ARE NOW THE PILOT","PLAIN DOWN",2];
sleep 5;
5 cutText ["","PLAIN DOWN",2];
};

It gives me an error. Any idea what I need to do to fix this?

Share this post


Link to post
Share on other sites

I think I figured it out.

So now when I am flying one of few different types of attack choppers and I kill a teammate with manual fire, it will kick me out of the chopper and send me to jail and the gunner will take the pilot seat.

if ( (vehicle player != player) && ((_veh isKindOf "AH64D_EP1") OR (_veh isKindOf "AH64D") OR (_veh isKindOf "AH1Z")) ) then {
null = [_killer] execVM "jail\check_gunner.sqf";
};

check_gunner.sqf:

_killer = _this select 0;
_veh = (vehicle player);

if (isNull assignedGunner _veh) exitWith {};
_gunner = (assignedGunner _veh);

if (driver _veh == _killer) then {
waitUntil {driver _veh != _killer};
};

doGetOut _gunner;
sleep 0.5;
_gunner moveInDriver _veh;
_veh engineOn true;

if ((local _gunner) && (!isServer)) then {

cutText ["YOU ARE NOW THE PILOT","PLAIN DOWN",2];
sleep 8;
cutText ["","PLAIN DOWN",2];
};

Share this post


Link to post
Share on other sites

Basically you need to make sure you run the moveInDriver command on the machine where the wannabe driver is local, or else nothing will happen. You just need to make sure the script executes on the machine of the copilot or whoever else you want to take over. Since you don't know in advance who it will be, the script needs to run a check on all machines when the pilot is sent to jail (preferably via addPublicVariableEventHandler or something similar, and then if you are the co-pilot then you moveInDriver, else do nothing.

Share this post


Link to post
Share on other sites

What if I did it like this?

_killer = _this select 0;
_veh = (vehicle player);

if (isNull assignedGunner _veh) exitWith {};
gunr = (assignedGunner _veh);
publicVariable "gunr";

if (driver _veh == _killer) then {
waitUntil {driver _veh != _killer};
};

null = [gunr] execVM "moveInDriver.sqf";

moveInDriver.sqf:

_unit = _this select 0;

doGetOut _unit;
sleep 0.5;
_unit moveInDriver _veh;
_veh engineOn true;

cutText ["YOU ARE NOW THE PILOT","PLAIN DOWN",2];
sleep 8;
cutText ["","PLAIN DOWN",2];

Would that work?

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

init.sqf:

vehicleList = ...
if (!isDedicated) then {execVM "client.sqf"};

takeover.sqf:

if (((vehicle player) in vehicleList) && (isNull (driver vehicle player))) then
// maybe also check if vehicle is moving using the velocity command
{
player moveInDriver vehicle;
};

client.sqf

fnc_checkTakeOver = compile preprocessFileLineNumbers "takeover.sqf"
while {true} do
{
[] call fnc_checktakeOver;
sleep .01;
}

Edited by galzohar

Share this post


Link to post
Share on other sites

I tried what you said, spent several hours on it, but I'm not having much luck.

Share this post


Link to post
Share on other sites

Did you make sure the helo is in vehicleList? As in:

vehicleList = [helo1, helo2];

Then the above code *should* work without anything extra.

Share this post


Link to post
Share on other sites

I put my poorman skills to work, lol. I added 22 playable units to the sample mission just so I could make it easier for somebody else to implement the punish script later if they wish to use the script. My sample mission was looking clean and simple until I then added 22 triggers, 1 for each player, which handles the pub var stuff for switching to players to driver seat. I know, I know, but it should work until I can get help with a better solution.

In the middle of my punish script, just before it teleports the player into jail, it does this...

if (_veh isKindOf "AH6J_EP1") then {
null = [_killer] execVM "jail\check_cargo.sqf";
};

if ( ((_veh isKindOf "AH64D_EP1") OR (_veh isKindOf "AH64D") OR (_veh isKindOf "AH1Z")) ) then {
null = [_killer] execVM "jail\check_gunner.sqf";
};

check_cargo.sqf

_killer = _this select 0;
_veh = (vehicle player);

if (driver _veh == _killer) then {
waitUntil {driver _veh != _killer};
};

_list = assignedCargo _veh;
_unit = _list select 0;

if (_unit == s1) then {
s1_toDriver = true;
publicVariable "s1_toDriver";
};

if (_unit == s2) then {
s2_toDriver = true;
publicVariable "s2_toDriver";
};

if (_unit == s3) then {
s3_toDriver = true;
publicVariable "s3_toDriver";
};

if (_unit == s4) then {
s4_toDriver = true;
publicVariable "s4_toDriver";
};

if (_unit == s5) then {
s5_toDriver = true;
publicVariable "s5_toDriver";
};

if (_unit == s6) then {
s6_toDriver = true;
publicVariable "s6_toDriver";
};

if (_unit == s7) then {
s7_toDriver = true;
publicVariable "s7_toDriver";
};

if (_unit == s8) then {
s8_toDriver = true;
publicVariable "s8_toDriver";
};

if (_unit == s9) then {
s9_toDriver = true;
publicVariable "s9_toDriver";
};

if (_unit == s10) then {
s10_toDriver = true;
publicVariable "s10_toDriver";
};

if (_unit == s11) then {
s11_toDriver = true;
publicVariable "s11_toDriver";
};

if (_unit == s12) then {
s12_toDriver = true;
publicVariable "s12_toDriver";
};

if (_unit == s13) then {
s13_toDriver = true;
publicVariable "s13_toDriver";
};

if (_unit == s14) then {
s14_toDriver = true;
publicVariable "s14_toDriver";
};

if (_unit == s15) then {
s15_toDriver = true;
publicVariable "s15_toDriver";
};

if (_unit == s16) then {
s16_toDriver = true;
publicVariable "s16_toDriver";
};

if (_unit == s17) then {
s17_toDriver = true;
publicVariable "s17_toDriver";
};

if (_unit == s18) then {
s18_toDriver = true;
publicVariable "s18_toDriver";
};

if (_unit == s19) then {
s19_toDriver = true;
publicVariable "s19_toDriver";
};

if (_unit == s20) then {
s20_toDriver = true;
publicVariable "s20_toDriver";
};

if (_unit == s21) then {
s21_toDriver = true;
publicVariable "s21_toDriver";
};

if (_unit == s22) then {
s22_toDriver = true;
publicVariable "s22_toDriver";
};[/spoiler]

check_gunner.sqf

_killer = _this select 0;
_veh = (vehicle player);

if (isNull assignedGunner _veh) exitWith {};

if (driver _veh == _killer) then {
waitUntil {driver _veh != _killer};
};

_unit = (assignedGunner _veh);




if (_unit == s1) then {
s1_toDriver = true;
publicVariable "s1_toDriver";
};

if (_unit == s2) then {
s2_toDriver = true;
publicVariable "s2_toDriver";
};

if (_unit == s3) then {
s3_toDriver = true;
publicVariable "s3_toDriver";
};

if (_unit == s4) then {
s4_toDriver = true;
publicVariable "s4_toDriver";
};

if (_unit == s5) then {
s5_toDriver = true;
publicVariable "s5_toDriver";
};

if (_unit == s6) then {
s6_toDriver = true;
publicVariable "s6_toDriver";
};

if (_unit == s7) then {
s7_toDriver = true;
publicVariable "s7_toDriver";
};

if (_unit == s8) then {
s8_toDriver = true;
publicVariable "s8_toDriver";
};

if (_unit == s9) then {
s9_toDriver = true;
publicVariable "s9_toDriver";
};

if (_unit == s10) then {
s10_toDriver = true;
publicVariable "s10_toDriver";
};

if (_unit == s11) then {
s11_toDriver = true;
publicVariable "s11_toDriver";
};

if (_unit == s12) then {
s12_toDriver = true;
publicVariable "s12_toDriver";
};

if (_unit == s13) then {
s13_toDriver = true;
publicVariable "s13_toDriver";
};

if (_unit == s14) then {
s14_toDriver = true;
publicVariable "s14_toDriver";
};

if (_unit == s15) then {
s15_toDriver = true;
publicVariable "s15_toDriver";
};

if (_unit == s16) then {
s16_toDriver = true;
publicVariable "s16_toDriver";
};

if (_unit == s17) then {
s17_toDriver = true;
publicVariable "s17_toDriver";
};

if (_unit == s18) then {
s18_toDriver = true;
publicVariable "s18_toDriver";
};

if (_unit == s19) then {
s19_toDriver = true;
publicVariable "s19_toDriver";
};

if (_unit == s20) then {
s20_toDriver = true;
publicVariable "s20_toDriver";
};

if (_unit == s21) then {
s21_toDriver = true;
publicVariable "s21_toDriver";
};

if (_unit == s22) then {
s22_toDriver = true;
publicVariable "s22_toDriver";
};[/spoiler]

An example of a repeating trigger trigger for player s8 would look like this:

Condition: s8_toDriver

Activation: null = [s8] execVM "jail\toDriver.sqf"; s8_toDriver = false; publicVariable "s8_toDriver";

and finally...

toDriver.sqf

_unit = _this select 0;
_veh = (vehicle _unit);

doGetOut _unit;
sleep 0.5;
_unit moveInDriver _veh;
_veh engineOn true;

if ((local _unit) && (!isServer)) then {

cutText ["YOU ARE NOW THE PILOT","PLAIN DOWN",2];
sleep 8;
cutText ["","PLAIN DOWN",2];
};

It tested fine in single player and hosted MP, but I haven't had the chance to test it with anybody in Dedi.

My Punish script is basically done. I managed to use something like Demonized's method to initially add the EH to all the units, so now I don't lose the EH after I die anymore.

I was going to test it a bit more, record/upload a very short movie and post it for download, but it's has not been fully dedi tested. I'm hoping to get help with that. I made a new jail cell that is actually viewable in the editor now, it looks much nicer too.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

I changed my script. I am going to use it in the next version of my team kill punish script. If a pilot teamkills and is teleported into jail, it used to move either an assignedGunner or assignedCargo unit into the driver seat, but I kept playing with it and tried to get it to work for all turret positions and this is what I came up with:

part of the script that would eject the team killing pilot from the vehicle...

if (vehicle _killer != _killer) then {
null = [_killer] execVM "jail\check_crew.sqf";
doGetOut _killer;
sleep 0.5;
};
//then the killer/pilot gets teleported into jail.

check_crew.sqf:

_killer = _this select 0;
_veh = (vehicle _killer);

if (driver _veh == _killer) then 
{
   waitUntil {driver _veh != _killer};
};

_man0 = _veh turretUnit [0]; 

if (!isNull _man0) exitWith 
{
   waitUntil{!(isNil "BIS_MPF_InitDone")};
   [nil, _man0, "loc", rEXECVM, "jail\toDriver.sqf", _man0] call RE;
};

_man1 = _veh turretUnit [1]; 

if (!isNull _man1) exitWith 
{
   waitUntil{!(isNil "BIS_MPF_InitDone")};
   [nil, _man1, "loc", rEXECVM, "jail\toDriver.sqf", _man1] call RE;
};

_man2 = _veh turretUnit [2]; 

if (!isNull _man2) exitWith 
{
   waitUntil{!(isNil "BIS_MPF_InitDone")};
   [nil, _man2, "loc", rEXECVM, "jail\toDriver.sqf", _man2] call RE;
};

_crewList = assignedCargo _veh;
_crewMan = _crewList select 0;

if ((!isNull _crewMan) && (_crewMan in _veh)) exitWith 
{
   waitUntil{!(isNil "BIS_MPF_InitDone")};
   [nil, _crewMan, "loc", rEXECVM, "jail\toDriver.sqf", _crewMan] call RE;
};

toDriver.sqf:

_unit = _this select 0;
_veh = (vehicle _unit);

unassignVehicle _unit;
doGetOut _unit;
sleep 1;
_unit assignAsDriver _veh;
_unit moveInDriver _veh;

_unit action ["EngineOn", _veh];
_veh engineOn true; 

if ((local _unit) && (!isServer)) then {
   cutText ["YOU ARE NOW THE PILOT","PLAIN DOWN",2];
   sleep 8;
   cutText ["","PLAIN DOWN",2];
};

The only problem I have encountered when testing is... on a dedicated server, if an ai unit is moved into the pilot seat, the engine never turns on and the air vehicle crashes into the ground. When I test in single player or hosted environment, everything works smoothly. You can see in the script that I tried using 2 different methods to get the engine to turn back on, but both fail to work on a dedicated server. Any ideas as to how I can get the engine to turn back on for a dedicated server?

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  

×