Arma 3 Scripting

Command in Weapons

weaponState

Also available as Markdown and JSON, or read the original wiki page.

Description

Returns the given or currently selected weapon state for unit or vehicle. With #Syntax 2, if no optional arguments are present, currently selected weapon is queried.

Note

Arma 3: Since Arma 3 v1.70 this command has been improved and extended:

  • A vehicle's weapon query doesn't need a weapon operator provided the weapon or muzzle is specified in optional param. (keep in mind that by default a vehicle has no weapons selected)
  • Driver turret can now be accessed as well with turret path [-1].
  • Muzzle name is supported as well as weapon name. The command searches for weapon first, then if not found, muzzle is searched for.

Syntax

Syntax 1

weaponState unit

Parameters:

Returns: Array with [weapon, muzzle, firemode, magazine, ammoCount, roundReloadPhase, magazineReloadPhase]

Syntax 2

weaponState [vehicle, turretPath, weapon, muzzle, firemode]

Parameters:

Returns: Array with [weapon, muzzle, firemode, magazine, ammoCount, roundReloadPhase, magazineReloadPhase]

Syntax 3

since arma3 2.06

unit weaponState weaponOrMuzzle

Parameters:

Returns: Array with [weapon, muzzle, firemode, magazine, ammoCount, roundReloadPhase, magazineReloadPhase]

Examples

Example 1

_wsPlayer = weaponState player;                    // ["arifle_MXC_ACO_F","arifle_MXC_ACO_F","Single","30Rnd_65x39_caseless_mag",30,0,0]

Example 2

Query currently selected gunner weapon:

_wsVehicle = weaponState [_apc, [0]];            // ["autocannon_40mm_CTWS","HE","player","60Rnd_40mm_GPR_Tracer_Red_shells",60,0,0]

Example 3

_wsVehicle = weaponState [_apc, [0], "AP"];        // ["autocannon_40mm_CTWS","AP","player","40Rnd_40mm_APFSDS_Tracer_Red_shells",40,0,0]

Example 4

_wsPlayer = player weaponState "GL_3GL_F";        // ["arifle_MX_GL_ACO_F","GL_3GL_F","Single","1Rnd_HE_Grenade_shell",1,0,0]

See also

weapons · selectWeaponTurret · loadMagazine · magazinesTurret · weaponsTurret · weaponReloadingTime

Community notes

AgentRev

In the case of a GL rifle, if the rifle is currently in GL mode, syntax 3 will return the same result for either muzzle:

player selectWeapon "GL_3GL_F";
_state = player weaponState "arifle_MX_GL_ACO_F";    // ["arifle_MX_GL_ACO_F","GL_3GL_F","Single","1Rnd_HE_Grenade_shell",1,0,0]
_state = player weaponState "GL_3GL_F";                // ["arifle_MX_GL_ACO_F","GL_3GL_F","Single","1Rnd_HE_Grenade_shell",1,0,0]

In rifle mode, the result is different:

player selectWeapon "arifle_MX_GL_ACO_F";
_state = player weaponState "arifle_MX_GL_ACO_F";    // ["arifle_MX_GL_ACO_F","arifle_MX_GL_ACO_F","Single","30Rnd_65x39_caseless_mag",30,0,0]
_state = player weaponState "GL_3GL_F";                // ["arifle_MX_GL_ACO_F","GL_3GL_F","Single","1Rnd_HE_Grenade_shell",1,0,0]

Therefore, in order to gather all states of one multi-muzzle weapon, we have to do some masochistic stuff:

fn_getWeaponStates =
{
    params ["_unit", "_weapon"];
    private _origState = weaponState _unit select [0,3];
    private _muzzles = [_weapon] + (getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles") select { _x != "this" });
    private _states = [];

    {
        _unit selectWeapon _x;
        _states pushBack weaponState _unit;
    } forEach _muzzles;

    _unit selectWeapon _origState;
    _states;
};

private _result = [player, primaryWeapon player] call fn_getWeaponStates;
/*
    [
        ["arifle_MX_GL_ACO_F", "arifle_MX_GL_ACO_F", "Single", "30Rnd_65x39_caseless_mag", 30, 0, 0],
        ["arifle_MX_GL_ACO_F", "GL_3GL_F", "Single", "1Rnd_HE_Grenade_shell", 1, 0, 0]
    ]
*/