weaponsInfo: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
No edit summary
 
(7 intermediate revisions by 3 users not shown)
Line 3: Line 3:
|game1= arma3
|game1= arma3
|version1= 2.10
|version1= 2.10
|branch= dev


|gr1= Weapons
|gr1= Weapons


|descr= Returns entitiy's weapons information including weapon index and firemode.
|descr= Returns entity's weapons information including weapon index and firemode.


|s1= unit [[weaponsInfo]] [weaponOrMuzzle, onlyLoaded]
|s1= unit [[weaponsInfo]] [weaponOrMuzzle, onlyLoaded]
Line 15: Line 14:
|p2= weaponOrMuzzle: [[String]] - name of the weapon or muzzle (returns whichever matches first) or "" to return all weapons
|p2= weaponOrMuzzle: [[String]] - name of the weapon or muzzle (returns whichever matches first) or "" to return all weapons


|p3= onlyLoaded (Optional): [[Boolean]] - [[true]] to return loaded weapons only. Default [[false]].
|p3= onlyLoaded: [[Boolean]] - (Optional, default [[false]]) [[true]] to return loaded weapons only


|r1= [[Array]] of [[Array]]s (or an empty []) - weapons information in format <nowiki>[</nowiki>[weaponIndex, isSelected, weaponName, muzzleName, firemode, magazineName, ammoCount], ...] where:
|r1= [[Array]] of [[Array]]s (or an empty []) - weapons information in format <nowiki>[</nowiki>[weaponIndex, isSelected, weaponName, muzzleName, firemode, magazineName, ammoCount, isPrimary], ...] where:
* weaponIndex: [[Number]] - internal weapon index (changes frequently) used with "SwitchWeapon" and "UseWeapon" [[action]]s
* weaponIndex: [[Number]] - internal weapon index (changes frequently) used with "SwitchWeapon" and "UseWeapon" [[action]]s
* isSelected: [[Boolean]] - [[true]] if this weapon is currently selected
* isSelected: [[Boolean]] - [[true]] if this weapon is currently selected
Line 25: Line 24:
* magazineName: [[String]] - name of the loaded magazine or ""
* magazineName: [[String]] - name of the loaded magazine or ""
* ammoCount: [[Number]] - magazine ammo count or -1
* ammoCount: [[Number]] - magazine ammo count or -1
* isPrimary: [[Boolean]] - [[true]] if this muzzle is considered primary by the engine (Since Arma 3 2.14)


|x1= Find weapon with FullAuto firemode and switch to it: <code>[[private]] _weapons = [[player]] [[weaponsInfo]] <nowiki>[</nowiki>[[currentMuzzle]] [[player]], [[true]]];
|x1= Find weapon with FullAuto firemode and switch to it: <sqf>
[[private]] _found = _weapons [[findIf]] { _x [[select]] 4 == "FullAuto" };
private _weapons = player weaponsInfo [currentMuzzle player, true];
[[if]] (_found > -1) [[then]] { [[action]] ["SwitchWeapon", [[player]], [[player]], _weapons [[select]] _found [[select]] 0] };</code>
private _found = _weapons findIf { _x select 4 == "FullAuto" };
if (_found > -1) then { action ["SwitchWeapon", player, player, _weapons select _found select 0] };
</sqf>


|seealso= [[weaponState]] [[weaponReloadingTime]]
|seealso= [[weaponState]] [[weaponReloadingTime]] [[action]]
}}
}}

Latest revision as of 10:07, 23 July 2023

Hover & click on the images for description

Description

Description:
Returns entity's weapons information including weapon index and firemode.
Groups:
Weapons

Syntax

Syntax:
unit weaponsInfo [weaponOrMuzzle, onlyLoaded]
Parameters:
unit: Object - person
weaponOrMuzzle: String - name of the weapon or muzzle (returns whichever matches first) or "" to return all weapons
onlyLoaded: Boolean - (Optional, default false) true to return loaded weapons only
Return Value:
Array of Arrays (or an empty []) - weapons information in format [[weaponIndex, isSelected, weaponName, muzzleName, firemode, magazineName, ammoCount, isPrimary], ...] where:
  • weaponIndex: Number - internal weapon index (changes frequently) used with "SwitchWeapon" and "UseWeapon" actions
  • isSelected: Boolean - true if this weapon is currently selected
  • weaponName: String - weapon name
  • muzzleName: String - muzzle name
  • firemode: String - firemode that is set for this 'weaponIndex'
  • magazineName: String - name of the loaded magazine or ""
  • ammoCount: Number - magazine ammo count or -1
  • isPrimary: Boolean - true if this muzzle is considered primary by the engine (Since Arma 3 2.14)

Examples

Example 1:
Find weapon with FullAuto firemode and switch to it:
private _weapons = player weaponsInfo [currentMuzzle player, true]; private _found = _weapons findIf { _x select 4 == "FullAuto" }; if (_found > -1) then { action ["SwitchWeapon", player, player, _weapons select _found select 0] };

Additional Information

See also:
weaponState weaponReloadingTime action

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