Advertisement
Guest User

service_point.sqf

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