Advertisement
Halvhjearne

service_point.sqf

Apr 15th, 2015
1,740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.58 KB | None | 0 0
  1. // Vehicle Service Point by Axe Cop +fix to rearm all weapons from driver+only delete ammo in rearmed weapon only (not entire turret) by HALV
  2. //reworked for a3 epoch by Halv
  3.  
  4. private ["_folder","_servicePointClasses","_maxDistance","_costsFree","_message","_messageShown","_repair_enable","_repair_costs","_repair_repairTime","_rearm_enable","_rearm_costs","_lastVehicle","_lastRole","_fnc_removeActions","_fnc_getCosts","_fnc_actionTitle","_fnc_getWeapons"];
  5.  
  6. //====================== general settings
  7. _folder = "addons\service_point\"; // folder where the service point scripts are saved, relative to the mission file
  8. _servicePointClasses = ["Land_CarService_F"]; // service point classes (can be house, vehicle and unit classes)
  9. _maxDistance = 10; // maximum distance from a service point for the options to be shown
  10. _costsFree = "free"; // text for no costs
  11. _message = "-- Vehicle Service Point --"; // message to be shown when in range of a service point (set to "" to disable)
  12. _actionColour = "#0096ff"; //the colour of the scroll action Blue: "#0096ff"
  13.  
  14. //====================== repair settings
  15. _repair_enable = true; // enable or disable the repair option
  16. _repair_repairTime = 5; // time needed to repair each damaged part (in seconds)
  17.  
  18. _repair_costs = [
  19.     ["Air",250], // 250 Crypto for air
  20.     ["Tank",250], // 250 Crypto Tank
  21.     ["Tracked_APC",200], // 200 Crypto Tracked_APC
  22.     ["Wheeled_APC",150], // 150 Crypto Wheeled_APC
  23.     ["AllVehicles",100] // 100 Crypto all other vehicles
  24. ];
  25.  
  26. //====================== rearm settings
  27. _rearm_enable = true; // enable or disable the rearm option
  28.  
  29. //deny re-arm if more than this amount of current weapons magazines already in the vehicle
  30. _deny_already_armed_with = 1;
  31. //deny re-arm if more than this amount of magazines already in the vehicle
  32. _GlobalMagazineMAX = 6;
  33.  
  34. //weapon classes disabled from re-arming
  35. _NoGoWeapCName = [
  36.     //irrelevant ones
  37.     "Horn","SmokeLauncher","MiniCarHorn","SportCarHorn","TruckHorn2","TruckHorn","BikeHorn","CarHorn","TruckHorn3",
  38.     //not allowed ones
  39.     "FFARLauncher_14","2A46M","2A46MRocket","M256","AT5LauncherSingle"
  40. ];
  41.  
  42. //magazine classnames not allowed to be rearmed
  43. _NoGoAmmoCName = [
  44. ];
  45.  
  46. //cost per magazine for individual vehicles
  47. _rearm_costs = [
  48. //  ["ArmoredSUV_PMC_DZE",100], // special costs for a single vehicle type
  49.     ["Air",400], // 500 Crypto for air
  50.     ["Tank",300], // 400 Crypto for Tank
  51.     ["Tracked_APC",250], // 350 Crypto for Tracked_APC
  52.     ["Wheeled_APC",200], // 300 Crypto for Wheeled_APC
  53.     ["AllVehicles",150] // 250 Crypto for all other vehicles
  54. ];
  55.  
  56. //debug weapons to see classnames in chat/rpt
  57. _debugWeapon = false;
  58.  
  59.  
  60. //=================================== CONFIG END
  61. if(isNil "isHalvTradeEnabled")then{isHalvTradeEnabled = false};
  62.  
  63. _lastVehicle = objNull;
  64. _lastRole = [];
  65.  
  66. SP_repair_action = -1;
  67. SP_rearm_actions = [];
  68.  
  69. _messageShown = false;
  70.  
  71. _fnc_removeActions = {
  72.     if (isNull _lastVehicle) exitWith {};
  73.     _lastVehicle removeAction SP_repair_action;
  74.     SP_repair_action = -1;
  75.     {
  76.         _lastVehicle removeAction _x;
  77.     } forEach SP_rearm_actions;
  78.     SP_rearm_actions = [];
  79.     _lastVehicle = objNull;
  80.     _lastRole = [];
  81. };
  82.  
  83. _fnc_getCosts = {
  84.     private ["_vehicle","_costs","_cost"];
  85.     _vehicle = _this select 0;
  86.     _costs = _this select 1;
  87.     _cost = [];
  88.     {
  89.         private "_typeName";
  90.         _typeName = _x select 0;
  91.         if (_vehicle isKindOf _typeName) exitWith {
  92.             _cost = _x select 1;
  93.         };
  94.     } forEach _costs;
  95.     _cost
  96. };
  97.  
  98. _fnc_actionTitle = {
  99.     private ["_actionName","_costs","_costsText","_actionTitle"];
  100.     _actionName = _this select 0;
  101.     _costs = _this select 1;
  102.     _costsText = _costsFree;
  103.     if (_costs > 0) then {
  104.         private ["_itemName","_displayName"];
  105.         _costsText = format ["%1 Crypto",_costs];
  106.     };
  107.     _actionTitle = format ["<t color='%3'>%1 (%2)</t>", _actionName, _costsText,_actionColour];
  108.     _actionTitle
  109. };
  110.  
  111. _fnc_getWeapons = {
  112.     private ["_vehicle","_role","_weapons"];
  113.     _vehicle = _this select 0;
  114.     //turrets positions to search for weapons
  115.     _turrets = [[-1],[0],[1],[2],[0,0],[1,0],[2,0],[0,1],[0,2]];
  116.     _weapons = [];
  117.     {
  118.         _turret = _x;
  119.         _weaponsTurret = _vehicle weaponsTurret _turret;
  120.         {
  121.             _weapon = _x;
  122.             if !(_weapon in _NoGoWeapCName) then{
  123.                 _weaponName = getText (configFile >> "CfgWeapons" >> _weapon >> "displayName");
  124.                 _weapons pushBack [_weapon, _weaponName, _turret];
  125.             };
  126.         }forEach _weaponsTurret;
  127.     }forEach _turrets;
  128.     _weapons
  129. };
  130.  
  131. _fnc_getAmmo = {
  132.     private ["_vehicle","_role","_weapons"];
  133.     _vehicle = _this select 0;
  134.     _weapon = _this select 1;
  135.     _allammo = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");
  136.     _ammoreturn = [];
  137.     {
  138.         _curammo = _x;
  139.         if !(_curammo in _NoGoAmmoCName) then{
  140.             _ammoname = getText (configFile >> "Cfgmagazines" >> _curammo >> "displayName");
  141.             _ammoreturn pushBack [_curammo, _ammoname];
  142.         };
  143.     }forEach _allammo;
  144.     _ammoreturn
  145. };
  146.  
  147. while {true} do {
  148.     private ["_vehicle","_inVehicle"];
  149.     _vehicle = vehicle player;
  150.     _inVehicle = _vehicle != player;
  151.     if (local _vehicle && _inVehicle) then {
  152.         private ["_pos","_servicePoints","_inRange"];
  153.         _pos = getPosATL _vehicle;
  154.         _servicePoints = (nearestObjects [_pos, _servicePointClasses, _maxDistance]) - [_vehicle];
  155.         _inRange = count _servicePoints > 0;
  156.         if (_inRange && (speed (_vehicle) < 1) && (speed (_vehicle) > -1)) then {
  157.             private ["_servicePoint","_role","_actionCondition","_costs","_actionTitle"];
  158.             _servicePoint = _servicePoints select 0;
  159.             _role = assignedVehicleRole player;
  160.             if (((str _role) != (str _lastRole)) || (_vehicle != _lastVehicle)) then {
  161.                 // vehicle or seat changed
  162.                 call _fnc_removeActions;
  163.             };
  164.             _lastVehicle = _vehicle;
  165.             _lastRole = _role;
  166.             _actionCondition = "vehicle _this == _target && local _target";
  167.             if (SP_repair_action < 0 && _repair_enable) then {
  168.                 _costs = [_vehicle, _repair_costs] call _fnc_getCosts;
  169.                 _actionTitle = [format["Repair %1",getText (configFile >> "Cfgvehicles" >> typeOf _vehicle >> "displayName")], _costs] call _fnc_actionTitle;
  170.                 SP_repair_action = _vehicle addAction [format["<img size='1.5'image='\a3\Ui_f\data\IGUI\Cfg\Cursors\iconrepairvehicle_ca.paa'/> %1",_actionTitle], _folder + "service_point_repair.sqf", [_servicePoint, _costs, _repair_repairTime], -1, false, true, "", _actionCondition];
  171.             };
  172.             if ((count SP_rearm_actions == 0) && _rearm_enable) then {
  173.                 private ["_weapons"];
  174.                 _costs = [_vehicle, _rearm_costs] call _fnc_getCosts;
  175.                 _weapons = [_vehicle, _role] call _fnc_getWeapons;
  176.                 {
  177.                     private "_weaponName";
  178.                     _curweapon = _x select 0;
  179.                     _weaponName = _x select 1;
  180.                     _curturret = _x select 2;
  181.                     if(_debugWeapon)then{_msg = format["WEAPONS DEBUG: %1",_x];diag_log _msg;systemChat _msg;};
  182.                     _ammo = [_vehicle,_curweapon] call _fnc_getAmmo;
  183.                     {
  184.                         _ammoclass = _x select 0;
  185.                         _ammoname = _x select 1;
  186.                         _actionTitle = [format["Rearm %1 with %2", _weaponName,_ammoname], _costs] call _fnc_actionTitle;
  187.                         SP_rearm_action = _vehicle addAction [format["<img size='1.5'image='\a3\Ui_f\data\IGUI\Cfg\WeaponIcons\mg_ca.paa'/> %1",_actionTitle], _folder + "service_point_rearm.sqf", [_servicePoint, _costs, [_weaponName,_ammoclass,_ammoname,_GlobalMagazineMAX,_deny_already_armed_with,_curturret]], -1, false, true, "", _actionCondition];
  188.                         SP_rearm_actions set [count SP_rearm_actions, SP_rearm_action];
  189.                     }forEach _ammo;
  190.                    
  191.                 } forEach _weapons;
  192.             };
  193.             if (!_messageShown && _message != "") then {
  194.                 _messageShown = true;
  195.                 _vehicle vehicleChat _message;
  196.             };
  197.         } else {
  198.             call _fnc_removeActions;
  199.             _messageShown = false;
  200.         };
  201.     } else {
  202.         call _fnc_removeActions;
  203.         _messageShown = false;
  204.     };
  205.     sleep 2;
  206. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement