Jump to content

Recommended Posts

REPACK and AUTO REPACK scripts

 

Hi all,

Here are two scripts (addon is scheduled) for those you want to repack their magazines.

First one is a simple auto-repack. No action needed. Based on a simple EH, the code runs when the player fires, so the auto-repack needs has a "one round latency" to work. Not a real problem.

Second one is more "realistic". Player must open the inventory and double click on each kind of mags to be repacked.

 

Parameters: NONE

 

AUTO-REPACK

to be placed in initPlayerLocal.sqf or in init.sqf when player is defined.

player addEventHandler ["fired",{
  if (player == _this select 0 && vehicle player == player) then {
    _mags = magazinesAmmo player;
    _inv = _mags select {(_x select 0) in getArray (configFile >> "cfgWeapons" >> currentWeapon player >> "magazines")};
  if (count _inv > 1) then {
    _sort = [_inv,[],{_x select 1},"ASCEND"] call BIS_fnc_sortBy;
    _lowest_mag = _sort select 0 select 0;
    _lowest_cnt = _sort select 0 select 1;
    _mags_space = _sort select [1, count _sort - 1];
    _full_tot = 0;
    _remain_tot = 0;
   {_full_tot = _full_tot + getnumber (configFile >> "cfgmagazines" >> _x select 0 >> "count")} forEach _mags_space;
   {_remain_tot = _remain_tot + (_x select 1)} forEach _mags_space;
  _full_space = _full_tot - _remain_tot;
  if (_lowest_cnt <= _full_space) then {
    for "_i" from 0 to count _mags_space - 1 do {
      if (_lowest_cnt > 0) then {
        _current_mag = _mags_space select _i select 0;
        _current_ammo = _mags_space select _i select 1;
        _current_space =  getnumber (configFile >> "cfgmagazines" >> _current_mag >> "count") - _current_ammo;
        if (_current_space > 0) then {
          _mags_space set [_i,[_current_mag,_current_ammo + _lowest_cnt]];
          _lowest_cnt = _lowest_cnt - _current_space;
        };
      };
    };
    {player removeMagazineGlobal (_x select 0)} forEach (magazinesAmmo player select {(_x select 0) in getArray (configFile >> "cfgWeapons" >> currentWeapon player >> "magazines")});
    {player addMagazine _x} forEach _mags_space;
  };
 }};
}];

 

 

MAGAZINE REPACK

to be placed in initPlayerLocal.sqf or in init.sqf when player is defined.

MGI_fnc_repack = {
  _idc = ctrlIDC (_this select 0);
  _selectedIndex = _this select 1;
  player setVariable ["MGImags", +((magazinesAmmoFull player) select {(lbdata [_idc,_selectedIndex]) in _x})];
  player setVariable ["MGIselect", true];
  false
};

0 = [] spawn {
  while {true} do {
    waitUntil {!(isnull (finddisplay 602)) && isnil {player getVariable "MGIselect"}};
    ((findDisplay 602) displayCtrl 619) ctrlSetEventHandler ["LBDblClick", "_this  call MGI_fnc_repack"];
    ((findDisplay 602) displayCtrl 633) ctrlSetEventHandler ["LBDblClick", "_this  call MGI_fnc_repack"];
    ((findDisplay 602) displayCtrl 638) ctrlSetEventHandler ["LBDblClick", "_this  call MGI_fnc_repack"];

    waitUntil {!isnil {player getVariable "MGIselect"} or isNull (findDisplay 602)};
    if (!isnil {player getVariable "MGIselect"}) then {
      private ["_mag","_wpnType","_wpn"];
      if (player getVariable ["MGImags",[]] isEqualTo []) then {
        _mag = "";
        _wpn = ""
      } else {
        _cnts = 0;
        _mag = (player getVariable "MGImags") select 0 select 0;
        _fullcnt = getnumber (configFile >> "cfgmagazines" >>_mag >> "count");
        if (_fullcnt > 0) then {
          {
            _wpnType = _x select 3;
            switch (_wpnType) do {
              case 1: {_wpn = primaryWeapon player};
              case 2: {_wpn = handGunWeapon player};
              case 4: {_wpn = secondaryWeapon player};
              default {_wpn =""};
            };
            _cnts = _cnts + (_x select 1);
            player setammo [_wpn,0];
          } count (player getVariable ["MGImags",[]]);
          _remainingShots = _cnts mod _fullcnt;
          {player removeMagazineGlobal _mag} count  (player getVariable ["MGImags",[]]);
          player addMagazines [_mag, floor (_cnts/_fullcnt)];
          if (_remainingShots >0) then {
            player addMagazine [_mag,_remainingShots];
          };
          reload player;
        };
      };
      player setVariable ["MGIselect", nil];
    };
  };
};

Double click on any magazine in your inventory.

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

So the first one allows for COD style reloads? If so that's cool and useful for arcade scenarios. 

Share this post


Link to post
Share on other sites
38 minutes ago, Spatsiba said:

So the first one allows for COD style reloads? If so that's cool and useful for arcade scenarios. 

 

Both codes keep the limitation of the global rounds number. If you need unlimited ammos, it's easy to do but it's something different.

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×