Jump to content

Disappearing Mags on login / revive fix


He-Man

Recommended Posts

Hi,

everybody of you know the problem with disappearing mags out of current weapon on login (only with 6,5mm weapons, especially GL-Weapons) and revive (every weapon).

Now I took some time to search for the Problem and I found it.

I also found some other things, that I was able to tune.

Let's begin with EPOCH_server_loadplayer.sqf:

Spoiler

                if (count _weaponsAndItems >= 2) then {
                    _equipped = _weaponsAndItems select 2;

If count _weaponsAndItems is >= 2, it can be 2. But then, _equipped can not be _weaponsaAndItems select 2!

So it must be "if (count _weaponsAndItems >= 3)"

 

Spoiler

                        {
                            ...
                            if (_x isEqualType []) then{
                                _wMags = true;
                                _wMagsArray = _x;
                            } else {
                                // attachments
                                if (_x != "") then{
                                    _attachments pushBack _x;
                                };
                            };
                            ...
                        } forEach(_weaponsAndItems select 1);

_weaponsAndItems select 1 is defined in EPOCH_server_savePlayer.sqf as "weaponsItems _player".

If the Player have a GL Weapon within a normal mag AND rnd Greande Shell, "weaponsItems _player" gives an array of: ['attach1','attach2','attach3',[magazine1],[magazine2],'bipod'].

Because there can come 2 arrays of mags, it must be: "_wMagsarray PUSHBACK _x"

 

Spoiler

                        if (_weapon in _equipped) then {
                            _equipped = _equipped - [_weapon];
                            if (_wMags) then {
                                _newPlyr addMagazine _wMagsArray;
                            };
                            if (_weapon != "") then {
                                _newPlyr addWeapon _weapon;
                            };
                            switch _type do {
                                case 1: { // primary
                                    removeAllPrimaryWeaponItems _newPlyr;
                                    { _newPlyr addPrimaryWeaponItem _x } forEach _attachments;
                                };
                                case 2:    { // handgun
                                    removeAllHandgunItems _newPlyr;
                                    { _newPlyr addHandgunItem _x } forEach _attachments;
                                };
                                case 4:    { // secondary
                                    // removeAllSecondaryWeaponItems player; does not exist ?
                                    {
                                        _newPlyr removeSecondaryWeaponItem _x;
                                    } forEach (secondaryWeaponItems _newPlyr);

                                    { _newPlyr addSecondaryWeaponItem _x } forEach _attachments;
                                };
                            };
                        } else {
                            // overflow need to add these items to storage
                            {
                                _newPlyr addItem _x;
                            } forEach _attachments;
                            if (_wMags) then {
                                _newPlyr addMagazine _wMagsArray;
                            };
 

In this Part, you can trim the code a bit. There is no need for running "if (_wMags) then ..." in IF and in ELSE. So just move it before the if/else.

The second part is, because we made an array of more then one mag in _wMagsArray, we have to load it as follows:

                        if (_wMags) then {
                            {
                                _newPlyr addMagazine _x;
                            } foreach _wMagsArray;
                        };
 

Now we come to EPOCH_server_revivePlayer.sqf:

Because the load player script and the revive player script are very similar, a have assumed the _fnc_addItemToX from the load player script to the top of the revive player script

Spoiler

if (_player distance _reviver > 20) exitWith{};

_fnc_addItemToX = {
    private ["_itemSlot","_itemqtys","_newPlyr"];
    _newPlyr = _this select 0;
    {
        _itemSlot = _forEachIndex;
        _itemqtys = _x select 1;
        {
            for "_i" from 1 to (_itemqtys select _forEachIndex) do {
                switch _itemSlot do {
                    case 0: { _newPlyr addItemToUniform _x };
                    case 1: { _newPlyr addItemToVest _x };
                    case 2: { _newPlyr addItemToBackpack _x };
                };
            };
        } forEach(_x select 0);
    } forEach (_this select 1);
};

if (!local _player) then {

 

Everybody knows, that often the revived Player have another weapon, as before he died. That is because the script is looking for all nearestObjects WeaponHolderSimulated from near to far and the last Weaponholder overwrite the first.

The solution is reversing the array of weaponholders.

In this part we also can fix the problem, that weapons can be duped by reviving. We delete the weponholders with our primary and secondary weapon instant.

Here the "old" code:

Spoiler

                _primaryWeapon = "";
                _secondaryWeapon = "";

                _droppedWeapons = [];
                {
                    {
                        _droppedWeapons pushBack _x;
                        _type = getNumber(configfile >> "cfgweapons" >> (_x select 0) >> "type");
                        switch _type do {
                            case 1: { _primaryWeapon = _x select 0 };
                            case 4: { _secondaryWeapon = _x select 0 };
                        };
                    } forEach (weaponsItemsCargo _x);

                } forEach nearestObjects[_player, ["WeaponHolderSimulated"], 12];

and here the new:

Spoiler

                 _wh = nearestObjects[_player, ["WeaponHolderSimulated"], 12];
               _droppedPrimary = [];
                _droppedSecondary = [];
                _droppedWeapons = [];
                _deleteprimary = [];
                _deletesecondary = [];
                reverse _wh;
                {
                    _currwh = _x;
                    {
                        _type = getNumber(configfile >> "cfgweapons" >> (_x select 0) >> "type");
                        switch _type do {
                            case 1: {_droppedPrimary = _x; _primaryWeapon = _x select 0; _deleteprimary = [_currwh]};
                            case 4: {_droppedSecondary = _x; _secondaryWeapon = _x select 0;_deletesecondary = [_currwh]};
                        };
                    } forEach (weaponsItemsCargo _x);
                } foreach _wh;
                {
                    if (!isnull _x) then {deletevehicle _x};
                } foreach (_deleteprimary+_deletesecondary);
                
                if !(_droppedPrimary isequalto []) then {_droppedWeapons pushback _droppedPrimary};
                if !(_droppedSecondary isequalto []) then {_droppedWeapons pushback _droppedSecondary};

 

Next the same as in load player:  

"if (count _weapons >= 3) then {..."

And for loading the Inventory I have taken the same codes as in load player.

 

It is already tested and working for us.

Here the complete files:

 

Epoch_server_loadPlayer.sqf:

https://www.dropbox.com/s/yaepsos0b11x5m4/EPOCH_server_loadPlayer.sqf?dl=0

 

EPOCH_server_revivePlayer.sqf:

https://www.dropbox.com/s/vb8ayuwlc2x0fb4/EPOCH_server_revivePlayer.sqf?dl=0

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...