Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 3.53 KB | None | 0 0
  1.  
  2. addMissionEventHandler["EachFrame", {
  3.  
  4.   private _vehicle = vehicle player;
  5.   private _posAGLS = getPos _vehicle;
  6.   private _posATL = getPosATL _vehicle;
  7.   private _prevVelocity = _vehicle getVariable ["LIB_prevVelocity", [0,0,0]];
  8.   private _velocityVehicle = velocityModelSpace _vehicle;
  9.   private _3Dspeed = vectorMagnitude _velocityVehicle;
  10.   private _maxAccelerations = [1,3,1];
  11.   private _overG = false;
  12.   private _velocityDiff = _velocityVehicle vectorDiff _prevVelocity;
  13.  
  14.   _vehicle setVariable ["LIB_AntiFlipSystemDisabled", true];
  15.   _vehicle allowdamage true;
  16.   player allowdamage true;
  17.  
  18.   {
  19.     private _i = _forEachIndex;
  20.     if ((abs _x) > (_maxAccelerations select _i)) then {
  21.             _overG = true;
  22.         };
  23.   } forEach _velocityDiff;
  24.   private _time = _vehicle getVariable ["LIB_prevVelocity_timestamp", diag_tickTime];
  25.   if ((!_overG && {(floor (diag_tickTime * 10)% 2) isEqualTo 0}) || (diag_tickTime - _time > 0.25)) then {
  26.     _vehicle setVariable ["LIB_prevVelocity", _velocityVehicle];
  27.     _vehicle setVariable ["LIB_prevVelocity_timestamp", diag_tickTime];
  28.   };
  29.   if (_overG && _3DSpeed != 0) then {
  30.     private _corrected = _velocityVehicle vectorMultiply (2.5/_3Dspeed);
  31.     _vehicle setVelocityModelSpace _corrected;
  32.   };
  33.  
  34.  
  35. private _vectorUpVehicle = vectorUp _vehicle;
  36. private _prevVectorUp = _vehicle getVariable ["LIB_prevVectorUp", _vectorUpVehicle];
  37. private _maxUpDelta = [0.1,0.1,0.1];
  38. private _overVUP = false;
  39. private _VUPDiff = _vectorUpVehicle vectorDiff _prevVectorUp;
  40. private _correctionVUP = _prevVectorUp;
  41.  
  42.  
  43. {
  44.   private _i = _forEachIndex;
  45.   if ((abs _x) > (_maxUpDelta select _i)) then {
  46.     _correctionVUP set [_i,(_maxUpDelta select _i)];
  47.     _overVUP = true;
  48.     systemChat str [_x, _maxUpDelta select _i];
  49.   };
  50. } forEach _VUPDiff;
  51.  
  52. private _time = _vehicle getVariable ["LIB_prevVectorUp_timestamp", diag_tickTime];
  53. if (!_overVUP && {(diag_tickTime - _time) > 0.25} || {(floor (diag_tickTime * 10)% 2) isEqualTo 0}) then {
  54.   _vehicle setVariable ["LIB_prevVectorUp", vectorUp _vehicle];
  55.   _vehicle setVariable ["LIB_prevVectorUp_timestamp", diag_tickTime];
  56. };
  57. if (_overVUP) then {
  58.   private _correctedVUP = vectorNormalized (_prevVectorUp vectoradd ((surfaceNormal _posATL) vectorMultiply 0.01));
  59.   _vehicle setVectorUp _correctedVUP;
  60.   _vehicle setVariable ["LIB_prevVectorUp", vectorUp _vehicle];
  61. };
  62.  
  63.   private _heightVehicle = (abs ((_posAGLS select 2) - (_posATL select 2))) min (_posAGLS select 2);
  64.   private _flying = false;
  65.   private _flipping = false;
  66.   _vehicle allowdamage false;
  67.   player allowdamage false;
  68.   if (_heightVehicle > 3 && ((_velocityVehicle select 2) > 1)) then {
  69.      _vehicle setVelocityModelSpace (_velocityVehicle vectorDiff [0,0,(abs ((_velocityVehicle select 2)*0.05))]);
  70.      _flying = true;
  71.   } else {
  72.     if ((_velocityVehicle select 2) > 5) then {
  73.       _vehicle setVelocityModelSpace (_velocityVehicle vectorDiff [0,0,1]);
  74.       _flying = true;
  75.     } else {
  76.       if (((_vectorUpVehicle select 2) < 0.3) || ((abs ((_vehicle call BIS_fnc_getPitchBank) select 1)) > 75)) then {
  77.         _vehicle setVectorUp (_vectorUpVehicle vectorAdd [0,0,0.1]);
  78.         _vehicle setVariable ["LIB_prevVectorUp", vectorUp _vehicle];
  79.         _flipping = true;
  80.       };
  81.     };
  82.   };
  83.  
  84.  
  85.     if (_overG || _overVUP || _flying || _flipping) then {
  86.          hintSilent format ["Antiflip Script Activated:\nOverspeed: %1\nOverrotation: %2\n Flipping: %3\nFlying: %4", _overG, _overVUP, _flipping, _flying];
  87.     } else {
  88.     _vehicle allowdamage true;
  89.     player allowdamage true;
  90.   };
  91. }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement