Jump to content

Recommended Posts

Hello everyone,

 

For a long while now, I have struggled with trying to manage the maximum number of inventory space on players as a mission maker.

Despite my best efforts, players still find ways when I am Zeus to either pick a container where they can have like 40 mags, or loot one later on in some way.

 

I am wondering if there is a way that by scripting, limit the number of magazines all players in a session can pick up.

For instance, if you set a limit of 10 magazines, either by stating which mag class names or just having all Cfg ammo you will not be able to add any more and get something like a message saying "I can't carry any more ammo. This is getting too heavy." regardless if you have more inventory space or not.

 

 

Tips or thoughts appreciated 🙂

 

 

Share this post


Link to post
Share on other sites

For a session, you could count how many times a player reloads his weapon.

For example, in initPlayerLocal.sqf:


 

MaxPrimaryWeaponMags = 10;
player addEventHandler ["Reloaded", {
  params ["_unit", "_weapon", "_muzzle", "_newMagazine", "_oldMagazine"];
  if (_weapon == primaryWeapon _unit) then {
    MaxPrimaryWeaponMags = MaxPrimaryWeaponMags -1;
    if (MaxPrimaryWeaponMags < 2) then {
      player removeMagazines (_newMagazine #0);
    };
  };
}];

Works for each type of magazines. You can check for whole compatible mags.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

There are still some things you can do to achieve this more "naturally". If the problem is that players can access ammo too easily, then you could for example:

  • give enemies a different type of ammo,
  • disable looting enemies completely,
  • clear inventory of containers/vehicles by default and add only what you want manually.

Removing magazines on reload isn't super intuitive in a situation where you check your inventory, you have plenty ammo and then suddenly after reload it turns out that you can't use any of it. IMO there should be feedback as soon as you try to pick up a magazine that you aren't allowed to use.

Also just to be sure, check if you have any arsenal available. Even if it's an empty arsenal, it still allows players to duplicate any items they already own.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks so far,

 

sooner or later I make a mistake or miss out on something and then it's too late, players are going to find some way to bypass if they can do it, so indeed I need something that enforce and makes sure it stays limited.

 

On 9/11/2023 at 2:26 PM, pierremgi said:

For a session, you could count how many times a player reloads his weapon.

For example, in initPlayerLocal.sqf:


 


MaxPrimaryWeaponMags = 10;
player addEventHandler ["Reloaded", {
  params ["_unit", "_weapon", "_muzzle", "_newMagazine", "_oldMagazine"];
  if (_weapon == primaryWeapon _unit) then {
    MaxPrimaryWeaponMags = MaxPrimaryWeaponMags -1;
    if (MaxPrimaryWeaponMags < 2) then {
      player removeMagazines (_newMagazine #0);
    };
  };
}];

Works for each type of magazines. You can check for whole compatible mags.

 

I have been testing this, works great. Maybe if I modify it somehow so that if players has above a certain number of mags, say 10, the excess number of mags above 10 will be removed after a reload and set to 10?

That way no matter how much mags you grab, you will be set back to a maximum number of mags each reload - if the number surpass 10.

I let the players know the rules, they loot excessive number of mags it will be set back, and then if they decide to try to go past it - it will be enforced without disrupting anything else.

Share this post


Link to post
Share on other sites

As far as a matter of cheating, I like the idea player can loose room by unusable mags, deleted.

 

16 hours ago, saddle said:

 Maybe if I modify it somehow so that if players has above a certain number of mags, say 10, the excess number of mags above 10 will be removed after a reload and set to 10?

That way no matter how much mags you grab, you will be set back to a maximum number of mags each reload - if the number surpass 10.

I let the players know the rules, they loot excessive number of mags it will be set back, and then if they decide to try to go past it - it will be enforced without disrupting anything else.

 

Yes. you can set the max nbr of mags (current mag only as above, compatible mags ), but also how/when the counter is reset. For example, the counter can be reset once mags are deleted.

Note: the above code count each mag (for primary weapon), so it's an overall count for the whole mission, and, no matter the player takes 2 or 3 mags from time to time, the countdown is ticking.

That can be a too big restriction.

 

Here is a new version, deleting above the max, at first reload!

 

MaxPrimaryWeaponMags = 10;
MaxHandGunMags = 3;
MaxMissiles = 1;
MaxHandGrenades = 3;
MaxLaunchGrenades = 2;
CompatThrowGrenades = compatibleMagazines "throw" select {!("_ir_" in toLowerANSI _x or "chemlight" in toLowerANSI _x)};

AAA_fnc_manageMags = compileFinal "
  params ['_plyr','_compats','_restricted',['_empty',FALSE]];
  {_plyr removeMagazines _x} count _compats;
  {_plyr addMagazines [_x,1]} count _restricted;
  if _empty then {
    _plyr setAmmo [currentMuzzle _plyr,0];
    reload _plyr;
  };
";

player addEventHandler ["Reloaded", {
  params ["_plyr", "_wpn", "_muzzle", "_newMag", ["_oldMag",["",0,-1,0]]];
  private _empty = (_oldMag #1 == 0);
  private _mag = _oldMag #0;
  private _compatMags = magazines _plyr select {_x in compatibleMagazines [currentWeapon _plyr,currentMuzzle _plyr]};
  _compatMags append [currentMagazine _plyr];
  _compatMags = _compatMags - [""];
  private ["_restricTedMags","_compatGrenades","_restricTedGrenades"];

  call {
    if (_wpn == primaryWeapon _plyr) exitWith {
      call {
        if (getNumber (configfile / "CfgMagazines" / _mag / "type") == 256 ) exitWith {
          if (count _compatMags > MaxPrimaryWeaponMags) then {
            _restricTedMags = _compatMags select [0,MaxPrimaryWeaponMags - 1];
          [_plyr,_compatMags,_restricTedMags,_empty] call AAA_fnc_manageMags;
          };
        };
        if (getNumber (configfile / "CfgMagazines" / _mag / "type") == 16 ) exitWith {
          if (count _compatMags > MaxLaunchGrenades) then {
            _restricTedMags = _compatMags select [0,MaxLaunchGrenades - 1];
            [_plyr,_compatMags,_restricTedMags,_empty] call AAA_fnc_manageMags;
          };
        };
      };
    };
    if (_wpn == "throw") exitWith {
      _compatGrenades = magazines _plyr select {_x in CompatThrowGrenades};
      if (count _compatGrenades > MaxHandGrenades) then {
        _restricTedGrenades = _compatGrenades select [0,MaxHandGrenades - 1];
        [_plyr,_compatGrenades,_restricTedGrenades] call AAA_fnc_manageMags;
      };
    };
    if (_wpn == handGunWeapon _plyr) exitWith {
      if (count _compatMags > MaxHandGunMags) then {
        _restricTedMags = _compatMags select [0,MaxHandGunMags - 1];
        [_plyr,_compatMags,_restricTedMags,_empty] call AAA_fnc_manageMags;
      };
    };
    if (_wpn == secondaryweapon _plyr) exitWith {
      _restricTedMags = _compatMags select [0, MaxMissiles - 1];
      if (count _compatMags > MaxMissiles) then {
        [_plyr,_compatMags,_restricTedMags,_empty] call AAA_fnc_manageMags;
      };
    };
  };
}];

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
On 9/13/2023 at 1:27 PM, pierremgi said:

As far as a matter of cheating, I like the idea player can loose room by unusable mags, deleted.

 

 

Yes. you can set the max nbr of mags (current mag only as above, compatible mags ), but also how/when the counter is reset. For example, the counter can be reset once mags are deleted.

Note: the above code count each mag (for primary weapon), so it's an overall count for the whole mission, and, no matter the player takes 2 or 3 mags from time to time, the countdown is ticking.

That can be a too big restriction.

 

Here is a new version, deleting above the max, at first reload!

 


MaxPrimaryWeaponMags = 10;
MaxHandGunMags = 3;
MaxMissiles = 1;
MaxHandGrenades = 3;
MaxLaunchGrenades = 2;
CompatThrowGrenades = compatibleMagazines "throw" select {!("_ir_" in toLowerANSI _x or "chemlight" in toLowerANSI _x)};

AAA_fnc_manageMags = compileFinal "
  params ['_plyr','_compats','_restricted',['_empty',FALSE]];
  {_plyr removeMagazines _x} count _compats;
  {_plyr addMagazines [_x,1]} count _restricted;
  if _empty then {
    _plyr setAmmo [currentMuzzle _plyr,0];
    reload _plyr;
  };
";

player addEventHandler ["Reloaded", {
  params ["_plyr", "_wpn", "_muzzle", "_newMag", ["_oldMag",["",0,-1,0]]];
  private _empty = (_oldMag #1 == 0);
  private _mag = _oldMag #0;
  private _compatMags = magazines _plyr select {_x in compatibleMagazines [currentWeapon _plyr,currentMuzzle _plyr]};
  _compatMags append [currentMagazine _plyr];
  _compatMags = _compatMags - [""];
  private ["_restricTedMags","_compatGrenades","_restricTedGrenades"];

  call {
    if (_wpn == primaryWeapon _plyr) exitWith {
      call {
        if (getNumber (configfile / "CfgMagazines" / _mag / "type") == 256 ) exitWith {
          if (count _compatMags > MaxPrimaryWeaponMags) then {
            _restricTedMags = _compatMags select [0,MaxPrimaryWeaponMags - 1];
          [_plyr,_compatMags,_restricTedMags,_empty] call AAA_fnc_manageMags;
          };
        };
        if (getNumber (configfile / "CfgMagazines" / _mag / "type") == 16 ) exitWith {
          if (count _compatMags > MaxLaunchGrenades) then {
            _restricTedMags = _compatMags select [0,MaxLaunchGrenades - 1];
            [_plyr,_compatMags,_restricTedMags,_empty] call AAA_fnc_manageMags;
          };
        };
      };
    };
    if (_wpn == "throw") exitWith {
      _compatGrenades = magazines _plyr select {_x in CompatThrowGrenades};
      if (count _compatGrenades > MaxHandGrenades) then {
        _restricTedGrenades = _compatGrenades select [0,MaxHandGrenades - 1];
        [_plyr,_compatGrenades,_restricTedGrenades] call AAA_fnc_manageMags;
      };
    };
    if (_wpn == handGunWeapon _plyr) exitWith {
      if (count _compatMags > MaxHandGunMags) then {
        _restricTedMags = _compatMags select [0,MaxHandGunMags - 1];
        [_plyr,_compatMags,_restricTedMags,_empty] call AAA_fnc_manageMags;
      };
    };
    if (_wpn == secondaryweapon _plyr) exitWith {
      _restricTedMags = _compatMags select [0, MaxMissiles - 1];
      if (count _compatMags > MaxMissiles) then {
        [_plyr,_compatMags,_restricTedMags,_empty] call AAA_fnc_manageMags;
      };
    };
  };
}];

 

 

Just did some extensive testing of this.

You have just helped me resolve one of my biggest headaches in hosting Arma sessions, and I hope many others will enjoy your talents.

Thank you so muchpierremgi, big props to you. 

Share this post


Link to post
Share on other sites

I have used this for a SP mission:

if (count magazines player > 10) then {
{player removeMagazineGlobal _x} forEach (magazines player select [10, 500])};

 

i cant remember where i got it and i don't know if ti can be used in a MP mission,

but maybe it can be inside the InitPlayerLocal.sqf.

  • Thanks 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

×