Jump to content
evokerzz

Automatic eject via vehicle's init line

Recommended Posts

I created a vehicle init script a few months ago with the purpose of automatically making the plane auto-eject pilots when the damage to the plane exceeds a certain threshold while limiting the damage to .9 for a few seconds preventing it from blowing up instantly. After a recent arma update however the script stopped working so I'm hoping that maybe someone more experienced in arma scripting can help me out with it.

My current revisions (seperated with a line) of the vehicle init with comments: https://pastebin.com/XSyXyES1

I'm trying to avoid using seperate script files to make this a simple copy-paste solution for everyone who isn't that familiar with mission editing.

  • Like 1

Share this post


Link to post
Share on other sites

{unassignVehicle _x;moveout _x } forEach crew f15;

  • Like 1

Share this post


Link to post
Share on other sites

that didn't work

current revision... 
to clear things a bit more: it should work with anyone who's in the plane, regardless if it's a player who starts out in the plane, a random player who took it from a hangar or an AI unit.. at least that's how it did work pre-update
 

this addEventHandler ["HandleDamage", {.9;}];  
dummy = this spawn {  
    waitUntil {(damage _this) > 0.8}; 
    {  
        {unassignVehicle _x; moveout _x} forEach crew f15; //still doesnt force units out of the plane
    };
    sleep 5;
    _this removeEventHandler["HandleDamage",0]; 
    sleep 5; 
    _this setdamage 1;  
};



*edit: i cannibalised the survivable crashes mod a bit and stumbled upon this piece of code (credit to rafael09ed on armaholic) and replaced "{unassignVehicle _x; moveout _x} forEach crew f15;" with it
it's not working as is but i think it might be a start to something, right now it gives an error saying "error undefined variable in expression: _unit" when the events reach the point of triggering that part of the init, just gotta figure out how to fix that
 

_unit action ["eject", vehicle _unit];
if (vehicle _unit != _unit) then {
moveOut _unit;
};



 

Edited by evokerzz
more info

Share this post


Link to post
Share on other sites

this addEventHandler ["HandleDamage", {0.84}];

0 = this spawn {

  waitUntil {(damage _this) > 0.8};

  { _x addBackpackGlobal "B_Parachute"; sleep 0.2; unassignVehicle _x; moveout _x} forEach crew f15;

  sleep 5;

  _this removeEventHandler["HandleDamage",0];

  sleep 5;

  _this setdamage 1;

};

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Try this code, more convenient i think.

(Still in init field of the aircraft)

 

if (isServer) then {  
  {_x setVariable ["bpk",unitBackpack _x]} foreach crew this;
  this addEventHandler ["HandleDamage", {
   params ["_veh","","_dam"];  
    if (_dam > 0.6 && !(_veh getVariable ["treated",false])) exitWith {
      [_veh, _thiseventHandler] spawn {
        params ["_veh","_eh"];
        _veh setVariable ["treated",true];
        _units = crew _veh;
        { _x allowDamage false;  _x addBackpackGlobal "B_Parachute"; sleep 0.2; unassignVehicle _x; moveout _x} forEach _units;
        uisleep 3;
        {_x allowDamage true;
         _x spawn {
          waituntil {(getPosATL _this) select 2 < 6};
          uisleep 4;
        if (!isNull (_this getVariable["bpk",objNull])) then {
          (_this getvariable "bpk") setPos (_this getpos [3,getDir _this]);
        _this action ["takeBag",(_this getVariable "bpk")]
        }
        }
        } forEach _units;
        uisleep 4;
        _veh removeEventHandler ["HandleDamage", _eh]
      };
    };   
  0.82   
  }]
};

 

  • Like 1

Share this post


Link to post
Share on other sites

Key factor in this..

{unassignVehicle _x;moveout _x }

 

if only I had of thought of this..

 

Oh. yeah.. I did.

Share this post


Link to post
Share on other sites
5 hours ago, pierremgi said:

this addEventHandler ["HandleDamage", {0.84}];

0 = this spawn {

  waitUntil {(damage _this) > 0.8};

  { _x addBackpackGlobal "B_Parachute"; sleep 0.2; unassignVehicle _x; moveout _x} forEach crew f15;

  sleep 5;

  _this removeEventHandler["HandleDamage",0];

  sleep 5;

  _this setdamage 1;

};


this works perfectly, thank you :), even though there's about a 1 in 10 chance where the pilot gets injured by shrapnel from a 2nd missile (haven't been killed yet after 20 tests)

meanwhile your longer script only seems to work when i haven't touched the controls for about a second before the missile impact..

@Beerkan yes, you did, but for some reason it didn't force the crew out of the plane, no idea why, even though by all logic it should

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

×