Advertisement
Guest User

service_point.sqf

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