selectWeapon: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(66 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| ofp |Game name=
|game1= ofp
|version1= 1.27


|1.27|Game version=
|game2= ofpe
|version2= 1.00


|arg= local |Multiplayer Arguments=
|game3= arma1
|version3= 1.00


|eff= global |Multiplayer Effects=
|game4= arma2
|version4= 1.00


|gr1= Weapons |GROUP1=
|game5= arma2oa
____________________________________________________________________________________________
|version5= 1.50


| Selects the given weapon.
|game6= tkoh
|version6= 1.00


Note: For weapons that have more than one muzzle, you have to input the <u>muzzlename</u> and '''not''' the weaponName.
|game7= arma3
|version7= 0.50


<br>The only weapons that have muzzleNames seem to be rifles with grenade launchers, handgrenades, smokeshells and satchels.
|arg= local


<br>In all other cases the weaponName must be used.
|eff= global
Fortunately, in OFP, in most cases, both names are the same. But check.


<br>In ArmA the weaponNames and muzzleNames are different.
|gr1= Weapons


<br>For muzzle names see [[:Category:Weapons|cfgWeapons]].  
|descr= Selects the given weapon.


<br>'''NOTE:''' The unit must be [[local]] to the PC on which command is executed. |DESCRIPTION=
|s1= unitName [[selectWeapon]] muzzleName
____________________________________________________________________________________________


| unitName '''selectWeapon''' muzzleName |SYNTAX=
|p1= unitName: [[Object]]


|p1= unitName: [[Object]] |PARAMETER1=
|p2= muzzleName: [[String]] - name of the weapon or muzzle
|p2= muzzleName: [[String]] |PARAMETER2=
{{Feature|important|For weapons that have '''more than one muzzle''', you have to input the '''muzzleName''' and not the '''weaponName'''.
* In {{ofp}}, in most cases, both names are the same. But check.
* In {{arma1}} the weaponNames and muzzleNames are different.
* For muzzle names see [[:Category:Weapons|CfgWeapons]].
}}
 
|r1= [[Nothing]]
 
|s2= unit [[selectWeapon]] [weapon, muzzle, firemode]
 
|s2since= arma3 2.08
 
|p21= unit: [[Object]] - person. This argument has to be [[local]], or it can be remote when executed on the [[isServer|server]]
 
|p22= weapon: [[String]] - name of the weapon, personal or vehicle's weapon (see [[weaponState]])
 
|p23= muzzle: [[String]] - name of the selected muzzle (see [[weaponState]])


| [[Nothing]] |RETURNVALUE=
|p24= firemode: [[String]] - name of the firemode (see [[weaponState]])
____________________________________________________________________________________________
 
|x1= <code>_soldier1 [[selectWeapon]] "LAWLauncher";</code> |EXAMPLE1=
|x2= <code>[[player]] [[selectWeapon]] "M203Muzzle";</code> |EXAMPLE2=


____________________________________________________________________________________________
|r2= [[Boolean]] or [[Nothing]] - [[true]] on success, [[false]] on failure, [[Nothing]] when the call to the command is dispatched over network


| [[fire]], [[forceWeaponFire]], [[primaryWeapon]], [[handgunWeapon]], [[secondaryWeapon]], [[weapons]], [[ArmA:_Actions#SWITCHWEAPON|action SwitchWeapon]], [[ArmA:_Actions#SWITCHMAGAZINE|action SwitchMagazine]]|SEEALSO=
|x1= <sqf>_soldier1 selectWeapon "LAWLauncher";</sqf>


|x2= <sqf>player selectWeapon "M203Muzzle";</sqf>
|x3= <sqf>player selectWeapon ["arifle_MX_GL_ACO_F", "arifle_MX_GL_ACO_F", "FullAuto"];</sqf>
|seealso= [[fire]] [[forceWeaponFire]] [[primaryWeapon]] [[handgunWeapon]] [[secondaryWeapon]] [[weapons]] [[ArmA:_Actions#SWITCHWEAPON|action SwitchWeapon]] [[ArmA:_Actions#SWITCHMAGAZINE|action SwitchMagazine]] [[isSwitchingWeapon]]
}}
}}


<h3 style="display:none">Notes</h3>
{{Note
<dl class="command_description">
|user= Dr_Eyeball
<!-- Note Section BEGIN -->
|timestamp= 20080805094900
|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:<br>
SelectWeapon.sqf
<sqf>
// Desc: select default weapon & handle multiple muzzles
if (count weapons player > 0) then
{
private ['_type', '_muzzles'];
 
_type = ((weapons player) select 0);
// check for multiple muzzles (eg: GL)
_muzzles = getArray (configFile >> "cfgWeapons" >> _type >> "muzzles");


<dd class="notedate">Posted on 5 Aug, 2008
if (count _muzzles > 1) then
<dt class="note">[[User:Dr_Eyeball|Dr_Eyeball]]<dd class="note">
{
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:<br>
player selectWeapon (_muzzles select 0);
SelectWeapon.sqf
}
<pre>
else
// Desc: select default weapon & handle multiple muzzles
{
if (count weapons player > 0) then
player selectWeapon _type;
{
};
  private['_type', '_muzzles'];
};
</sqf>
  _type = ((weapons player) select 0);
}}
  // check for multiple muzzles (eg: GL)
  _muzzles = getArray(configFile >> "cfgWeapons" >> _type >> "muzzles");
  if (count _muzzles > 1) then
  {
    player selectWeapon (_muzzles select 0);
  }
  else
  {
    player selectWeapon _type;
  };
};
</pre>


<dd class="notedate">Posted on 22 Mar, 2010
{{Note
<dt class="note">'''MaestrO.fr'''<dd class="note">
|user= MaestrO.fr
Can be used with [[primaryWeapon]] to select the primary weapon.
|timestamp= 20100322154500
|text= Can be used with [[primaryWeapon]] to select the primary weapon.
An example with muzzle care (see Dr_EyeBall note) :  
An example with muzzle care (see Dr_EyeBall note) :  
<pre>
<sqf>
if ( (primaryWeapon player) != "") then
if ((primaryWeapon player) != "") then
{
{
  private['_type', '_muzzles'];
private ['_type', '_muzzles'];
  _type = primaryWeapon player;
  // check for multiple muzzles (eg: GL)
  _muzzles = getArray(configFile >> "cfgWeapons" >> _type >> "muzzles");
  if (count _muzzles > 1) then
  {
    player selectWeapon (_muzzles select 0);
  }
  else
  {
    player selectWeapon _type;
  };
};
</pre>


<!-- Note Section END -->
_type = primaryWeapon player;
</dl>
// check for multiple muzzles (eg: GL)
<h3 style="display:none">Bottom Section</h3>
_muzzles = getArray (configFile >> "cfgWeapons" >> _type >> "muzzles");
[[Category:Scripting Commands|SELECTWEAPON]]
 
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
if (count _muzzles > 1) then
[[Category:Scripting Commands OFP 1.96|SELECTWEAPON]]
{
[[Category:Scripting Commands OFP 1.46|SELECTWEAPON]]
player selectWeapon (_muzzles select 0);
[[Category:Scripting Commands Armed Assault|SELECTWEAPON]]
}
[[Category:Command_Group:_Weapons|{{uc:{{PAGENAME}}}}]]
else
[[Category:Scripting Commands Arma 2|{{uc:{{PAGENAME}}}}]]
{
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
player selectWeapon _type;
[[Category:Scripting Commands Take On Helicopters|{{uc:{{PAGENAME}}}}]]
};
};
</sqf>
}}

Latest revision as of 23:54, 2 November 2024

Hover & click on the images for description

Description

Description:
Selects the given weapon.
Groups:
Weapons

Syntax

Syntax:
unitName selectWeapon muzzleName
Parameters:
unitName: Object
muzzleName: String - name of the weapon or muzzle
For weapons that have more than one muzzle, you have to input the muzzleName and not the weaponName.
  • In Operation Flashpoint, in most cases, both names are the same. But check.
  • In Armed Assault the weaponNames and muzzleNames are different.
  • For muzzle names see CfgWeapons.
Return Value:
Nothing

Alternative Syntax

Syntax:
unit selectWeapon [weapon, muzzle, firemode]
Parameters:
unit: Object - person. This argument has to be local, or it can be remote when executed on the server
weapon: String - name of the weapon, personal or vehicle's weapon (see weaponState)
muzzle: String - name of the selected muzzle (see weaponState)
firemode: String - name of the firemode (see weaponState)
Return Value:
Boolean or Nothing - true on success, false on failure, Nothing when the call to the command is dispatched over network

Examples

Example 1:
_soldier1 selectWeapon "LAWLauncher";
Example 2:
player selectWeapon "M203Muzzle";
Example 3:
player selectWeapon ["arifle_MX_GL_ACO_F", "arifle_MX_GL_ACO_F", "FullAuto"];

Additional Information

See also:
fire forceWeaponFire primaryWeapon handgunWeapon secondaryWeapon weapons action SwitchWeapon action SwitchMagazine isSwitchingWeapon

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Dr_Eyeball - c
Posted on Aug 05, 2008 - 09:49 (UTC)
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:
SelectWeapon.sqf
// Desc: select default weapon & handle multiple muzzles if (count weapons player > 0) then { private ['_type', '_muzzles']; _type = ((weapons player) select 0); // check for multiple muzzles (eg: GL) _muzzles = getArray (configFile >> "cfgWeapons" >> _type >> "muzzles"); if (count _muzzles > 1) then { player selectWeapon (_muzzles select 0); } else { player selectWeapon _type; }; };
MaestrO.fr - c
Posted on Mar 22, 2010 - 15:45 (UTC)
Can be used with primaryWeapon to select the primary weapon. An example with muzzle care (see Dr_EyeBall note) :
if ((primaryWeapon player) != "") then { private ['_type', '_muzzles']; _type = primaryWeapon player; // check for multiple muzzles (eg: GL) _muzzles = getArray (configFile >> "cfgWeapons" >> _type >> "muzzles"); if (count _muzzles > 1) then { player selectWeapon (_muzzles select 0); } else { player selectWeapon _type; }; };