selectWeapon: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - "<code>([^ ]*)\[\[([a-zA-Z][a-zA-Z0-9_]+)\]\]([^ ]*)<\/code>" to "<code>$1$2$3</code>") |
Lou Montana (talk | contribs) m (Text replacement - "<sqf>([^↵][^<]*↵[^<]*)<\/sqf>" to "<sqf> $1 </sqf>") |
||
(24 intermediate revisions by the same user not shown) | |||
Line 34: | Line 34: | ||
|p1= unitName: [[Object]] | |p1= unitName: [[Object]] | ||
|p2= muzzleName: [[String]] - | |p2= muzzleName: [[String]] - name of the weapon or muzzle | ||
{{Feature|important|For weapons that have '''more than one muzzle''', you have to input the '''muzzleName''' and not the '''weaponName'''. | {{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 {{ofp}}, in most cases, both names are the same. But check. | ||
Line 49: | Line 49: | ||
|p21= unit: [[Object]] - person. This argument has to be [[local]], or it can be remote when executed on the [[isServer|server]] | |p21= unit: [[Object]] - person. This argument has to be [[local]], or it can be remote when executed on the [[isServer|server]] | ||
|p22= weapon: [[String]] - | |p22= weapon: [[String]] - name of the weapon, personal or vehicle's weapon (see [[weaponState]]) | ||
|p23= muzzle: [[String]] - | |p23= muzzle: [[String]] - name of the selected muzzle (see [[weaponState]]) | ||
|p24= firemode: [[String]] - | |p24= firemode: [[String]] - name of the firemode (see [[weaponState]]) | ||
|r2= [[Boolean]] or [[Nothing]] - [[true]] on success, [[false]] on failure, [[Nothing]] when the call to the command is dispatched over network | |r2= [[Boolean]] or [[Nothing]] - [[true]] on success, [[false]] on failure, [[Nothing]] when the call to the command is dispatched over network | ||
|x1= < | |x1= <sqf>_soldier1 selectWeapon "LAWLauncher";</sqf> | ||
|x2= < | |x2= <sqf>player selectWeapon "M203Muzzle";</sqf> | ||
|x3= < | |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]] | |seealso= [[fire]] [[forceWeaponFire]] [[primaryWeapon]] [[handgunWeapon]] [[secondaryWeapon]] [[weapons]] [[ArmA:_Actions#SWITCHWEAPON|action SwitchWeapon]] [[ArmA:_Actions#SWITCHMAGAZINE|action SwitchMagazine]] | ||
Line 71: | Line 71: | ||
|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> | |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 | SelectWeapon.sqf | ||
< | <sqf> | ||
// Desc: select default weapon & handle multiple muzzles | |||
if (count weapons player > 0) then | |||
{ | { | ||
private ['_type', '_muzzles']; | |||
_type = (( | _type = ((weapons player) select 0); | ||
// check for multiple muzzles (eg: GL) | |||
_muzzles = | _muzzles = getArray (configFile >> "cfgWeapons" >> _type >> "muzzles"); | ||
if (count _muzzles > 1) then | |||
{ | { | ||
player selectWeapon (_muzzles select 0); | |||
} | } | ||
else | |||
{ | { | ||
player selectWeapon _type; | |||
}; | }; | ||
}; | }; | ||
</ | </sqf> | ||
}} | }} | ||
Line 97: | Line 98: | ||
|text= Can be used with [[primaryWeapon]] to select the primary weapon. | |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) : | ||
< | <sqf> | ||
if ((primaryWeapon player) != "") then | |||
{ | { | ||
private ['_type', '_muzzles']; | |||
_type = | _type = primaryWeapon player; | ||
// check for multiple muzzles (eg: GL) | |||
_muzzles = | _muzzles = getArray (configFile >> "cfgWeapons" >> _type >> "muzzles"); | ||
if (count _muzzles > 1) then | |||
{ | { | ||
player selectWeapon (_muzzles select 0); | |||
} | } | ||
else | |||
{ | { | ||
player selectWeapon _type; | |||
}; | }; | ||
}; | }; | ||
</ | </sqf> | ||
}} | }} |
Latest revision as of 19:43, 3 September 2024
Description
- Description:
- Selects the given weapon.
- Groups:
- Weapons
Syntax
- Syntax:
- unitName selectWeapon muzzleName
- Parameters:
- unitName: Object
- muzzleName: String - name of the weapon or muzzle
- 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:
- Example 3:
Additional Information
- See also:
- fire forceWeaponFire primaryWeapon handgunWeapon secondaryWeapon weapons action SwitchWeapon action 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 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; }; };
- 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; }; };
Categories:
- Scripting Commands
- Introduced with Operation Flashpoint version 1.27
- Operation Flashpoint: New Scripting Commands
- Operation Flashpoint: Scripting Commands
- Operation Flashpoint: Elite: Scripting Commands
- ArmA: Armed Assault: Scripting Commands
- Arma 2: Scripting Commands
- Arma 2: Operation Arrowhead: Scripting Commands
- Take On Helicopters: Scripting Commands
- Arma 3: Scripting Commands
- Command Group: Weapons
- Scripting Commands: Global Effect