Advertisement
Guest User

ats

a guest
Mar 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 5.07 KB | None | 0 0
  1. span class="re5"> ATRAIN_Player_Actions = missionNamespace getVariable ["ATRAIN_Player_Actions",[]];
  2. // start a player's eyes
  3. private _searchStartPointASL = eyePos player;
  4. // end 2 meters in front of where player is looking
  5. private _searchEndPointASL = _searchStartPointASL vectorAdd ((_searchStartPointASL vectorFromTo (ATLtoASL screenToWorld [0.5,0.5])) vectorMultiply 2);
  6. private _objects = lineIntersectsWith [_searchStartPointASL,_searchEndPointASL];
  7. private _trainFound = objNull;
  8. {
  9.     if(count ([_x] call ATRAIN_fnc_getTrainDefinition) > 0) exitWith {
  10.         _trainFound = _x;
  11.     };
  12. } forEach _objects;
  13.  
  14. if(!isNull _trainFound && count ATRAIN_Player_Actions == 0) then {
  15.     _trainFound = _trainFound getVariable ["ATRAIN_Remote_Copy",_trainFound];
  16.     private _trainDef = [_trainFound] call ATRAIN_fnc_getTrainDefinition;
  17.     _trainDef params ["_className", "_isDrivable", "_isRideable"];
  18.    
  19.     // Add actions
  20.     if(_isDrivable) then {
  21.         private _mainEngine = _trainFound getVariable ["ATRIAN_Current_Train", _trainFound];
  22.         private _currentDriver = _mainEngine getVariable ["ATRAIN_Remote_Driver", objNull];
  23.         private _isKilled = _trainFound getVariable ["ATRAIN_Remote_Killed", false];
  24.         if((isNull _currentDriver || !alive _currentDriver || _currentDriver == player) && !_isKilled) then {      
  25.             private _driveAction = player addAction ["Get in Train as Driver", {
  26.                 (_this select 3) params ["_mainEngine","_trainCar"];
  27.                 private _currentDriver = _mainEngine getVariable ["ATRAIN_Remote_Driver", objNull];
  28.                 if(isNull _currentDriver || !alive _currentDriver || _currentDriver == player) then {  
  29.                     [_mainEngine,_trainCar] call ATRAIN_fnc_getInTrain;
  30.                 };
  31.             },[_mainEngine,_trainFound]];
  32.             ATRAIN_Player_Actions pushBack _driveAction;
  33.         };
  34.     };
  35. ////////////////////////////////////////////
  36.     private _currentTrain = _trainFound getVariable ["ATRIAN_Current_Train", objNull];
  37.     if(!isNull _currentTrain && (_currentTrain getVariable ["ATRAIN_Local_Velocity",0]) == 0 && _currentTrain != _trainFound) then {
  38.         private _unloadAction = player addAction ["Unloadd", {},_trainFound];
  39.         ATRAIN_Player_Actions pushBack _unloadAction;
  40.    
  41.     };
  42. ////////////////////////////////////////////////       
  43.     private _currentTrain = _trainFound getVariable ["ATRIAN_Current_Train", objNull];
  44.     if(!isNull _currentTrain && (_currentTrain getVariable ["ATRAIN_Local_Velocity",0]) == 0 && _currentTrain != _trainFound) then {
  45.         private _disconnectAction = player addAction ["Disconnect Car", {
  46.        
  47.             private _trainCar = _this select 3;
  48.             private _localTrainCar = _trainCar getVariable ["ATRAIN_Local_Copy", _trainCar];
  49.             private _currentTrain = _trainCar getVariable ["ATRIAN_Current_Train", objNull];
  50.            
  51.             private _carsInRear = _currentTrain getVariable ["ATRAIN_Remote_Cars_In_Rear",[]];
  52.             private _carsInFront = _currentTrain getVariable ["ATRAIN_Remote_Cars_In_Front",[]];
  53.             private _allCars = _currentTrain getVariable ["ATRAIN_Remote_Cars",[]];
  54.            
  55.             private _rearCarSeen = false;
  56.             private _newCarsInRear = [];
  57.             {
  58.                 if(_x == _trainCar && !_rearCarSeen) then {
  59.                     _rearCarSeen = true;
  60.                 };
  61.                 if(_rearCarSeen) then {
  62.                     _x setVariable ["ATRIAN_Current_Train",nil,true];
  63.                     _x setVariable ["ATRIAN_Remote_Is_Backwards", nil, true];
  64.                     _x setPosASL (getPosASLVisual _localTrainCar);
  65.                     _x setVectorDirAndUp [vectorDir _localTrainCar, vectorUp _localTrainCar];
  66.                     _allCars = _allCars - [_x];
  67.                 } else {
  68.                     _newCarsInRear pushBack _x;
  69.                 };
  70.             } forEach _carsInRear;
  71.             _currentTrain setVariable ["ATRAIN_Remote_Cars_In_Rear",_newCarsInRear,true];
  72.            
  73.            
  74.            
  75.             private _frontCarSeen = false;
  76.             private _newCarsInFront = [];
  77.             {
  78.                 if(_x == _trainCar && !_frontCarSeen) then {
  79.                     _frontCarSeen = true;
  80.                 };     
  81.                 if(_frontCarSeen) then {
  82.                     _x setVariable ["ATRIAN_Current_Train",nil,true];
  83.                     _x setVariable ["ATRIAN_Remote_Is_Backwards", nil, true];
  84.                     _x setPosASL (getPosASLVisual _localTrainCar);
  85.                     _x setVectorDirAndUp [vectorDir _localTrainCar, vectorUp _localTrainCar];
  86.                     _allCars = _allCars - [_x];
  87.                 } else {
  88.                     _newCarsInFront pushBack _x;
  89.                 };
  90.             } forEach _carsInFront;
  91.             _currentTrain setVariable ["ATRAIN_Remote_Cars_In_Front",_newCarsInFront,true];
  92.  
  93.             _currentTrain setVariable ["ATRAIN_Remote_Cars",_allCars,true];
  94.  
  95.         },_trainFound];
  96.         ATRAIN_Player_Actions pushBack _disconnectAction;
  97.    
  98.     };
  99.    
  100.    
  101.    
  102.     if(_isRideable) then {
  103.         private _currentTrain = _trainFound getVariable ["ATRIAN_Current_Train", objNull];
  104.         private _currentDriver = _currentTrain getVariable ["ATRAIN_Remote_Driver", objNull];
  105.         private _isKilled = _trainFound getVariable ["ATRAIN_Remote_Killed", false];
  106.         if(!isNull _currentTrain && _currentTrain != _trainFound && _currentDriver != player && !_isKilled) then {
  107.             private _rideAction = player addAction ["Ride Train", {
  108.                 [_this select 3] call ATRAIN_fnc_getInTrainPassenger;
  109.             },_trainFound];
  110.             ATRAIN_Player_Actions pushBack _rideAction;
  111.         };
  112.     };
  113. };
  114.  
  115. if(isNull _trainFound && count ATRAIN_Player_Actions > 0) then {
  116.     {
  117.         player removeAction _x;
  118.     } forEach ATRAIN_Player_Actions;
  119.     ATRAIN_Player_Actions = [];
  120. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement