weaponState: Difference between revisions

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


| arma2oa |= Game name
|game1= arma2oa
|version1= 1.60


|1.60|= Game version
|game2= tkoh
____________________________________________________________________________________________
|version2= 1.00


| Returns the currently selected weapon state for unit or vehicle.  
|game3= arma3
<br><br>Since Arma 3 v1.69.140397 this command has been improved and extended:
|version3= 0.50
* It is now possible to query any weapon of a vehicle without the need to place a weapon operator first, provided the weapon or muzzle is specified in optional param. By default a vehicle has no weapons selected, so querying currently selected weapon returns no weapon, unless weapon is specified.
 
|gr1= Weapons
 
|descr= Returns the given or currently selected weapon state for unit or vehicle.
With {{Link|#Syntax 2}}, if no optional arguments are present, currently selected weapon is queried.
{{Feature|arma3|
Since {{arma3}} 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.<br>(keep in mind that by default a vehicle has no weapons selected)
* Driver turret can now be accessed as well with turret path [-1].
* Driver turret can now be accessed as well with turret path [-1].
* Muzzle name is supported as well as weapon name. Weapon search gets priority, but if there is no weapon with given name, the muzzles will be searched. |= Description
* Muzzle name is supported as well as weapon name. The command searches for weapon first, then if not found, muzzle is searched for.
____________________________________________________________________________________________
}}


| '''weaponState''' unit |= Syntax
|s1= [[weaponState]] unit


|p1= unit: [[Object]] |= Parameter 1
|p1= unit: [[Object]]


| [[Array]] - in format [weapon, muzzle, firemode, magazine, ammoCount], where:
|r1= [[Array]] in format [weapon, muzzle, firemode, magazine, ammoCount, roundReloadPhase, magazineReloadPhase], where:
* weapon: [[String]]
* weapon: [[String]]
* muzzle: [[String]]
* muzzle: [[String]]
* firemode: [[String]]
* firemode: [[String]]
* magazine: [[String]]
* magazine: [[String]]
* ammoCount: [[Number]] |= Return value
* ammoCount: [[Number]]
____________________________________________________________________________________________
* {{GVI|arma3|2.06|size= 0.75}} roundReloadPhase: [[Number]] - current ammo round reload phase (see [[weaponReloadingTime]])
* {{GVI|arma3|2.06|size= 0.75}} magazineReloadPhase: [[Number]] - current magazine reload phase from 1 to 0, 0 - reload complete. &gt; 0 - reload in progress
 
|s2= [[weaponState]] [vehicle, turretPath, weapon, muzzle, firemode]
 
|p21= vehicle: [[Object]]
 
|p22= turretPath: [[Array]]


|s2= '''weaponState''' [vehicle, turretPath, weapon] |= Syntax
|p23= weapon: [[String]] - (Optional, default {{hl|""}}) weapon or muzzle name
|p23since= arma3 1.70


|p21 =  [vehicle, turretPath, weapon]: [[Array]] |=
|p24= muzzle: [[String]] - (Optional, default {{hl|""}}) muzzle name
|p22= vehicle: [[Object]] |= Parameter 1
|p24since= arma3 2.08
|p23= turretPath: [[Array]] |= Parameter 2
|p24= weapon (Optional): [[String]] (since Arma 3 v1.69.140397) - weapon or muzzle name |=


|r2= [[Array]] - in format [weapon, muzzle, firemode, magazine, ammoCount], where:
|p25= firemode: [[String]] - (Optional, default {{hl|""}}) firemode name
|p25since= arma3 2.08
 
|r2= [[Array]] in format [weapon, muzzle, firemode, magazine, ammoCount, roundReloadPhase, magazineReloadPhase], where:
* weapon: [[String]]
* weapon: [[String]]
* muzzle: [[String]]
* muzzle: [[String]]
* firemode: [[String]]
* firemode: [[String]]
* magazine: [[String]]
* magazine: [[String]]
* ammoCount: [[Number]] |= Return value
* ammoCount: [[Number]]
____________________________________________________________________________________________
* {{GVI|arma3|2.06|size= 0.75}} roundReloadPhase: [[Number]] - current ammo round reload phase (see [[weaponReloadingTime]])
* {{GVI|arma3|2.06|size= 0.75}} magazineReloadPhase: [[Number]] - current magazine reload phase from 1 to 0, 0 - reload complete. &gt; 0 - reload in progress


|x1= <code>_wsPlayer = [[weaponState]] [[player]]; // ["arifle_MXC_ACO_F","arifle_MXC_ACO_F","Single","30Rnd_65x39_caseless_mag",30]</code>|= EXAMPLE1
|s3= unit [[weaponState]] weaponOrMuzzle
|x2= <code>_wsVehicle = [[weaponState]] [_apc, [0]]; // ["autocannon_40mm_CTWS","HE","player","60Rnd_40mm_GPR_Tracer_Red_shells",60]</code>|= EXAMPLE2
|x3= <code>_wsVehicle = [[weaponState]] [_apc, [0], "AP"]; // ["autocannon_40mm_CTWS","AP","player","40Rnd_40mm_APFSDS_Tracer_Red_shells",40]</code>|= EXAMPLE3
____________________________________________________________________________________________


| [[weapons]], [[selectWeaponTurret]], [[loadMagazine]], [[magazinesTurret]], [[weaponsTurret]] |= SEEALSO
|s3since= arma3 2.06


| |= MPBEHAVIOUR
|p41= unit: [[Object]]
____________________________________________________________________________________________


|p42= weaponOrMuzzle: [[String]]
|r3= [[Array]] in format [weapon, muzzle, firemode, magazine, ammoCount, roundReloadPhase, magazineReloadPhase], where:
* weapon: [[String]]
* muzzle: [[String]]
* firemode: [[String]]
* magazine: [[String]]
* ammoCount: [[Number]]
* {{GVI|arma3|2.06|size= 0.75}} roundReloadPhase: [[Number]] - current ammo round reload phase (see [[weaponReloadingTime]])
* {{GVI|arma3|2.06|size= 0.75}} magazineReloadPhase: [[Number]] - current magazine reload phase from 1 to 0, 0 - reload complete. &gt; 0 - reload in progress
|x1= <sqf>_wsPlayer = weaponState player; // ["arifle_MXC_ACO_F","arifle_MXC_ACO_F","Single","30Rnd_65x39_caseless_mag",30,0,0]</sqf>
|x2= Query currently selected gunner weapon:
<sqf>_wsVehicle = weaponState [_apc, [0]]; // ["autocannon_40mm_CTWS","HE","player","60Rnd_40mm_GPR_Tracer_Red_shells",60,0,0]</sqf>
|x3= <sqf>_wsVehicle = weaponState [_apc, [0], "AP"]; // ["autocannon_40mm_CTWS","AP","player","40Rnd_40mm_APFSDS_Tracer_Red_shells",40,0,0]</sqf>
|x4= <sqf>_wsPlayer = player weaponState "GL_3GL_F"; // ["arifle_MX_GL_ACO_F","GL_3GL_F","Single","1Rnd_HE_Grenade_shell",1,0,0]</sqf>
|seealso= [[weapons]] [[selectWeaponTurret]] [[loadMagazine]] [[magazinesTurret]] [[weaponsTurret]] [[weaponReloadingTime]].
}}
}}


<h3 style='display:none'>Notes</h3>
{{Note
<dl class='command_description'>
|user= AgentRev
</dl>
|timestamp= 20220331040809
|text= 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:
<sqf>
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]
</sqf>
In rifle mode, the result is different:
<sqf>
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]
</sqf>
Therefore, in order to gather all states of one multi-muzzle weapon, we have to do some masochistic stuff:
<sqf>
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;


<h3 style='display:none'>Bottom Section</h3>
_unit selectWeapon _origState;
_states;
};


[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
private _result = [player, primaryWeapon player] call fn_getWeaponStates;
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
/*
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
["arifle_MX_GL_ACO_F", "arifle_MX_GL_ACO_F", "Single", "30Rnd_65x39_caseless_mag", 30, 0, 0],
[[Category:ArmA 2 OA: New Scripting Commands List|{{uc:{{PAGENAME}}}}]]
["arifle_MX_GL_ACO_F", "GL_3GL_F", "Single", "1Rnd_HE_Grenade_shell", 1, 0, 0]
]
*/
</sqf>
}}

Latest revision as of 23:29, 30 March 2024

Hover & click on the images for description

Description

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.
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.
Groups:
Weapons

Syntax 1

Syntax:
weaponState unit
Parameters:
unit: Object
Return Value:
Array in format [weapon, muzzle, firemode, magazine, ammoCount, roundReloadPhase, magazineReloadPhase], where:

Syntax 2

Syntax:
weaponState [vehicle, turretPath, weapon, muzzle, firemode]
Parameters:
vehicle: Object
turretPath: Array
since Arma 3 logo black.png1.70
weapon: String - (Optional, default "") weapon or muzzle name
since Arma 3 logo black.png2.08
muzzle: String - (Optional, default "") muzzle name
since Arma 3 logo black.png2.08
firemode: String - (Optional, default "") firemode name
Return Value:
Array in format [weapon, muzzle, firemode, magazine, ammoCount, roundReloadPhase, magazineReloadPhase], where:

Syntax 3

Syntax:
unit weaponState weaponOrMuzzle
Parameters:
unit: Object
weaponOrMuzzle: String
Return Value:
Array in format [weapon, muzzle, firemode, magazine, ammoCount, roundReloadPhase, magazineReloadPhase], where:

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]

Additional Information

See also:
weapons selectWeaponTurret loadMagazine magazinesTurret weaponsTurret weaponReloadingTime.

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
AgentRev - c
Posted on Mar 31, 2022 - 04:08 (UTC)
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] ] */