MaviS Posted April 10 Share Posted April 10 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? 1 Quote Link to comment Share on other sites More sharing options...
GraveYard Posted April 11 Share Posted April 11 The file that dose this is fn_handleItem.sqf. Are you running a modded server? 1 Quote Link to comment Share on other sites More sharing options...
MaviS Posted April 11 Author Share Posted April 11 8 hours ago, GraveYard said: The file that dose this is fn_handleItem.sqf. Are you running a modded server? No. I am not using modded server. fn_handleItem.sqf https://pastebin.com/dA2r9sgq Quote Link to comment Share on other sites More sharing options...
GraveYard Posted April 11 Share Posted April 11 Do you get any error? Quote Link to comment Share on other sites More sharing options...
MaviS Posted April 11 Author Share Posted April 11 4 hours ago, GraveYard said: Do you get any error? No, there is no error. Working properly. I want the Scope and Suppressor to be added to the weapon after purchase. Quote Link to comment Share on other sites More sharing options...
MaviS Posted April 24 Author Share Posted April 24 topic current. Quote Link to comment Share on other sites More sharing options...
KllTA Posted May 20 Share Posted May 20 (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: 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]. 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; };. 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. The variable _ispack is declared but not used in the "CfgVehicles" case. If it's not needed, you can remove it to avoid confusion. 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. 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 May 20 by KllTA Quote Link to comment Share on other sites More sharing options...
KllTA Posted May 20 Share Posted May 20 (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 May 22 by KllTA Fixed 1 Quote Link to comment Share on other sites More sharing options...
KllTA Posted May 20 Share Posted May 20 @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 Quote Link to comment Share on other sites More sharing options...
GraveYard Posted May 22 Share Posted May 22 @KllTA in case 3 addLauncherItem is not part of Arma 3 1 Quote Link to comment Share on other sites More sharing options...
KllTA Posted May 22 Share Posted May 22 (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 May 22 by KllTA Accidental code from another proj 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.