Advertisement
Guest User

Untitled

a guest
Nov 25th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. // Vehicle Service Point by Axe Cop
  2.  
  3. private ["_folder","_servicePointClasses","_maxDistance","_actionTitleFormat","_actionCostsFormat","_costsFree","_message","_messageShown","_refuel_enable","_refuel_costs","_refuel_updateInterval","_refuel_amount","_repair_enable","_repair_costs","_repair_repairTime","_rearm_enable","_rearm_costs","_rearm_magazineCount","_lastVehicle","_lastRole","_refuel_action","_repair_action","_rearm_actions","_fnc_removeActions","_fnc_getCosts","_fnc_actionTitle","_fnc_isArmed","_fnc_getWeapons"];
  4.  
  5. // ---------------- CONFIG START ----------------
  6.  
  7. // general settings
  8. _folder = "service_point\"; // folder where the service point scripts are saved, relative to the mission file
  9. _servicePointClasses = ["Land_A_FuelStation_Feed"]; // service point classes (add "FuelPump_DZ" to use the dynamic Epoch fuel pumps)
  10. _maxDistance = 10; // maximum distance from a service point for the options to be shown
  11. _actionTitleFormat = "%1 (%2)"; // text of the vehicle menu, %1 = action name (Refuel, Repair, Rearm), %2 = costs (see format below)
  12. _actionCostsFormat = "%2 %1"; // %1 = item name, %2 = item count
  13. _costsFree = "free"; // text for no costs
  14. _message = "Vehicle Service Point nearby"; // message to be shown when in range of a service point (set to "" to disable)
  15.  
  16. // refuel settings
  17. _refuel_enable = true; // enable or disable the refuel option
  18. _refuel_costs = ["ItemGoldBar10oz",1]; // free for all vehicles (equal to [["AllVehicles",[]]])
  19. _refuel_updateInterval = 0.5; // update interval (in seconds)
  20. _refuel_amount = 0.02; // amount of fuel to add with every update (in percent)
  21.  
  22. // repair settings
  23. _repair_enable = true; // enable or disable the repair option
  24. _repair_costs = [
  25. ["Air",["ItemBriefcase100oz",1]], // 5 Gold for helicopters and planes
  26. ["AllVehicles",["ItemGoldBar10oz",5]] // 2 Gold for all other vehicles
  27. ];
  28. _repair_repairTime = 2; // time needed to repair each damaged part (in seconds)
  29.  
  30. // rearm settings
  31. _rearm_enable = true; // enable or disable the rearm option
  32. _rearm_costs = [
  33. ["ArmoredSUV_PMC_DZE",["ItemBriefcase100oz",3]], // special costs for a single vehicle type
  34. ["Air",["ItemBriefcase100oz",3]], // 2 10oz Gold for helicopters and planes
  35. ["AllVehicles",["ItemBriefcase100oz",2]] // 1 10oz Gold for all other vehicles
  36. ];
  37. _rearm_magazineCount = 1; // amount of magazines to be added to the vehicle weapon
  38.  
  39. // ----------------- CONFIG END -----------------
  40.  
  41. call compile preprocessFileLineNumbers (_folder + "ac_functions.sqf");
  42.  
  43. _lastVehicle = objNull;
  44. _lastRole = [];
  45.  
  46. _refuel_action = -1;
  47. _repair_action = -1;
  48. _rearm_actions = [];
  49.  
  50. _messageShown = false;
  51.  
  52. _fnc_removeActions = {
  53. if (isNull _lastVehicle) exitWith {};
  54. _lastVehicle removeAction _refuel_action;
  55. _refuel_action = -1;
  56. _lastVehicle removeAction _repair_action;
  57. _repair_action = -1;
  58. {
  59. _lastVehicle removeAction _x;
  60. } forEach _rearm_actions;
  61. _rearm_actions = [];
  62. _lastVehicle = objNull;
  63. _lastRole = [];
  64. };
  65.  
  66. _fnc_getCosts = {
  67. private ["_vehicle","_costs","_cost"];
  68. _vehicle = _this select 0;
  69. _costs = _this select 1;
  70. _cost = [];
  71. {
  72. private "_typeName";
  73. _typeName = _x select 0;
  74. if (_vehicle isKindOf _typeName) exitWith {
  75. _cost = _x select 1;
  76. };
  77. } forEach _costs;
  78. _cost
  79. };
  80.  
  81. _fnc_actionTitle = {
  82. private ["_actionName","_costs","_costsText","_actionTitle"];
  83. _actionName = _this select 0;
  84. _costs = _this select 1;
  85. _costsText = _costsFree;
  86. if (count _costs == 2) then {
  87. private ["_itemName","_itemCount","_displayName"];
  88. _itemName = _costs select 0;
  89. _itemCount = _costs select 1;
  90. _displayName = getText (configFile >> "CfgMagazines" >> _itemName >> "displayName");
  91. _costsText = format [_actionCostsFormat, _displayName, _itemCount];
  92. };
  93. _actionTitle = format [_actionTitleFormat, _actionName, _costsText];
  94. _actionTitle
  95. };
  96.  
  97. _fnc_isArmed = {
  98. private ["_role","_armed"];
  99. _role = _this;
  100. _armed = count _role > 1;
  101. _armed
  102. };
  103.  
  104. _fnc_getWeapons = {
  105. private ["_vehicle","_role","_weapons"];
  106. _vehicle = _this select 0;
  107. _role = _this select 1;
  108. _weapons = [];
  109. if (count _role > 1) then {
  110. private ["_turret","_weaponsTurret"];
  111. _turret = _role select 1;
  112. _weaponsTurret = _vehicle weaponsTurret _turret;
  113. {
  114. private "_weaponName";
  115. _weaponName = getText (configFile >> "CfgWeapons" >> _x >> "displayName");
  116. _weapons set [count _weapons, [_x, _weaponName, _turret]];
  117. } forEach _weaponsTurret;
  118. };
  119. _weapons
  120. };
  121.  
  122. while {true} do {
  123. private ["_vehicle","_inVehicle"];
  124. _vehicle = vehicle player;
  125. _inVehicle = _vehicle != player;
  126. if (local _vehicle && _inVehicle) then {
  127. private ["_pos","_objects","_inRange"];
  128. _pos = position _vehicle;
  129. _objects = nearestObjects [_pos, _servicePointClasses, _maxDistance];
  130. _inRange = count _objects > 0;
  131. if (_inRange) then {
  132. private ["_role","_actionCondition","_costs","_actionTitle"];
  133. _role = assignedVehicleRole player;
  134. if (((str _role) != (str _lastRole)) || (_vehicle != _lastVehicle)) then {
  135. // vehicle or seat changed
  136. call _fnc_removeActions;
  137. };
  138. _lastVehicle = _vehicle;
  139. _lastRole = _role;
  140. _actionCondition = "vehicle _this == _target && local _target";
  141. if (_refuel_action < 0 && _refuel_enable) then {
  142. _costs = [_vehicle, _refuel_costs] call _fnc_getCosts;
  143. _actionTitle = ["Refuel", _costs] call _fnc_actionTitle;
  144. _refuel_action = _vehicle addAction [_actionTitle, _folder + "service_point_refuel.sqf", [_costs, _refuel_updateInterval, _refuel_amount], -1, false, true, "", _actionCondition];
  145. };
  146. if (_repair_action < 0 && _repair_enable) then {
  147. _costs = [_vehicle, _repair_costs] call _fnc_getCosts;
  148. _actionTitle = ["Repair", _costs] call _fnc_actionTitle;
  149. _repair_action = _vehicle addAction [_actionTitle, _folder + "service_point_repair.sqf", [_costs, _repair_repairTime], -1, false, true, "", _actionCondition];
  150. };
  151. if ((_role call _fnc_isArmed) && (count _rearm_actions == 0) && _rearm_enable) then {
  152. private ["_weapons"];
  153. _costs = [_vehicle, _rearm_costs] call _fnc_getCosts;
  154. _weapons = [_vehicle, _role] call _fnc_getWeapons;
  155. {
  156. private ["_weaponName","_rearm_action"];
  157. _weaponName = _x select 1;
  158. _actionTitle = [format["Rearm %1", _weaponName], _costs] call _fnc_actionTitle;
  159. _rearm_action = _vehicle addAction [_actionTitle, _folder + "service_point_rearm.sqf", [_costs, _rearm_magazineCount, _x], -1, false, true, "", _actionCondition];
  160. _rearm_actions set [count _rearm_actions, _rearm_action];
  161. } forEach _weapons;
  162. };
  163. if (!_messageShown && _message != "") then {
  164. _messageShown = true;
  165. _vehicle vehicleChat _message;
  166. };
  167. } else {
  168. call _fnc_removeActions;
  169. _messageShown = false;
  170. };
  171. } else {
  172. call _fnc_removeActions;
  173. _messageShown = false;
  174. };
  175. sleep 2;
  176. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement