{"name":"setUnitLoadout","operator":null,"title":"setUnitLoadout","type":"command","url":"https://community.bistudio.com/wiki/setUnitLoadout","revid":370162,"updated":"2024-11-02T23:29:35Z","groups":["Unit Inventory"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"1.58"}],"since":{"game":"arma3","name":"Arma 3","version":"1.58"},"arma3_since":"1.58","branch":null,"locality":{"argument":"global","effect":"global","server_exec":false},"exec":null,"description":"Creates a loadout from given inventory structure and applies it to a unit.\nWhen String for class name is supplied, the command will search `CfgVehicles` for the given class in order to extract the loadout from config.\nIf Config is given, it will search given config (including mission config) for the loadout information.\nIn either case, the config should contain the following entries, which is standard for any unit class, for example:\n\n```cpp\nclass MyLoadout\n{\n    uniformClass = \"U_B_CombatUniform_mcam\";\n    backpack = \"B_AssaultPack_mcamo\";\n    linkedItems[] = { \"V_PlateCarrier1_rgr\", \"H_HelmetB\", \"ItemCompass\", \"ItemWatch\", \"ItemRadio\", \"NVGoggles\" };\n    weapons[] = { \"arifle_MX_ACO_pointer_F\", \"hgun_P07_F\" };\n    items[] = { \"FirstAidKit\", \"FirstAidKit\", \"FirstAidKit\" };\n    magazines[] = {\n        \"30Rnd_65x39_caseless_mag\", \"16Rnd_9x21_Mag\", \"SmokeShell\",\n        \"HandGrenade\", \"HandGrenade\", \"HandGrenade\", \"HandGrenade\", \"HandGrenade\",\n        \"HandGrenade\", \"HandGrenade\", \"HandGrenade\", \"HandGrenade\", \"HandGrenade\",\n        \"HandGrenade\", \"HandGrenade\", \"HandGrenade\", \"HandGrenade\", \"HandGrenade\",\n        \"HandGrenade\", \"HandGrenade\", \"HandGrenade\", \"HandGrenade\", \"HandGrenade\",\n        \"HandGrenade\", \"HandGrenade\", \"HandGrenade\", \"HandGrenade\"\n    };\n};\n```\n\n> [!IMPORTANT]\n> Since Arma 3 v2.20 if the command is executed while the unit is in the process of switching weapon, the command will be aborted. To check if unit is switching weapon use isSwitchingWeapon.","syntaxes":[{"syntax":"unit setUnitLoadout loadout","since":null,"effect":null,"exec":null,"params":[{"name":"unit","type":"Object","optional":false,"default":null,"description":null,"types":["Object"],"since":null,"text":"unit: Object"},{"name":"loadout","type":"Array","optional":false,"default":null,"description":"Unit Loadout Array","types":["Array"],"since":null,"text":"loadout: Array - Unit Loadout Array"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"unit","types":["Object"]},"right":{"text":"loadout","types":["Array"]}},{"syntax":"unit setUnitLoadout [loadout, fullMagazines]","since":null,"effect":null,"exec":null,"params":[{"name":"unit","type":"Object","optional":false,"default":null,"description":null,"types":["Object"],"since":null,"text":"unit: Object"},{"name":"loadout","type":"Array","optional":false,"default":null,"description":"Unit Loadout Array","types":["Array"],"since":null,"text":"loadout: Array - Unit Loadout Array"},{"name":"fullMagazines","type":"Boolean","optional":false,"default":null,"description":"partially emptied magazines will be refilled when the loadout is applied","types":["Boolean"],"since":null,"text":"fullMagazines: Boolean - partially emptied magazines will be refilled when the loadout is applied"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"unit","types":["Object"]},"right":{"text":"[loadout, fullMagazines]","types":["Array"]}},{"syntax":"unit setUnitLoadout name","since":null,"effect":null,"exec":null,"params":[{"name":"unit","type":"Object","optional":false,"default":null,"description":null,"types":["Object"],"since":null,"text":"unit: Object"},{"name":"name","type":"String","optional":false,"default":null,"description":"class name (see description)","types":["String"],"since":null,"text":"name: String - class name (see description)"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"unit","types":["Object"]},"right":{"text":"name","types":["String"]}},{"syntax":"unit setUnitLoadout config","since":null,"effect":null,"exec":null,"params":[{"name":"unit","type":"Object","optional":false,"default":null,"description":null,"types":["Object"],"since":null,"text":"unit: Object"},{"name":"config","type":"Config","optional":false,"default":null,"description":"config class (see description)","types":["Config"],"since":null,"text":"config: Config - config class (see description)"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"unit","types":["Object"]},"right":{"text":"config","types":["Config"]}}],"examples":[{"text":"```sqf\n_unit setUnitLoadout \"B_Soldier_F\";                                        // by class name\n_unit setUnitLoadout (configFile >> \"CfgVehicles\" >> \"B_Soldier_F\");    // by config entry\n_unit setUnitLoadout (missionConfigFile >> \"MyLoadout\");                // (also works for mission config)\n_unit setUnitLoadout getUnitLoadout _otherUnit;                            // by loadout array\n```","code":["_unit setUnitLoadout \"B_Soldier_F\";\t\t\t\t\t\t\t\t\t\t// by class name\n_unit setUnitLoadout (configFile >> \"CfgVehicles\" >> \"B_Soldier_F\");\t// by config entry\n_unit setUnitLoadout (missionConfigFile >> \"MyLoadout\");\t\t\t\t// (also works for mission config)\n_unit setUnitLoadout getUnitLoadout _otherUnit;\t\t\t\t\t\t\t// by loadout array"]},{"text":"```sqf\nplayer_2 setUnitLoadout (getUnitLoadout player_1);            // Copies loadout from player_1 and applies it to player_2\nplayer_2 setUnitLoadout [getUnitLoadout player_1, true];    // Copies loadout from player_1 and applies it to player_2 while topping up all magazines\n```","code":["player_2 setUnitLoadout (getUnitLoadout player_1);\t\t\t// Copies loadout from player_1 and applies it to player_2\nplayer_2 setUnitLoadout [getUnitLoadout player_1, true];\t// Copies loadout from player_1 and applies it to player_2 while topping up all magazines"]},{"text":"Strip unit of everything:\n\n```sqf\n_unit setUnitLoadout (configFile >> \"EmptyLoadout\");\n```","code":["_unit setUnitLoadout (configFile >> \"EmptyLoadout\");"]},{"text":"Make sure the unit is not switching weapon:\n\n```sqf\nplayer spawn \n{\n    waitUntil {!isSwitchingWeapon _this};\n    _this setUnitLoadout (configFile >> \"EmptyLoadout\");\n};\n```","code":["player spawn \n{\n\twaitUntil {!isSwitchingWeapon _this};\n\t_this setUnitLoadout (configFile >> \"EmptyLoadout\");\n};"]}],"multiplayer":null,"problems":"> [!IMPORTANT]\n> If this command is used on the player, it makes the inventory window bug (if opened) - vest and backpack tabs disappear. Closing and re-opening the inventory solves the issue.","aliases":[],"see_also":["getUnitLoadout","isSwitchingWeapon"],"notes":[{"user":"Demellion","date":"2019-12-17T23:08:00Z","text":"Empty or used magazines in loadouts will be refilled under specific circumstance, even if the refill argument is false. This seems to happen if amount of used magazines is 2 or more.\n\n```sqf\nplayer setUnitLoadout [\n    [\"arifle_MX_ACO_pointer_F\", \"\", \"acc_pointer_IR\", \"optic_Aco\", [], [], \"\"],\n    [],\n    [\"hgun_P07_F\", \"\", \"\", \"\", [\"16Rnd_9x21_Mag\", 16], [], \"\"],\n    [\"U_B_CombatUniform_mcam\", [[\"30Rnd_65x39_caseless_mag\", 1, 1]]],\n    [\"V_PlateCarrier1_rgr\", []],\n    [\"B_AssaultPack_mcamo_Ammo\", []],\n    \"H_HelmetB_grass\", \"\", [], [\"ItemMap\", \"\", \"ItemRadio\", \"ItemCompass\", \"ItemWatch\", \"NVGoggles\"]\n];\n```\n\nWill result in 30Rnd magazine with one bullet in it.\n\n```sqf\nplayer setUnitLoadout [\n    [\"arifle_MX_ACO_pointer_F\", \"\", \"acc_pointer_IR\", \"optic_Aco\", [], [], \"\"],\n    [],\n    [\"hgun_P07_F\", \"\", \"\", \"\", [\"16Rnd_9x21_Mag\", 16], [], \"\"],\n    [\"U_B_CombatUniform_mcam\", [[\"30Rnd_65x39_caseless_mag\", 2, 1]]],\n    [\"V_PlateCarrier1_rgr\", []],\n    [\"B_AssaultPack_mcamo_Ammo\", []],\n    \"H_HelmetB_grass\", \"\", [], [\"ItemMap\", \"\", \"ItemRadio\", \"ItemCompass\", \"ItemWatch\", \"NVGoggles\"]\n];\n```\n\nWill result in 2 magazines but full, 30 rounds in it. This applies to any magazines count >2. They will never be with specified amount of rounds, even if you force the refill argument to false."},{"user":"Andrew_S90","date":"2020-10-23T21:16:00Z","text":"Here is a command I wrote up that provides a fix for the ammo bug described by Demellion above.\nhttps://pastebin.com/SHX41Jkk\nPass a loadout to your compiled command and it will provide one back that will not refill ammo."},{"user":"POLPOX","date":"2022-08-23T08:27:09Z","text":"```sqf\nplayer setUnitLoadout [\n    nil, nil, nil, nil, nil,\n    [\"B_Bergen_sgg\", nil],\n    nil, nil, nil, nil\n];\n```\n\nYou can use nil to skip some desired parameter. The skipped part will be ignored and remain the same with old loadout.\n\nThis method is *very slightly* faster than the latter method:\n\n```sqf\nprivate _loadout = getUnitLoadout player;\n_loadout#5 set [0, \"B_Bergen_mcamo_F\"];\nplayer setUnitLoadout _loadout;\n```"}],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Unit Inventory","Introduced with Arma 3 version 1.58","Scripting Commands","Scripting Commands: Global Effect"]}