Guest User

MF-Tow/init.sqf

a guest
Sep 24th, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. /**
  2. * mf-tow/init.sqf
  3. * The main script for initalising towing functionality.
  4. *
  5. * Created by Matt Fairbrass (matt_d_rat)
  6. * Version: 1.1.2
  7. * MIT Licence
  8. **/
  9.  
  10. private ["_cursorTarget", "_towableVehicles", "_towableVehiclesTotal"];
  11.  
  12. // Public variables
  13. MF_Tow_Base_Path = "addons\mf-tow"; // The base path to the MF-Tow Folder.
  14. MF_Tow_Distance = 10; // Minimum distance (in meters) away from vehicle the tow truck must be to tow.
  15. MF_Tow_Multi_Towing = false; // Allow a vehicle which is towing another vehicle already to be towed by another tow. Disabled by default.
  16.  
  17. // Functions
  18.  
  19. /**
  20. * Returns an array of towable objects which can be pulled by the tow truck.
  21. * Configure this as required to set which vehicles can pull which types of other vehicles.
  22. **/
  23. MF_Tow_Towable_Array =
  24. {
  25. private ["_array","_towTruck"];
  26. _towTruck = _this select 0;
  27. _array = [];
  28.  
  29. switch (typeOf _towTruck) do
  30. {
  31. case "ATV_CZ_EP1": {_array = ["Motorcycle"];};
  32. case "ATV_US_EP1": {_array = ["Motorcycle"];};
  33. case "hilux1_civil_3_open": {_array = ["Motorcycle","Car"];};
  34. case "hilux1_civil_3_open_EP1": {_array = ["Motorcycle","Car"];};
  35. case "ArmoredSUV_PMC": {_array = ["Motorcycle","Car"];};
  36. case "ArmoredSUV_PMC_DZ": {_array = ["Motorcycle","Car"];};
  37. case "ArmoredSUV_PMC_DZE": {_array = ["Motorcycle","Car"];};
  38. case "UAZ_Unarmed_TK_CIV_EP1": {_array = ["Motorcycle","Car"];};
  39. case "HMMWV_M1151_M2_CZ_DES_EP1_DZE": {_array = ["Motorcycle","Car","Truck"];};
  40. case "HMMWV_M1151_M2_CZ_DES_EP1": {_array = ["Motorcycle","Car","Truck"];};
  41. case "tractor": {_array = ["Motorcycle","Car","Truck"];};
  42. case "TowingTractor": {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
  43. };
  44.  
  45. _array
  46. };
  47.  
  48. /**
  49. * Animate the player in a towing action, whilst attaching them to the tow vehicle to ensure safety.
  50. **/
  51. MF_Tow_Animate_Player_Tow_Action =
  52. {
  53. private ["_towTruck","_offsetZ"];
  54. _towTruck = _this select 0;
  55. _offsetZ = 0.1;
  56.  
  57. // Bounding box on UAZ is screwed, offset z-axis correctly
  58. if(_towTruck isKindOf "UAZ_Base") then {
  59. _offsetZ = 1.8;
  60. };
  61.  
  62. [player,20,true,(getPosATL player)] spawn player_alertZombies; // Alert nearby zombies
  63. [1,1] call dayz_HungerThirst; // Use some hunger and thirst to perform the action
  64.  
  65. // Attach the player to the tow truck temporarily for safety so that they aren't accidentally hit by the vehicle when it gets attached
  66. player attachTo [_towTruck,
  67. [
  68. (boundingBox _towTruck select 1 select 0),
  69. (boundingBox _towTruck select 0 select 1) + 1,
  70. (boundingBox _towTruck select 0 select 2) - (boundingBox player select 0 select 2) + _offsetZ
  71. ]
  72. ];
  73.  
  74. player setDir 270;
  75. player setPos (getPos player);
  76. player playActionNow "Medic"; // Force the animation
  77. };
  78.  
  79. MF_Tow_Get_Vehicle_Name =
  80. {
  81. private ["_vehicle", "_configVeh", "_vehicleName"];
  82. _vehicle = _this select 0;
  83.  
  84. _configVeh = configFile >> "cfgVehicles" >> TypeOf(_vehicle);
  85. _vehicleName = getText(_configVeh >> "displayName");
  86.  
  87. _vehicleName
  88. };
  89.  
  90. // Initialise script
  91. _cursorTarget = cursorTarget;
  92. _towableVehicles = [_cursorTarget] call MF_Tow_Towable_Array;
  93. _towableVehiclesTotal = count (_towableVehicles);
  94.  
  95. // Add the action to the players scroll wheel menu if the cursor target is a vehicle which can tow.
  96. if(_towableVehiclesTotal > 0) then {
  97. if (s_player_towing < 0) then {
  98. if(!(_cursorTarget getVariable ["MFTowIsTowing", false])) then {
  99. s_player_towing = player addAction ["Attach Tow", format["%1\tow_AttachTow.sqf", MF_Tow_Base_Path], _cursorTarget, 0, false, true, "",""];
  100. } else {
  101. s_player_towing = player addAction ["Detach Tow", format["%1\tow_DetachTow.sqf", MF_Tow_Base_Path], _cursorTarget, 0, false, true, "",""];
  102. };
  103. };
  104. }
  105. else {
  106. player removeAction s_player_towing;
  107. s_player_towing = -1;
  108. };
Advertisement
Add Comment
Please, Sign In to add comment