Jump to content

Weapon accessory issue


Recommended Posts

Hello friends.

I buy weapon attachments, but the weapon doesn't come on it, it goes in the bag.

For this, after purchasing weapon attachments, I want them to be added to the weapon.

How can I edit this?

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...
Posted (edited)

If you just want the code I understand Scroll down, but....

Upon reviewing the code, I found a few potential errors or areas of improvement:

  1. In the parameters section, the default values are specified as arrays with a single element, e.g., ["_bool", false, [false]]. It seems like a typo, and the default values should be simply specified as ["_bool", false].

  2. In the "CfgWeapons" case, there is a condition check for if ((_details select 4) isEqualTo 4096) then { if ((_details select 5) isEqualTo -1) then { _isgun = true; }; };. This condition can be simplified by combining the checks into a single line: if ((_details select 4) isEqualTo 4096 && (_details select 5) isEqualTo -1) then { _isgun = true; };.

  3. In the "CfgWeapons" case, there is a repetitive code block that can be simplified by extracting it into a separate function. The repeated code block is responsible for adding the item to the appropriate weapon slot based on the type. By creating a function, you can reduce code duplication and improve maintainability.

  4. The variable _ispack is declared but not used in the "CfgVehicles" case. If it's not needed, you can remove it to avoid confusion.

  5. The switch case for "CfgWeapons" contains nested switch cases, which can make the code harder to read and understand. Consider refactoring the code to use separate functions or helper methods to handle different scenarios, making the code more modular and easier to follow.

  6. There are several occurrences of if (!isNil "_items") then { ... };, but the _items variable is only set within specific cases. If _items is not set, the condition check is unnecessary and can be removed.

These suggestions aim to improve the code structure, readability, and maintainability. However, without a specific problem or expected behavior, it is challenging to provide a comprehensive review or identify all potential issues.

bare with me as I am rewriting the code now to fix the errors I've noted

Edited by KllTA
Link to comment
Share on other sites

Posted (edited)

These changes should help improve the code's structure and readability, as well as address some potential issues. However, please note that I can't guarantee that the code will work as intended without additional context or a specific problem to solve. Make sure to thoroughly test the code and adjust it as needed to meet your requirements.

 

#include "..\..\script_macros.hpp"
/*
File: fn_handleItem.sqf
Author: Bryan "tonic" Boardwine

Description
Main gear handling functionality.
*/

private["_items", "_isgun"];

params[
    ["_item", "", [""]],
    ["_bool", false, [false]],
    ["_ispack", false, [false]],
    ["_ongun", false, [false]],
    ["_override", false, [false]],
    ["_touniform", false, [false]],
    ["_tovest", false, [false]],
    ["_preview", false, [false]]
];

// Some checks
if (_item == "") exitwith {};

private _details = [_item] call life_fnc_fetchCfgDetails;
if (count _details == 0) exitwith {};

if (_bool) then {
    switch (_details select 6) do {
        case "CfgGlasses": {
            if (_touniform) exitwith {
                player addItemtouniform _item;
            };
            if (_tovest) exitwith {
                player addItemtovest _item;
            };
            
            if (_ispack) then {
                player addItemtobackpack _item;
            } else {
                if (_override) then {
                    player addItem _item;
                } else {
                    if (!(goggles player == "")) then {
                        removeGoggles player;
                    };
                    player addgoggles _item;
                };
            };
        };
        
        case "Cfgvehicles": {
            if (!(backpack player == "")) then {
                _items = backpackitems player;
                removeBackpack player;
            };
            
            player addbackpack _item;
            clearAllitemsfromBackpack player;
            
            if (!isnil "_items") then {
                {
                    [_x, true, true, false, true] call life_fnc_handleItem;
                } forEach _items;
            };
        };
        
        case "Cfgmagazines": {
            if (_touniform) exitwith {
                player addItemtouniform _item;
            };
            if (_tovest) exitwith {
                player addItemtovest _item;
            };
            if (_ispack) exitwith {
                player addItemtobackpack _item;
            };
            
            player addMagazine _item;
        };
        
        case "Cfgweapons": {
            if (_touniform) exitwith {
                player addItemtouniform _item;
            };
            if (_tovest) exitwith {
                player addItemtovest _item;
            };
            if (_ispack) exitwith {
                player addItemtobackpack _item;
            };
            
            if ((_details select 4) in [1, 2, 4, 5, 4096]) then {
                if ((_details select 4) == 4096) then {
                    if ((_details select 5) == - 1) then {
                        _isgun = true;
                    };
                } else {
                    _isgun = true;
                };
            };
            
            if (_isgun) then {
                if (!_ispack && _override) exitwith {};
                // It was in the vest/uniform, try to close to prevent it overriding stuff... (Actual weapon and not an item)
                if (_item == "mineDetector") then {
                    player addItem _item;
                } else {
                    player addWeapon _item;
                };
            } else {
                switch (_details select 5) do {
                    case 0: {
                        if (_ispack) then {
                            player addItemtobackpack _item;
                        } else {
                            if (_override) then {
                                player addItem _item;
                            } else {
                                player addprimaryWeaponItem _item;
                            };
                        };
                    };
                    case 1: {
                        if (_ispack) then {
                            player addItemtobackpack _item;
                        } else {
                            if (_override) then {
                                player addItem _item;
                            } else {
                                player addHandgunItem _item;
                            };
                        };
                    };
                    case 2: {
                        if (_ispack) then {
                            player addItemtobackpack _item;
                        } else {
                            if (_override) then {
                                player addItem _item;
                            } else {
                                player addsecondaryWeaponItem _item;
                            };
                        };
                    };
                    case 3: {
                        if (_ispack) then {
                            player addItemtobackpack _item;
                        } else {
                            if (_override) then {
                                player addItem _item;
                            };
                        };
                    };
                    default {
						systemChat format["Unhandled item type: %1", _item];
						diag_log format["Unhandled item type: %1", _item];
					};
                };
            };
        };
    };
};

// Handle gear preview
if (_preview) then {
    player call life_fnc_handleItemPreview;
};

 

Edited by KllTA
Fixed
  • Like 1
Link to comment
Share on other sites

@MaviS Topic Bumped, Issue is solved. If you need any further assistance please let me know. I usually don't write the code for Users but the Arma3Life framework at times can be a pain. the snip I provided will solve your issues and some more. feel free to copy paste this into your code as you wish! if this helped feel free to heart it for others to see

Link to comment
Share on other sites

Posted (edited)

@GraveYard Thanks for bringing this to my attention
My bad I was rushing the code and was also working on another project, it is now fixed

I will also recheck my work throughout Viscode and Debug through ArmDebugger

Code appears to be working correctly, I have removed the accidental Prams that I use for another framework!

REMOVED: addLauncherItem
Edited by KllTA
Accidental code from another proj
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.