Advertisement
Halvhjearne

service_point_repair.sqf

Apr 15th, 2015
2,965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.49 KB | None | 0 0
  1. // Vehicle Service Point (Repair) by Axe Cop
  2. //reworked for a3 epoch by Halv
  3.  
  4. private ["_vehicle","_args","_servicePoint","_costs","_repairTime","_type","_name","_hitpoints","_allRepaired"];
  5.  
  6. _vehicle = _this select 0;
  7.  
  8. if (!local _vehicle) exitWith { diag_log format["Error: called service_point_repair.sqf with non-local vehicle: %1", _vehicle] };
  9.  
  10. _args = _this select 3;
  11. _servicePoint = _args select 0;
  12. _costs = _args select 1;
  13. _repairTime = _args select 2;
  14. _type = typeOf _vehicle;
  15. _name = getText(configFile >> "cfgVehicles" >> _type >> "displayName");
  16.  
  17. if (EPOCH_playerCrypto < _costs && isHalvTradeEnabled) exitWith {cutText [format["You need %1 Crypto to Repair %2", _costs,_name], "PLAIN DOWN"];};
  18.  
  19. if(_costs > 0 && isHalvTradeEnabled)then{
  20.     HALV_takegive = [player,(_costs*-1),true];
  21.     publicVariableServer "HALV_takegive";
  22. };
  23.  
  24. //EPOCH_playerCrypto = EPOCH_playerCrypto - _costs ;
  25.  
  26. //taken from a2 epoch vehicle_getHitpoints.sqf
  27. _fnc_vehicle_getHitpoints = {
  28.     private ["_cfgHitPoints", "_hps", "_funcGetHitPoints"];
  29.     _cfgHitPoints = configFile >> "CfgVehicles" >> (typeOf _this) >> "HitPoints";
  30.     _hps = [];
  31.  
  32.     _funcGetHitPoints =
  33.     {
  34.         for "_i" from 0 to ((count _this) - 1) do
  35.         {
  36.             private ["_hp"];
  37.             _hp = configName (_this select _i);
  38.            
  39.             if (!(_hp in _hps)) then
  40.             {
  41.                 _hps set [count _hps, _hp];
  42.             };
  43.         };
  44.     };
  45.  
  46.     while {(configName _cfgHitPoints) != ""} do
  47.     {
  48.         _cfgHitPoints call _funcGetHitPoints;
  49.         _cfgHitPoints = inheritsFrom _cfgHitPoints;
  50.     };
  51.  
  52.     _hps
  53. };
  54.  
  55. _vehicle engineOn false;
  56.  
  57. _hitpoints = _vehicle call _fnc_vehicle_getHitpoints;
  58. _allRepaired = true;
  59. {
  60.     private "_damage";
  61.     if ((vehicle player != _vehicle) || (!local _vehicle) || ([0,0,0] distance (velocity _vehicle) > 1)) exitWith {
  62.         _allRepaired = false;
  63.         titleText [format["Repairing of %1 stopped", _name], "PLAIN DOWN"];
  64.     };
  65.     _damage = _vehicle getHitPointDamage _x;
  66.     if (_damage > 0) then {
  67.         if (_repairTime > 0) then {
  68.             private "_partName";
  69.             //change "HitPart" to " - Part" rather than complicated string replace
  70.             _partName = toArray _x;
  71.             _partName set [0,20];
  72.             _partName set [1,45];
  73.             _partName set [2,20];
  74.             _partName = toString _partName;
  75.             titleText [format["Repairing%1 ...", _partName], "PLAIN DOWN", _repairTime];
  76.             sleep _repairTime;
  77.         };
  78.         _vehicle setHitPointDamage [_x, 0];
  79.     };
  80. } forEach _hitpoints;
  81.  
  82. if (_allRepaired) then {
  83.     _vehicle setDamage 0;
  84.     _vehicle setVelocity [0,0,1];
  85.     titleText [format["%1 Repaired", _name], "PLAIN DOWN"];
  86. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement