Advertisement
aeroson

Arma 3 - unflip_vehicle.sqf

Jan 29th, 2015
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. /*
  2. AUTHOR: aeroson
  3. NAME: unflip_vehicle.sqf
  4. VERSION: 1
  5.  
  6. DESCRIPTION:
  7. If vehicle's angle to ground is over 45 and vehicle has no alive crew,
  8. shows Unflip vehicle action in player's action menu
  9.  
  10. USAGE:
  11. paste this into init.sqf
  12. 0 = [] execVM 'unflip_vehicle.sqf';
  13.  
  14. */
  15.  
  16. if(!hasInterface) exitWith { }; // exit if we are not a player
  17.  
  18.  
  19. aero_unflip_unflipVehicle = {
  20.  
  21. _veh = _this;
  22.  
  23. if(owner _veh != owner player) exitWith { // if we dont own it, remote execute this on the owner machine
  24. [_veh, "aero_unflip_unflipVehicle", _veh] call BIS_fnc_mp;
  25. };
  26.  
  27. _veh allowDamage false; // prevent damage from collision
  28.  
  29. _newPos = getPos _veh;
  30. _veh setVectorUp (surfaceNormal _newPos);
  31. _newPos set[2, 0];
  32. _veh setPos _newPos;
  33.  
  34. sleep 2; // wait a bit for physics to kick in
  35.  
  36. _veh setVelocity [0,0,0]; // stop vehicle, so it doesnt fly away due to collision
  37. _veh allowDamage true;
  38.  
  39. };
  40.  
  41.  
  42. // unit addAction [title, script, arguments, priority, showWindow, hideOnUse, shortcut, condition, positionInModel, radius, radiusView, showIn3D, available, textDefault, textToolTip]
  43. aero_unflip_canShow = {
  44.  
  45. _t = player;
  46. _radius = 2;
  47. _pos = (getPos _t) vectorAdd ((eyeDirection _t) vectorMultiply _radius); // look for pos that is infront of us and towards the direction we look
  48. _objs = nearestObjects[_pos, ["Car","Tank"], _radius*2]; // so find vehicles in sphere of _radius in front of you
  49.  
  50. aero_unflip_targetVehicle = {
  51. if(
  52. // true || // uncomment for debug
  53. ({alive _x} count crew _x == 0) && // if vehicle has no alive crew
  54. ((vectorUp _x) vectorDotProduct (surfaceNormal (getpos _x)) < 0.5) // if vehicle angle to surface is over 45 degrees
  55. ) exitWith { _x };
  56. } forEach _objs;
  57.  
  58. !isNil{aero_unflip_targetVehicle}
  59.  
  60. };
  61.  
  62.  
  63. aero_unflip_addAction = {
  64.  
  65. if(!isNil{aero_unflip_handle_addAction}) then {
  66. (aero_unflip_handle_addAction select 0) removeAction (aero_unflip_handle_addAction select 1);
  67. };
  68.  
  69. aero_unflip_handle_addAction = [
  70. player,
  71. player addAction [
  72. "<t color='#FF0000'>Unflip vehicle</t>",
  73. {
  74. aero_unflip_targetVehicle call aero_unflip_unflipVehicle;
  75. },
  76. [],
  77. 1000,
  78. false,
  79. true,
  80. "",
  81. "[] call aero_unflip_canShow"
  82. ]
  83. ];
  84.  
  85. };
  86.  
  87.  
  88. [] call aero_unflip_addAction;
  89. player addEventHandler ["respawn", { [] call aero_unflip_addAction; }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement