Advertisement
anden3

edit_vehicle_loadout.sqf

Mar 13th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 5.27 KB | None | 0 0
  1. span class="re5"> GetVehicleWeapons = {
  2.     private _result = [];
  3.    
  4.     private _getAnyMagazines = {
  5.         private _weapon = configFile >> "CfgWeapons" >> _this;
  6.         private _mags = [];
  7.        
  8.         {
  9.             _mags = _mags + getArray (
  10.                 (if (_x == "this") then { _weapon } else { _weapon >> _x }) >> "magazines"
  11.             );
  12.         } forEach getArray (_weapon >> "muzzles");
  13.         _mags;
  14.     };
  15.    
  16.     private _findRecurse = {
  17.         private ["_class", "_currentPath"];
  18.        
  19.         private _root =  (_this select 0);
  20.         private _path = +(_this select 1);
  21.        
  22.         for "_i" from 0 to count _root -1 do {
  23.             _class = _root select _i;
  24.            
  25.             if (isClass _class) then {
  26.                 _currentPath = _path + [_i];
  27.                
  28.                 {
  29.                     _result set [count _result, [_x, _x call _getAnyMagazines, _currentPath, str _class]];
  30.                 } forEach getArray (_class >> "weapons");
  31.                
  32.                 _class = _class >> "turrets";
  33.                
  34.                 if (isClass _class) then {
  35.                     [_class, _currentPath] call _findRecurse;
  36.                 };
  37.             };
  38.         };
  39.     };
  40.    
  41.     private _class = (
  42.         configFile >> "CfgVehicles" >> (
  43.             switch (typeName _this) do {
  44.                 case "STRING" : {_this};
  45.                 case "OBJECT" : {typeOf _this};
  46.                 default {nil}
  47.             }
  48.         ) >> "turrets"
  49.     );
  50.    
  51.     [_class, []] call _findRecurse;
  52.     _result;
  53. };
  54. AddVehicleAmmo = {    
  55.     params ["_unit", "_mag", "_path", "_magCount", "_ammoCount"];
  56.     _unit removeMagazinesTurret [_mag, _path];
  57.    
  58.     if (_ammoCount > 0) then {
  59.         _unit addMagazineTurret [_mag, _path, _ammoCount];
  60.     };
  61.    
  62.     if (_magCount > 0) then {
  63.         for "_i" from 1 to _magCount do {
  64.             _unit addMagazineTurret [_mag, _path];
  65.         };
  66.     };
  67. };
  68. ["Equipment", "Change Vehicle Loadout", {
  69.     _unit = [_logic, false] call Ares_fnc_GetUnitUnderCursor;
  70.     if (isNull _unit) exitWith {
  71.         [localize "STR_NO_OBJECT_SELECTED"] call Ares_fnc_ShowZeusMessage;
  72.         playSound "FD_Start_F";
  73.     };
  74.    
  75.     _unit = vehicle _unit;
  76.    
  77.     if (!(_unit isKindOf "AllVehicles")) exitWith {
  78.         ["Object is not a vehicle"] call Ares_fnc_ShowZeusMessage;
  79.         playSound "FD_Start_F";
  80.     };
  81.    
  82.     _weaponList = _unit call GetVehicleWeapons;
  83.    
  84.     _paths         = [];
  85.     _weapons       = [];
  86.     _magazines     = [];
  87.     _magazineNames = [];
  88.    
  89.     {
  90.         _x params ["_weapon", "_mags", "_path", "_config"];
  91.         _weapons pushBack _weapon;
  92.        
  93.         _magNames = [];
  94.        
  95.         {
  96.             _magNames pushBack (getText (configFile >> "CfgMagazines" >> _x >> "displayName"));
  97.         } forEach _mags;
  98.        
  99.         _paths         pushBack _path;
  100.         _magazines     pushBack _mags;
  101.         _magazineNames pushBack _magNames;
  102.     } forEach _weaponList;
  103.    
  104.     _properties = ["Loadout",  [
  105.         ["Choose weapon", _weapons]
  106.     ]] call Ares_fnc_ShowChooseDialog;
  107.    
  108.     if (count _properties == 0) exitWith {
  109.         ["Loadout editing aborted"] call Ares_fnc_ShowZeusMessage;
  110.     };
  111.    
  112.     _turretPath     = _paths         select (_properties select 0);
  113.     _weaponMags     = _magazines     select (_properties select 0);
  114.     _weaponMagNames = _magazineNames select (_properties select 0);
  115.    
  116.     _properties = ["Loadout", [
  117.         ["Choose magazine", _weaponMagNames]
  118.     ]] call Ares_fnc_ShowChooseDialog;
  119.    
  120.     if (count _properties == 0) exitWith {
  121.         ["Loadout editing aborted"] call Ares_fnc_ShowZeusMessage;
  122.     };
  123.    
  124.     _selectedMagazine = _weaponMags select (_properties select 0);
  125.    
  126.     _magazineCount = 0;
  127.     _largestMag    = 0;
  128.     _ammoCount     = 0;
  129.    
  130.     {
  131.         _x params ["_class", "_path", "_ammo", "_id", "_creator"];
  132.        
  133.         if (_class == _selectedMagazine) then {            
  134.             if (_ammo > _largestMag) then {
  135.                 _largestMag = _ammo;
  136.             };
  137.         };
  138.     } forEach magazinesAllTurrets _unit;
  139.    
  140.     {
  141.         _x params ["_class", "_path", "_ammo", "_id", "_creator"];
  142.        
  143.         if (_class == _selectedMagazine) then {
  144.             if (_ammo < _largestMag) then {
  145.                 _ammoCount = _ammo;
  146.             }
  147.             else {
  148.                 _magazineCount = _magazineCount + 1;
  149.             };
  150.         };
  151.     } forEach magazinesAllTurrets _unit;
  152.    
  153.     if (_ammoCount == 0 && _magazineCount > 0) then {
  154.         _ammoCount     = _largestMag;
  155.         _magazineCount = _magazineCount - 1;
  156.     };
  157.    
  158.     _properties = ["", [
  159.         ["Ammo Count",     str _ammoCount,     str _ammoCount],
  160.         ["Magazine Count", str _magazineCount, str _magazineCount]
  161.     ]] call Ares_fnc_ShowChooseDialog;
  162.    
  163.     if (count _properties == 0) exitWith {
  164.         ["Loadout editing aborted"] call Ares_fnc_ShowZeusMessage;
  165.     };
  166.    
  167.     _newAmmoCount = parseNumber (_properties select 0);
  168.     _newMagCount  = parseNumber (_properties select 1);
  169.    
  170.     [_unit, _selectedMagazine, _turretPath, _newMagCount, _newAmmoCount] remoteExecCall ["AddVehicleAmmo", _unit];
  171.    
  172. }] call Ares_fnc_RegisterCustomModule;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement