Advertisement
Guest User

Untitled

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