{"name":"selectWeapon","title":"selectWeapon","type":"command","url":"https://community.bistudio.com/wiki/selectWeapon","revid":373007,"updated":"2025-03-11T23:11:21Z","groups":["Weapons"],"status":"ok","games":{"ofp":"1.27","ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofp 1.27","arma3_since":"0.50","locality":{"argument":"local","effect":"global"},"description":"Selects the given weapon.\n\n> [!NOTE]\n> Passing empty string will not deselect current weapon. Use 'SwitchWeapon' action instead:\n>\n> ```sqf\n> player action [\"SwitchWeapon\", player, player, -1]\n> ```","syntaxes":[{"syntax":"unitName selectWeapon muzzleName","params":[{"name":"unitName","type":"Object","type_expr":"Object"},{"name":"muzzleName","type":"String","description":"name of the weapon or muzzle\n\n> [!IMPORTANT]\n> For weapons that have **more than one muzzle**, you have to input the **muzzleName** and not the **weaponName**.\n>\n> - In Operation Flashpoint, in most cases, both names are the same. But check.\n> - In Armed Assault the weaponNames and muzzleNames are different.\n> - For muzzle names see CfgWeapons.","type_expr":"String"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"binary","left":{"text":"unitName"},"right":{"text":"muzzleName"}},{"syntax":"unit selectWeapon [weapon, muzzle, firemode]","since":"arma3 2.08","params":[{"name":"unit","type":"Object","description":"person. This argument has to be local, or it can be remote when executed on the server","type_expr":"Object"},{"name":"weapon","type":"String","description":"name of the weapon, personal or vehicle's weapon (see weaponState)","type_expr":"String"},{"name":"muzzle","type":"String","description":"name of the selected muzzle (see weaponState)","type_expr":"String"},{"name":"firemode","type":"String","description":"name of the firemode (see weaponState)","type_expr":"String"}],"returns":{"type":"Boolean or Nothing","type_expr":"Boolean | Nothing","description":"true on success, false on failure, Nothing when the call to the command is dispatched over network"},"form":"binary","left":{"text":"unit"},"right":{"text":"[weapon, muzzle, firemode]"}}],"examples":[{"code":["_soldier1 selectWeapon \"LAWLauncher\";"]},{"code":["player selectWeapon \"M203Muzzle\";"]},{"code":["player selectWeapon [\"arifle_MX_GL_ACO_F\", \"arifle_MX_GL_ACO_F\", \"FullAuto\"];"]}],"see_also":["fire","forceWeaponFire","primaryWeapon","handgunWeapon","secondaryWeapon","weapons","ArmA: Actions","isSwitchingWeapon"],"notes":[{"user":"Dr_Eyeball","date":"2008-08-05T09:49:00Z","text":"Rather than simply using selectWeapon to select your default weapon after adding them to your player, it is recommended you use a script instead similar to the following, which caters for multiple muzzles:\nSelectWeapon.sqf\n\n```sqf\n// Desc: select default weapon & handle multiple muzzles\nif (count weapons player > 0) then\n{\n    private ['_type', '_muzzles'];\n\n    _type = ((weapons player) select 0);\n    // check for multiple muzzles (eg: GL)\n    _muzzles = getArray (configFile >> \"cfgWeapons\" >> _type >> \"muzzles\");\n\n    if (count _muzzles > 1) then\n    {\n        player selectWeapon (_muzzles select 0);\n    }\n    else\n    {\n        player selectWeapon _type;\n    };\n};\n```"},{"user":"MaestrO.fr","date":"2010-03-22T15:45:00Z","text":"Can be used with primaryWeapon to select the primary weapon.\nAn example with muzzle care (see Dr_EyeBall note) :\n\n```sqf\nif ((primaryWeapon player) != \"\") then\n{\n    private ['_type', '_muzzles'];\n\n    _type = primaryWeapon player;\n    // check for multiple muzzles (eg: GL)\n    _muzzles = getArray (configFile >> \"cfgWeapons\" >> _type >> \"muzzles\");\n\n    if (count _muzzles > 1) then\n    {\n        player selectWeapon (_muzzles select 0);\n    }\n    else\n    {\n        player selectWeapon _type;\n    };\n};\n```"}]}