Advertisement
Guest User

Split Service Points DZE

a guest
Mar 14th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.90 KB | None | 0 0
  1. // Vehicle Service Point by Axe Cop
  2.  
  3. private ["_folder","_servicePointClassesRF","_servicePointClassesRA","_servicePointClassesRP","_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","_fnc_removeActions","_fnc_getCosts","_fnc_actionTitle","_fnc_isArmed","_fnc_getWeapons"];
  4.  
  5. // ---------------- CONFIG START ----------------
  6.  
  7. // general settings
  8. _folder = "addons\scripts\service_point\"; // folder where the service point scripts are saved, relative to the mission file
  9. _servicePointClassesRF = ["dayz_fuelpumparray","DZE_fueltruckarray"]; // service point refuel classes (can be house, vehicle and unit classes)
  10. _servicePointClassesRA = ["dayz_repairstationarray","DZE_repairtruckarray"]; // service point repair classes (can be house, vehicle and unit classes)
  11. _servicePointClassesRP = ["dayz_rearmstationarray","DZE_rearmtruckarray"]; // service point Rearm classes (can be house, vehicle and unit classes)
  12. _maxDistance = 15; // maximum distance from a service point for the options to be shown
  13. _actionTitleFormat = "%1 (%2)"; // text of the vehicle menu, %1 = action name (Refuel, Repair, Rearm), %2 = costs (see format below)
  14. _actionCostsFormat = "%2 %1"; // %1 = item name, %2 = item count
  15. _costsFree = "free"; // text for no costs
  16. _message = "Vehicle Service Point nearby"; // message to be shown when in range of a service point (set to "" to disable)
  17.  
  18. // refuel settings
  19. _refuel_enable = true; // enable or disable the refuel option
  20. _refuel_costs = [
  21. ["AllVehicles",["ItemGoldBar10oz",1]]
  22. ]; // free for all vehicles (equal to [["AllVehicles",[]]])
  23. _refuel_updateInterval = 1; // update interval (in seconds)
  24. _refuel_amount = 0.05; // amount of fuel to add with every update (in percent)
  25.  
  26. // repair settings
  27. _repair_enable = true; // enable or disable the repair option
  28. _repair_costs = [
  29. ["Air",["ItemGoldBar",5]], // 5 Gold for helicopters and planes
  30. ["AllVehicles",["ItemGoldBar",2]] // 2 Gold for all other vehicles
  31. ];
  32. _repair_repairTime = 5; // time needed to repair each damaged part (in seconds)
  33.  
  34. // rearm settings
  35. _rearm_enable = true; // enable or disable the rearm option
  36. _rearm_costs = [
  37. ["ArmoredSUV_PMC_DZE",["ItemGoldBar10oz",2]], // special costs for a single vehicle type
  38. ["Air",["ItemGoldBar10oz",2]], // 2 10oz Gold for helicopters and planes
  39. ["AllVehicles",["ItemGoldBar10oz",1]] // 1 10oz Gold for all other vehicles
  40. ];
  41. _rearm_magazineCount = 3; // amount of magazines to be added to the vehicle weapon
  42.  
  43. // ----------------- CONFIG END -----------------
  44.  
  45. _lastVehicle = objNull;
  46. _lastRole = [];
  47.  
  48. SP_refuel_action = -1;
  49. SP_repair_action = -1;
  50. SP_rearm_actions = [];
  51.  
  52. _messageShown = false;
  53.  
  54. _fnc_removeActions = {
  55. if (isNull _lastVehicle) exitWith {};
  56. _lastVehicle removeAction SP_refuel_action;
  57. SP_refuel_action = -1;
  58. _lastVehicle removeAction SP_repair_action;
  59. SP_repair_action = -1;
  60. {
  61. _lastVehicle removeAction _x;
  62. } forEach SP_rearm_actions;
  63. SP_rearm_actions = [];
  64. _lastVehicle = objNull;
  65. _lastRole = [];
  66. };
  67.  
  68. _fnc_getCosts = {
  69. private ["_vehicle","_costs","_cost"];
  70. _vehicle = _this select 0;
  71. _costs = _this select 1;
  72. _cost = [];
  73. {
  74. private "_typeName";
  75. _typeName = _x select 0;
  76. if (_vehicle isKindOf _typeName) exitWith {
  77. _cost = _x select 1;
  78. };
  79. } forEach _costs;
  80. _cost
  81. };
  82.  
  83. _fnc_actionTitle = {
  84. private ["_actionName","_costs","_costsText","_actionTitle"];
  85. _actionName = _this select 0;
  86. _costs = _this select 1;
  87. _costsText = _costsFree;
  88. if (count _costs == 2) then {
  89. private ["_itemName","_itemCount","_displayName"];
  90. _itemName = _costs select 0;
  91. _itemCount = _costs select 1;
  92. _displayName = getText (configFile >> "CfgMagazines" >> _itemName >> "displayName");
  93. _costsText = format [_actionCostsFormat, _displayName, _itemCount];
  94. };
  95. _actionTitle = format [_actionTitleFormat, _actionName, _costsText];
  96. _actionTitle
  97. };
  98.  
  99. _fnc_isArmed = {
  100. private ["_role","_armed"];
  101. _role = _this;
  102. _armed = count _role > 1;
  103. _armed
  104. };
  105.  
  106. _fnc_getWeapons = {
  107. private ["_vehicle","_role","_weapons"];
  108. _vehicle = _this select 0;
  109. _role = _this select 1;
  110. _weapons = [];
  111. if (count _role > 1) then {
  112. private ["_turret","_weaponsTurret"];
  113. _turret = _role select 1;
  114. _weaponsTurret = _vehicle weaponsTurret _turret;
  115. {
  116. private "_weaponName";
  117. _weaponName = getText (configFile >> "CfgWeapons" >> _x >> "displayName");
  118. _weapons set [count _weapons, [_x, _weaponName, _turret]];
  119. } forEach _weaponsTurret;
  120. };
  121. _weapons
  122. };
  123.  
  124. while {true} do {
  125. private ["_vehicle","_inVehicle"];
  126. _vehicle = vehicle player;
  127. _inVehicle = _vehicle != player;
  128. if (local _vehicle && _inVehicle) then {
  129. private ["_pos","_servicePoints","_inRange"];
  130. _pos = getPosATL _vehicle;
  131. _servicePointsRF = (nearestObjects [_pos, _servicePointClassesRF, _maxDistance]) - [_vehicle];
  132. _servicePointsRA = (nearestObjects [_pos, _servicePointClassesRA, _maxDistance]) - [_vehicle];
  133. _servicePointsRP = (nearestObjects [_pos, _servicePointClassesRP, _maxDistance]) - [_vehicle];
  134. _inRangeRF = count _servicePointsRF > 0;
  135. _inRangeRA = count _servicePointsRA > 0;
  136. _inRangeRP = count _servicePointsRP > 0;
  137. if (_inRangeRA) || (_inRangeRF) || (_inRangeRP) then {
  138. private ["_servicePointRF","_servicePointRA","_servicePointRP","_role","_actionCondition","_costs","_actionTitle"];
  139. _servicePointRF = _servicePointsRF select 0;
  140. _servicePointRA = _servicePointsRA select 0;
  141. _servicePointRP = _servicePointsRP select 0;
  142. _role = assignedVehicleRole player;
  143. if (((str _role) != (str _lastRole)) || (_vehicle != _lastVehicle)) then {
  144. // vehicle or seat changed
  145. call _fnc_removeActions;
  146. };
  147. _lastVehicle = _vehicle;
  148. _lastRole = _role;
  149. _actionCondition = "vehicle _this == _target && local _target";
  150. if (SP_refuel_action < 0 && _refuel_enable) then {
  151. _costs = [_vehicle, _refuel_costs] call _fnc_getCosts;
  152. _actionTitle = ["Refuel", _costs] call _fnc_actionTitle;
  153. SP_refuel_action = _vehicle addAction [_actionTitle, _folder + "service_point_refuel.sqf", [_servicePointRF, _costs, _refuel_updateInterval, _refuel_amount], -1, false, true, "", _actionCondition];
  154. };
  155. if (SP_repair_action < 0 && _repair_enable) then {
  156. _costs = [_vehicle, _repair_costs] call _fnc_getCosts;
  157. _actionTitle = ["Repair", _costs] call _fnc_actionTitle;
  158. SP_repair_action = _vehicle addAction [_actionTitle, _folder + "service_point_repair.sqf", [_servicePointRP, _costs, _repair_repairTime], -1, false, true, "", _actionCondition];
  159. };
  160. if (_role call _fnc_isArmed) && (count SP_rearm_actions == 0) && _rearm_enable) then {
  161. private ["_weapons"];
  162. _costs = [_vehicle, _rearm_costs] call _fnc_getCosts;
  163. _weapons = [_vehicle, _role] call _fnc_getWeapons;
  164. {
  165. private "_weaponName";
  166. _weaponName = _x select 1;
  167. _actionTitle = [format["Rearm %1", _weaponName], _costs] call _fnc_actionTitle;
  168. SP_rearm_action = _vehicle addAction [_actionTitle, _folder + "service_point_rearm.sqf", [_servicePointRA, _costs, _rearm_magazineCount, _x], -1, false, true, "", _actionCondition];
  169. SP_rearm_actions set [count SP_rearm_actions, SP_rearm_action];
  170. } forEach _weapons;
  171. };
  172. if (!_messageShown && _message != "") then {
  173. _messageShown = true;
  174. _vehicle vehicleChat _message;
  175. };
  176. } else {
  177. call _fnc_removeActions;
  178. _messageShown = false;
  179. };
  180. } else {
  181. call _fnc_removeActions;
  182. _messageShown = false;
  183. };
  184. sleep 2;
  185. };
  186.  
  187.  
  188.  
  189. These are the extra variables defined in a custom variables.sqf
  190.  
  191. // These work with just a running generator
  192. dayz_fuelpumparray = ["FuelPump_DZ","Land_A_FuelStation_Feed","Land_Ind_FuelStation_Feed_EP1","Land_FuelStation_Feed_PMC","FuelStation","Land_ibr_FuelStation_Feed","Land_fuelstation_army","Land_fuelstation","land_fuelstation_w","Land_benzina_schnell"];
  193. DZE_fueltruckarray = ["KamazRefuel_DZ","UralRefuel_TK_EP1_DZ","MtvrRefuel_DES_EP1_DZ","V3S_Refuel_TK_GUE_EP1_DZ","MtvrRefuel_DZ","KamazRefuel_DZE","UralRefuel_TK_EP1_DZE","MtvrRefuel_DES_EP1_DZE","V3S_Refuel_TK_GUE_EP1_DZE","MtvrRefuel_DZE"];
  194.  
  195. // repair classes
  196. dayz_repairstationarray = ["MAP_garaz_mala","Land_Vysilac_FM","Land_Ind_Workshop01_01","Land_Ind_Workshop01_02","Land_Ind_Workshop01_03","Land_Ind_Workshop01_04","Land_Ind_Workshop01_L","Land_Ind_Garage01","Land_Ind_Garage01_EP1","Land_MBG_Garage_Single_A","Land_MBG_Garage_Single_B","Land_MBG_Garage_Single_C","Land_MBG_Garage_Single_D","Land_Mil_Repair_center_EP1","Land_repair_center"];
  197. DZE_repairtruckarray = ["UralRepair_CDF","UralRepair_INS","V3S_Repair_TK_GUE_EP1","KamazRepair","MtvrRepair"];
  198.  
  199. //rearm classes
  200. dayz_rearmstationarray = ["Bunker_PMC","Land_Shed_M02"];
  201. DZE_rearmtruckarray = ["UralReammo_CDF","UralReammo_INS","KamazReammo","V3S_Reammo_TK_GUE_EP1"];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement