selectWeapon: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "]]<dd class="note">" to "]]</dt> <dd class="note">")
m (Some wiki formatting)
Line 30: Line 30:
|descr= Selects the given weapon.
|descr= Selects the given weapon.


|s1= unitName '''selectWeapon''' muzzleName
|s1= unitName [[selectWeapon]] muzzleName


|p1= unitName: [[Object]]
|p1= unitName: [[Object]]
Line 57: Line 57:
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>
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
SelectWeapon.sqf
<pre>
<code>{{cc|Desc: select default weapon & handle multiple muzzles}}
// Desc: select default weapon & handle multiple muzzles
[[if]] ([[count]] [[weapons]] [[player]] > 0) [[then]]
if (count weapons player > 0) then
{
{
[[private]] ['_type', '_muzzles'];
  private['_type', '_muzzles'];
 
_type = (([[weapons]] [[player]]) select 0);
  _type = ((weapons player) select 0);
{{cc|check for multiple muzzles (eg: GL)}}
  // check for multiple muzzles (eg: GL)
_muzzles = [[getArray]] ([[configFile]] >> "cfgWeapons" >> _type >> "muzzles");
  _muzzles = getArray(configFile >> "cfgWeapons" >> _type >> "muzzles");
 
[[if]] ([[count]] _muzzles > 1) [[then]]
  if (count _muzzles > 1) then
{
  {
[[player]] [[selectWeapon]] (_muzzles [[select]] 0);
    player selectWeapon (_muzzles select 0);
}
  }
[[else]]
  else
{
  {
[[player]] [[selectWeapon]] _type;
    player selectWeapon _type;
};
  };
};
};
</code>
</pre>
</dd>
 
<dt><dt>
<dt><dt>
<dd class="notedate">Posted on 22 Mar, 2010</dd>
<dd class="notedate">Posted on 22 Mar, 2010</dd>
<dt class="note">'''MaestrO.fr'''<dd class="note">
<dt class="note">[[User:MaestrO.fr|MaestrO.fr]]</dt>
<dd class="note">
Can be used with [[primaryWeapon]] to select the primary weapon.
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>
<code>[[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>


</dl>
_type = [[primaryWeapon]] [[player]];
{{cc|check for multiple muzzles (eg: GL)}}
_muzzles = [[getArray]] ([[configFile]] >> "cfgWeapons" >> _type >> "muzzles");


{{GameCategory|arma1|Scripting Commands}}
[[if]] ([[count]] _muzzles > 1) [[then]]
{
[[player]] [[selectWeapon]] (_muzzles [[select]] 0);
}
[[else]]
{
[[player]] [[selectWeapon]] _type;
};
};
</code>
</dd>


{{GameCategory|arma2|Scripting Commands}}
</dl>
{{GameCategory|arma3|Scripting Commands}}
{{GameCategory|tkoh|Scripting Commands}}

Revision as of 19:01, 12 June 2021

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

Examples

Example 1:
_soldier1 selectWeapon "LAWLauncher";
Example 2:
player selectWeapon "M203Muzzle";

Additional Information

See also:
fireforceWeaponFireprimaryWeaponhandgunWeaponsecondaryWeaponweaponsaction SwitchWeaponaction SwitchMagazine

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
Posted on 5 Aug, 2008
Dr_Eyeball
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; }; };
Posted on 22 Mar, 2010
MaestrO.fr
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; }; };