Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.63 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","_fnc_removeActions","_fnc_getCosts","_fnc_actionTitle","_fnc_isArmed","_fnc_getWeapons","_fnc_getMagazines"];
  4.  
  5. // ---------------- CONFIG START ----------------
  6.  
  7. // -- Single Currency Prices -- //
  8. _coinsRepairAir = 5000;
  9. _coinsRepairVehicles = 2000;
  10.  
  11.  
  12.  
  13.  
  14.  
  15. //Rearm
  16. _coinsRearmAir = 20000;
  17. _coinsRearmVehicles = 10000;
  18.  
  19.  
  20. // -- End Single Currency Prices -- //
  21.  
  22. // general settings
  23. _folder = "Custom\service_point\"; // folder where the service point scripts are saved, relative to the mission file
  24. _servicePointClasses = dayz_fuelpumparray +["FuelPump_DZ", "Land_A_FuelStation_Feed", "Land_Fuel_tank_big", "Land_Ind_TankSmall", "Land_Ind_TankSmall2", "Land_Ind_TankSmall2_EP1", "Land_LHD_1", "Land_LHD_2", "Land_LHD_3", "Land_LHD_4", "Land_LHD_5", "Land_LHD_6", "Land_fuel_tank_stairs", "Land_fuelstation", "Land_fuelstation_army", "Land_ibr_FuelStation_Feed", "MAP_Ind_TankBig", "MAP_Ind_TankSmall", "MAP_Ind_TankSmall2", "MAP_nav_pier_M_fuel", "land_benzina_schnell", "land_nav_pier_M_fuel", "Land_A_FuelStation_Feed"];
  25. _maxDistance = 10; // maximum distance from a service point for the options to be shown
  26. _actionTitleFormat = "%1 (%2)"; // text of the vehicle menu, %1 = action name (Refuel, Repair, Rearm), %2 = costs (see format below)
  27. _actionCostsFormat = "%2 %1"; // %1 = item name, %2 = item count
  28. _costsFree = "free"; // text for no costs
  29. _message = "Vehicle Service Point nearby"; // message to be shown when in range of a service point (set to "" to disable)
  30.  
  31. // refuel settings
  32. _refuel_enable = true; // enable or disable the refuel option
  33. _refuel_costs = [
  34. ["AllVehicles",[CurrencyName,_coinsRefuelVehicles]],
  35.  
  36. ["Air",[CurrencyName,_coinsRefuelAir]]];
  37. _refuel_updateInterval = 1; // update interval (in seconds)
  38. _refuel_amount = 0.05; // amount of fuel to add with every update (in percent)
  39.  
  40. // repair settings
  41. _repair_enable = true; // enable or disable the repair option
  42. _repair_costs = [
  43. ["Air",[CurrencyName,_coinsRepairAir]], // [1,"ItemGoldBar10oz",1
  44. ["AllVehicles",[CurrencyName,_coinsRepairVehicles]] // 2 Gold for all other vehicles
  45.  
  46. ];
  47. _repair_repairTime = 2; // time needed to repair each damaged part (in seconds)
  48.  
  49. // rearm settings
  50. _rearm_enable = true; // enable or disable the rearm option
  51. //_blockedWeaponNames=["S-5","Hydra","CRV7"]; // weapon names you wish to exclude from rearming. Leave empty [] to allow all
  52. _blockedWeaponNames=[]; // Weapon names you wish to exclude from rearming. Leave empty [] to allow all
  53. _blockedAmmoNames = [ // Ammo names you wish to exclude from rearming. Leave empty [] to allow all
  54. "192Rnd_57mm",
  55. "128Rnd_57mm",
  56. "1200Rnd_762x51_M240",
  57. "SmokeLauncherMag",
  58. "60Rnd_CMFlareMagazine",
  59. "120Rnd_CMFlareMagazine",
  60. "240Rnd_CMFlareMagazine",
  61. "120Rnd_CMFlare_Chaff_Magazine",
  62. "240Rnd_CMFlare_Chaff_Magazine",
  63. "4Rnd_Ch29",
  64. "80Rnd_80mm",
  65. "80Rnd_S8T",
  66. "150Rnd_30mmAP_2A42",
  67. "150Rnd_30mmHE_2A42",
  68. "38Rnd_FFAR",
  69. "12Rnd_CRV7",
  70. "1500Rnd_762x54_PKT",
  71. "2000Rnd_762x54_PKT",
  72. "150Rnd_30mmAP_2A42",
  73. "150Rnd_30mmHE_2A42",
  74. "230Rnd_30mmAP_2A42",
  75. "230Rnd_30mmHE_2A42",
  76. "4000Rnd_762x51_M134",
  77. "300Rnd_25mm_GAU12",
  78. "2Rnd_GBU12",
  79. "2Rnd_Sidewinder_F35",
  80. "14Rnd_57mm",
  81. "64Rnd_57mm"
  82.  
  83. ];
  84. _rearm_costs = [
  85.  
  86. ["Car",[CurrencyName,_coinsRearmVehicles]],
  87. ["Air",[CurrencyName,_coinsRearmAir]] //
  88. ];
  89. _rearm_magazineCount = 3; // amount of magazines to be added to the vehicle weapon
  90.  
  91. // ----------------- CONFIG END -----------------
  92.  
  93.  
  94. _lastVehicle = objNull;
  95. _lastRole = [];
  96.  
  97. SP_refuel_action = -1;
  98. SP_repair_action = -1;
  99. SP_rearm_actions = [];
  100.  
  101. _messageShown = false;
  102.  
  103. _fnc_removeActions = {
  104. if (isNull _lastVehicle) exitWith {};
  105. _lastVehicle removeAction SP_refuel_action;
  106. SP_refuel_action = -1;
  107. _lastVehicle removeAction SP_repair_action;
  108. SP_repair_action = -1;
  109. {
  110. _lastVehicle removeAction _x;
  111. } forEach SP_rearm_actions;
  112. SP_rearm_actions = [];
  113. _lastVehicle = objNull;
  114. _lastRole = [];
  115. };
  116.  
  117. _fnc_getCosts = {
  118. private ["_vehicle","_costs","_cost"];
  119. _vehicle = _this select 0;
  120. _costs = _this select 1;
  121. _cost = [];
  122. {
  123. private "_typeName";
  124. _typeName = _x select 0;
  125. if (_vehicle isKindOf _typeName) exitWith {
  126. _cost = _x select 1;
  127. };
  128. } forEach _costs;
  129. _cost
  130. };
  131.  
  132. _fnc_actionTitle = {
  133. private ["_actionName","_costs","_costsText","_actionTitle"];
  134. _actionName = _this select 0;
  135. _costs = _this select 1;
  136. _costsText = _costsFree;
  137. if (count _costs == 2) then {
  138. private ["_itemName","_itemCount","_displayName"];
  139. _itemName = _costs select 0;
  140. _itemCount = _costs select 1;
  141. _displayName = _itemName;
  142. _costsText = format [_actionCostsFormat, _displayName, _itemCount];
  143. };
  144. _actionTitle = format [_actionTitleFormat, _actionName, _costsText];
  145. _actionTitle
  146. };
  147.  
  148. _fnc_isArmed = {
  149. private ["_role","_armed"];
  150. _role = _this;
  151. _armed = count _role > 1;
  152. _armed
  153. };
  154.  
  155. _fnc_getWeapons = {
  156. private ["_vehicle","_role","_weapons","_magazineNumber","_badAmmo","_badWeapon","_magazines","_weapon"];
  157. _vehicle = _this select 0;
  158. _role = _this select 1;
  159. _weapons = [];
  160. if (count _role > 1) then {
  161. private ["_turret","_weaponsTurret"];
  162. _turret = _role select 1;
  163. _weaponsTurret = _vehicle weaponsTurret _turret;
  164. {
  165. private "_weaponName";
  166. _weaponName = getText (configFile >> "CfgWeapons" >> _x >> "displayName");
  167. // block ammo types
  168. _badWeapon = _weaponName in _blockedWeaponNames;
  169. if (!_badWeapon) then {
  170.  
  171. _weapon = _x;
  172. // get all ammo types for this weapon
  173. _magazines = [_weapon] call _fnc_getMagazines;
  174.  
  175. // loop through all ammo types and add them to our list
  176. {
  177. _badAmmo = _x in _blockedAmmoNames;
  178. // check to see if our ammo is prohibited
  179. if (!_badAmmo) then {
  180. // add one entry to weapons per ammo type.
  181. _weapons set [count _weapons, [_weapon, _weaponName, _turret, _x]];
  182. };
  183.  
  184. } foreach _magazines;
  185. };
  186.  
  187. } forEach _weaponsTurret;
  188. } else {
  189. private ["_turret","_weaponsTurret","_badAmmo","_badWeapon","_magazines","_weapon"];
  190. _turret = [-1];
  191. _weaponsTurret = vehicle player weaponsTurret [-1];
  192. {
  193. private "_weaponName";
  194. _weaponName = getText (configFile >> "CfgWeapons" >> _x >> "displayName");
  195.  
  196. // block ammo types
  197. _badWeapon = _weaponName in _blockedWeaponNames;
  198. if (!_badWeapon) then {
  199.  
  200. _weapon = _x;
  201. // get all ammo types for this weapon
  202. _magazines = [_weapon] call _fnc_getMagazines;
  203.  
  204. // loop through all ammo types and add them to our list
  205. {
  206. // check to see if our ammo is prohibited
  207. _badAmmo = _x in _blockedAmmoNames;
  208. if (!_badAmmo) then {
  209. _weapons set [count _weapons, [_weapon, _weaponName, _turret, _x]];
  210. } forEach _weaponsTurret;
  211. };
  212. _weapons
  213. };
  214.  
  215. while {true} do {
  216. private ["_vehicle","_inVehicle"];
  217. _vehicle = vehicle player;
  218. _inVehicle = _vehicle != player;
  219. if (local _vehicle && _inVehicle) then {
  220. private ["_pos","_servicePoints","_inRange"];
  221. _pos = getPosATL _vehicle;
  222. _servicePoints = (nearestObjects [_pos, _servicePointClasses, _maxDistance]) - [_vehicle];
  223. _inRange = count _servicePoints > 0;
  224. if (_inRange) then {
  225. private ["_servicePoint","_role","_actionCondition","_costs","_actionTitle"];
  226. _servicePoint = _servicePoints select 0;
  227. if (assignedDriver _vehicle == player) then {
  228. _role = ["Driver", [-1]];
  229. } else {
  230. _role = assignedVehicleRole player;
  231. };
  232. if (((str _role) != (str _lastRole)) || (_vehicle != _lastVehicle)) then {
  233. // vehicle or seat changed
  234. call _fnc_removeActions;
  235. };
  236. _lastVehicle = _vehicle;
  237. _lastRole = _role;
  238. _actionCondition = "vehicle _this == _target && LOCAL _target";
  239. if (SP_refuel_action < 0 && _refuel_enable) then {
  240. _costs = [_vehicle, _refuel_costs] call _fnc_getCosts;
  241. _actionTitle = ["Refuel", _costs] call _fnc_actionTitle;
  242. SP_refuel_action = _vehicle addAction [_actionTitle, _folder + "service_point_refuel.sqf", [_servicePoint, _costs, _refuel_updateInterval, _refuel_amount], -1, false, true, "", _actionCondition];
  243. };
  244. if (SP_repair_action < 0 && _repair_enable) then {
  245. _costs = [_vehicle, _repair_costs] call _fnc_getCosts;
  246. _actionTitle = ["Repair", _costs] call _fnc_actionTitle;
  247. SP_repair_action = _vehicle addAction [_actionTitle, _folder + "service_point_repair.sqf", [_servicePoint, _costs, _repair_repairTime], -1, false, true, "", _actionCondition];
  248. };
  249. if ((_role call _fnc_isArmed) && (count SP_rearm_actions == 0) && _rearm_enable) then {
  250. private ["_weapons"];
  251. _costs = [_vehicle, _rearm_costs] call _fnc_getCosts;
  252. _weapons = [_vehicle, _role] call _fnc_getWeapons;
  253. {
  254. private "_weaponName";
  255. _weaponName = _x select 1;
  256. _actionTitle = [format["Rearm %1", _weaponName], _costs] call _fnc_actionTitle;
  257. SP_rearm_action = _vehicle addAction [_actionTitle, _folder + "service_point_rearm.sqf", [_servicePoint, _costs, _rearm_magazineCount, _x], -1, false, true, "", _actionCondition];
  258. SP_rearm_actions set [count SP_rearm_actions, SP_rearm_action];
  259. } forEach _weapons;
  260. };
  261. if (!_messageShown && _message != "") then {
  262. _messageShown = true;
  263. _vehicle vehicleChat _message;
  264. };
  265. } else {
  266. call _fnc_removeActions;
  267. _messageShown = false;
  268. };
  269. } else {
  270. call _fnc_removeActions;
  271. _messageShown = false;
  272. };
  273. sleep 2;
  274. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement