Script: Getting out of vehicles - enhancement

Party-approved programming
Post Reply
Black Mamba
Posts: 335
Joined: Sun May 27, 2012 12:11 pm

Script: Getting out of vehicles - enhancement

Post by Black Mamba »

Hey there again. I came up with this script idea one or two sessions back, when I got out of a vehicle, and my character obviously decided to jump out the side we were taking fire from.
So the basic idea here is to provide every player with a choice when (s)he disembarks: want to jump out left, or right?
Then, I remembered all those times my FTL would tell me "when we get out of the chopper, you take the left side", and again my dude would randomly decide to go out right. So I expanded that to the choppers (not the Chinook though, you get out from the back as everyone else)
Then I got to the littlebird, but you obviously couldn't get out from the left when you're on the right skid, right?
So I implemented a system that those who know Dsly's st_littlebird_enhancement will recognize (but simpler, and no shooting from the skids). You can move on the skids from one place to another, and dismount exactly where you're looking. No more rooftop insertions "Damn I missed the building!".
This script is pretty easy to include in your mission, as it doesn't need you to keep track of the vehicles you placed. It also doesn't take time to create some big array containing all the vehicles: everything is done on the fly, as a mod would do.
Just paste it somewhere and call it from the init.sqf

Code: Select all

call compile preprocessfileLineNumbers "Custom\BM_vehicleSeats_Enhancement.sqf";
Note that it relies on two of my other scripts, here and here.

BM_vehicleSeats_Enhancement.sqf

Code: Select all

/*      BM_vehicleSeats_Enhancement
This script gives every player the ability to chose if he wants to jump out from a vehicle to the right or to the left.
It will work for any land vehicle, as well as most choppers (the option won't be provided for the pilot).
The MH6 will give you the possibility to move on the skids from one seat to another, as well as the ability to perform
precision dismounts (dismount where you're looking).
It is pretty easy to use as you don't need to register any vehicle and/or _units for it to work. It is also reasonably performance friendly, and doesn't create
huge arrays.
It relies on the following scripts:
   - BM_addAction.sqf
   - BM_XEH.sqf
   
Example: (init.sqf)
call compile preprocessfileLineNumbers "Custom\BM_XEH.sqf";
call compile preprocessfileLineNumbers "Custom\BM_vehicleSeats_Enhancement.sqf";

All three scripts being in a Custom folder, at the root of the mission folder.
This script will hopefully be expanded in the future.
*/

BM_fn_dirTo = {
   _pos1 = _this select 0;
   _pos2 = _this select 1;
   _dir = ((_pos2 select 0) - (_pos1 select 0)) atan2 ((_pos2 select 1) - (_pos1 select 1));
   _dir = _dir % 360;
   if (_dir < 0) then {_res = 360 + _res};
   _dir
};

BM_fn_JumpOut = {
   _veh = _this select 0;
   _side = _this select 3;
   _bb = boundingBox _veh;
   _posX = (_bb select _side) select 0;
   _pos = _veh worldToModel (getPosATL player);
   _posY = _pos select 1;
   _bbcenter = _veh modelToWorld (boundingCenter _veh);
   _exitPos = _veh modelToWorld [_posX, _posY, _bbcenter select 2];
   _dir = [_bbcenter, _exitPos] call BM_fn_dirTo;
   player setposASL _exitPos;
   player setDir _dir;
   player setVelocity (velocity _veh);
};

["BM_fn_JumpOutRemAct", {
   _veh = _this;
   _acts = player getVariable ["BM_JOact", []];
   {_veh removeAction _x} forEach _acts;
   player setVariable ["BM_JOact", []];
}] call BM_addEventHandler;

BM_fn_JumpVehRegAct = {   
   _veh = vehicle player;
   if (vehicle player == player) exitWith {}; 
   _left = _veh addAction [("<t color=""#1EFF00"">" + ("Jump Out Left") + "</t>"), "Custom\BM_addAction.sqf", [0, BM_fn_JumpOut], 10, false, true];
   _right = _veh addAction [("<t color=""#FF0000"">" + ("Jump Out Right") + "</t>"), "Custom\BM_addAction.sqf", [1, BM_fn_JumpOut], 10, false, true];
   player setVariable ["BM_JOact", [_left, _right]];
   _veh call BM_fn_JOeh;
};

BM_fn_JOVehicleType = {
   _veh = vehicle player;
   if (_veh == player) exitWith {};
   if (_veh isKindOf "Plane" || _veh isKindOf "ParachuteBase" || _veh isKindOf "Man" || _veh isKindOf "StaticWeapon" || _veh isKindOf "Static" || _veh isKindOf "CH47_base_EP1") exitWith {};
   if (_veh isKindOf "MH6J_EP1") exitWith {[] call BM_fn_JOLbDisAct;};
   if (_veh isKindOf "Helicopter") exitWith {[] call BM_fn_JOBHAct;};
   [] call BM_fn_JumpVehRegAct;
};

BM_fn_JOLbDisAct = {
   _veh = vehicle player;
   if (!(_veh isKindOf "MH6J_EP1")) exitWith {};
   if (player == driver _veh) exitWith {};
   _act = _veh addAction [("<t color=""#001AFF"">" + ("Jump Out") + "</t>"), "Custom\BM_addAction.sqf", BM_fn_JumpOutLb, 10, false, true];
   _left = _veh addAction [("<t color=""#1EFF00"">" + ("Move Skid Left") + "</t>"), "Custom\BM_addAction.sqf", [0, BM_fn_NewSkid], 9, false, true];
   _right = _veh addAction [("<t color=""#FF0000"">" + ("Move Skid Right") + "</t>"), "Custom\BM_addAction.sqf", [1, BM_fn_NewSkid], 9, false, true];
   player setVariable ["BM_JOact", [_act, _left, _right]];
   _veh call BM_fn_JOeh;
};

BM_fn_JumpOutLb = {
   _veh = vehicle player;
   _pos = positionCameraToWorld [0,0,0];          
   _exitPos = positionCameraToWorld [0,0,1.5];
   _bboxcenter = _veh worldToModel (boundingCenter _veh);
   _dir = [_pos, _exitPos] call BM_fn_dirTo;
   player setPosATL _exitPos;
   player setDir _dir;
   player setVelocity (velocity _veh);
};

BM_fn_JumpOutBH = {
   _veh = vehicle player;
   _side = _this select 3;
   _exitPos = _veh selectionPosition "pos cargo";
   _exitPos set [0, _side * (_exitPos select 0)];
   _bbcenter = _veh modeltoworld (boundingCenter _veh);
   _exitPos = _veh modeltoworld _exitPos;
   _dir = [_bbcenter, _exitPos] call BM_fn_dirTo;   
   if ((assignedVehicleRole player) select 0 != "CARGO") then {
      MoveOut player;
   };
   player SetPosATL _exitPos;
   player setDir _dir;
   player setVelocity (velocity _veh);
};

BM_fn_JOBHAct = {
   _veh = vehicle player;
   if (!(_veh isKindOf "Helicopter")) exitWith {};
   if ((assignedVehicleRole player) select 0 != "CARGO") exitWith {};
   //if (player == driver _veh) exitWith {};
   _left = _veh addAction [("<t color=""#1EFF00"">" + ("Jump Out Left") + "</t>"), "Custom\BM_addAction.sqf", [1, BM_fn_JumpOutBH], 10, false, true];
   _right = _veh addAction [("<t color=""#FF0000"">" + ("Jump Out Right") + "</t>"), "Custom\BM_addAction.sqf", [-1, BM_fn_JumpOutBH], 10, false, true];
   player setVariable ["BM_JOact", [_left, _right]];
   _veh call BM_fn_JOeh;
};

BM_fn_JOeh = {
   _veh = _this;
   _eh = _veh getVariable "BM_goEH";
   if (isNil "_eh") then {
      _veh setVariable ["BM_goEH", true, true];
      _veh addEventHandler ["GetOut", {
         _unit = _this select 2;
         if (_unit != player) exitWith {};
         _veh = _this select 0;
         [_unit, "BM_fn_JumpOutRemAct", _veh] call BM_localRemoteEvent;
      }];
   };
};

BM_fn_NewSkid = {
   private ["_targetPos"];
   _veh = vehicle player;
   _side = _this select 3;
   _relPos = _veh worldToModel (getposATL player);
   _posX = _relPos select 0;
   _posY = _relPos select 1;
   _isSkid = false;
   _isRear = false;
   _isLeft = false;
   if (_posX < -0.6 || _posX > 0.6) then {
      _isSkid = true;
      if (_posY < 0.7) then {
         _isRear = true;
      };
      if (_posX < 0.6) then {
         _isLeft = true;
      };
   };
   if (!(_isSkid)) then {
      if (_side == 1) then {
         _targetPos = 1;
      };
   } else {
      if (_isLeft) then {
         if (_isRear) then {
            if (_side == 1) then {
               _targetPos = 3;
            };
         } else {
            if ( _side == 0) then {
               _targetPos = 2;
            };
         };
      } else {
         if (!(_isRear)) then {
            if (_side == 1) then {
               _targetPos = 4;
            } else {
               _targetPos = 0;
            };
         } else {
            if   (_side == 0) then {
               _targetPos = 1;
            };      
         };
      };
   };
   if (!(isnil "_targetPos")) then {
      _targetPos spawn BM_fn_MoveSkid;
   };
};

BM_fn_MoveSkid = {
   _veh = vehicle player;
   _targetPos = _this;
   MoveOut player;
   player moveincargo [_veh, _targetPos];
   sleep 1;
   _acts = player getVariable "BM_JOact";
   if (count _acts == 0) then {
      call BM_fn_JOVehicleType;
   };
};

BM_fn_JumpOutMainLoop = {
   while {alive player} do {
      waitUntil {sleep 0.5; vehicle player != player};
      [] call BM_fn_JOVehicleType;
      waitUntil {sleep 0.5; vehicle player == player};
   };
};
   
[] spawn BM_fn_JumpOutMainLoop;   
Last edited by Black Mamba on Thu May 16, 2013 1:46 pm, edited 1 time in total.

Wilson
Posts: 77
Joined: Sat Sep 29, 2012 10:25 am

Re: Script: Getting out of vehicles - enhancement

Post by Wilson »

Great Script!

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: Script: Getting out of vehicles - enhancement

Post by wolfenswan »

This script appears to have some problems when people attempt to leave a vehicle at the same time, causing them to be temporarily stuck in the vehicle.

Draith
Posts: 7
Joined: Sat Jan 05, 2013 8:00 pm

Re: Script: Getting out of vehicles - enhancement

Post by Draith »



A short clip showing a bug I experienced this evening.

Black Mamba
Posts: 335
Joined: Sun May 27, 2012 12:11 pm

Re: Script: Getting out of vehicles - enhancement

Post by Black Mamba »

Holy... Wow. Err, okay.

So, just ,to clarify, we're talking about two different bugs here, right?

Wolf, I thought I had fixed this, I'll have another look. You're talking about a land vehicle, not a chopper?

Draith, that is, I guess, FUBAR, is the word. Never seen this, no idea what can cause that. I'll have a look around, but it looks like a good old Arma network bug.

Thanks for reporting, guys!

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: Script: Getting out of vehicles - enhancement

Post by wolfenswan »

Wolf, I thought I had fixed this, I'll have another look. You're talking about a land vehicle, not a chopper?
It might be the same bug. I was in the black hawk.

User avatar
head
Posts: 133
Joined: Sun Jul 31, 2011 4:22 pm
Location: Sweeeden

Re: Script: Getting out of vehicles - enhancement

Post by head »

Black Mamba wrote:Holy... Wow. Err, okay.

So, just ,to clarify, we're talking about two different bugs here, right?

Wolf, I thought I had fixed this, I'll have another look. You're talking about a land vehicle, not a chopper?

Draith, that is, I guess, FUBAR, is the word. Never seen this, no idea what can cause that. I'll have a look around, but it looks like a good old Arma network bug.

Thanks for reporting, guys!
Had that.

Black Mamba
Posts: 335
Joined: Sun May 27, 2012 12:11 pm

Re: Script: Getting out of vehicles - enhancement

Post by Black Mamba »

Finally found the bug here (I think). I'll try to correct that.

Edit: the bug with the actions not disappearing and stacking up in the menu should be corrected. I think. I'll need some more stress-testing. I suspect the "get back in there" issue might be related to a network issue where the player's position (set client side) is overrided by the server, due to ping. I previously had that kind of stuff happening during the mission initialization, when the server messes up with teleport scripts, but never after the beginning of the mission. I'll keep digging.

Post Reply