{"name":"selectWeapon","operator":null,"title":"selectWeapon","type":"command","url":"https://community.bistudio.com/wiki/selectWeapon","revid":373007,"updated":"2025-03-11T23:11:21Z","groups":["Weapons"],"status":"ok","replaced_by":[],"games":[{"game":"ofp","name":"Operation Flashpoint","version":"1.27"},{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofp","name":"Operation Flashpoint","version":"1.27"},"arma3_since":"0.50","branch":null,"locality":{"argument":"local","effect":"global","server_exec":false},"exec":null,"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","since":null,"effect":null,"exec":null,"params":[{"name":"unitName","type":"Object","optional":false,"default":null,"description":null,"types":["Object"],"since":null,"text":"unitName: Object"},{"name":"muzzleName","type":"String","optional":false,"default":null,"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> - 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.","types":["String"],"since":null,"text":"muzzleName: String - 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> - 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."}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"unitName","types":["Object"]},"right":{"text":"muzzleName","types":["String"]}},{"syntax":"unit selectWeapon [weapon, muzzle, firemode]","since":"arma3 2.08","effect":null,"exec":null,"params":[{"name":"unit","type":"Object","optional":false,"default":null,"description":"person. This argument has to be local, or it can be remote when executed on the server","types":["Object"],"since":null,"text":"unit: Object - person. This argument has to be local, or it can be remote when executed on the server"},{"name":"weapon","type":"String","optional":false,"default":null,"description":"name of the weapon, personal or vehicle's weapon (see weaponState)","types":["String"],"since":null,"text":"weapon: String - name of the weapon, personal or vehicle's weapon (see weaponState)"},{"name":"muzzle","type":"String","optional":false,"default":null,"description":"name of the selected muzzle (see weaponState)","types":["String"],"since":null,"text":"muzzle: String - name of the selected muzzle (see weaponState)"},{"name":"firemode","type":"String","optional":false,"default":null,"description":"name of the firemode (see weaponState)","types":["String"],"since":null,"text":"firemode: String - name of the firemode (see weaponState)"}],"returns":{"type":"Boolean or Nothing","types":["Boolean","Nothing"],"description":"true on success, false on failure, Nothing when the call to the command is dispatched over network","text":"Boolean or Nothing - true on success, false on failure, Nothing when the call to the command is dispatched over network"},"form":"binary","operator":null,"left":{"text":"unit","types":["Object"]},"right":{"text":"[weapon, muzzle, firemode]","types":["Array"]}}],"examples":[{"text":"```sqf\n_soldier1 selectWeapon \"LAWLauncher\";\n```","code":["_soldier1 selectWeapon \"LAWLauncher\";"]},{"text":"```sqf\nplayer selectWeapon \"M203Muzzle\";\n```","code":["player selectWeapon \"M203Muzzle\";"]},{"text":"```sqf\nplayer selectWeapon [\"arifle_MX_GL_ACO_F\", \"arifle_MX_GL_ACO_F\", \"FullAuto\"];\n```","code":["player selectWeapon [\"arifle_MX_GL_ACO_F\", \"arifle_MX_GL_ACO_F\", \"FullAuto\"];"]}],"multiplayer":null,"problems":null,"aliases":[],"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:\n\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```"}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Weapons","Introduced with Operation Flashpoint version 1.27","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Scripting Commands: Global Effect","Take On Helicopters: Scripting Commands"]}