Jump to content

Recommended Posts

Hi
Does anyone know how to limit the number of mag to 10 if a player needs to get more ammunition? 

I have some kind of script that works but it gives the inventory full mags. 

If (Player CanAdd ((GetArray (ConfigFile >> "CfgWeapons" >> currentWeapon player >> "Magazines")) Select 0)) Then
    {
    While {Player CanAdd ((GetArray (ConfigFile >> "CfgWeapons" >> currentWeapon player >> "Magazines")) Select 0)} Do
        {
        Player AddMagazine ((GetArray (ConfigFile >> "CfgWeapons" >> currentWeapon player >> "Magazines")) Select 0);
        };
    Player playMove "AinvPknlMstpSrasWrflDnon_Putdown_AmovPknlMstpSrasWrflDnon";
    PlaySound "Rearm";
    }
    Else
    {
    PlaySound "OnClick_Cancel";
    };

Share this post


Link to post
Share on other sites

Would this pseudocode do the trick?

while == true
     inv = playerInventory
     if inv > 10 mags

          call 150mm fire support on player position
     endIf
done

 

Share this post


Link to post
Share on other sites
if (count magazines player > 10) then {
//Do something to punish player, or remove magazine with removeMagazineGlobal
}

 

Share this post


Link to post
Share on other sites

 

On 3/3/2020 at 1:58 PM, Dedmen said:

if (count magazines player > 10) then { //Do something to punish player, or remove magazine with removeMagazineGlobal }

Ok good idea, but where to put this script. 

Share this post


Link to post
Share on other sites

You could run it in a while loop from initPlayerLocal.sqf/onPlayerRespawn.sqf, though that may not be performative. A better choice might be to add a TAKE event handler to each player unit (from the same init/respawn scripts) which does that check when fired.

Share this post


Link to post
Share on other sites
On 3/3/2020 at 12:58 PM, Dedmen said:

if (count magazines player > 10) then {
//Do something to punish player, or remove magazine with removeMagazineGlobal
}

 

Hi Dedmen

if i just want to remove ANY magazine that the player has over 10 then how do i remove it, since i do not know what weapon the player want to use in game for my SP game.

I did look at the RemoveMagazineGlobal on Wiki but is says that you have to type the name of the magazin, i am planning to to use RHS mods for my game , but the player can also use vanilla weapons, so how can i check to see if player has more than 10 magazines anytime in game , this counts for west only, what the player puts inside his backpack does not count.

 

Play3r.

Share this post


Link to post
Share on other sites
22 hours ago, Play3r said:

but is says that you have to type the name of the magazin

Yep, and "magazines player" from the script above, returns a list of magazine type names that you can use for removeMagazine

 

But.. What do you do if the player has 11 magazines, but only one magazine that fits his weapon and 10 others that he cannot use. If you remove that one magazine that he can use and leave him with 10 useless ones that wouldn't be that fair.

So if you want to really do it right, it won't be that easy, you probably want to remove the least useful magazine.

 

As for removing any magazines that go over 10.

 

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

https://community.bistudio.com/wiki/select

 

That will just grab all (up to 500, but I don't think you'll get that high) magazines that are past number 10. Not caring about how useful the first 10 magazines are.

  • Thanks 1

Share this post


Link to post
Share on other sites
10 hours ago, Dedmen said:

But.. What do you do if the player has 11 magazines, but only one magazine that fits his weapon and 10 others that he cannot use.

then he has taken the wrong ones to start with..to bad for him  LOL

 

I will try the script..

 

Ps. sorry @Casio91Fin for taking over your tread.  

 

 

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

×