weaponState: Difference between revisions
Jump to navigation
Jump to search
(Note about how I hate myself) |
Lou Montana (talk | contribs) (Add default values) |
||
(11 intermediate revisions by 4 users not shown) | |||
Line 12: | Line 12: | ||
|gr1= Weapons | |gr1= Weapons | ||
|descr= Returns the given or currently selected weapon state for unit or vehicle. With | |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: | 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) | * 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. The command searches for weapon first, then if not found, muzzle is searched for. }} | * Muzzle name is supported as well as weapon name. The command searches for weapon first, then if not found, muzzle is searched for. | ||
}} | |||
|s1= [[weaponState]] unit | |s1= [[weaponState]] unit | ||
Line 22: | Line 25: | ||
|p1= unit: [[Object]] | |p1= unit: [[Object]] | ||
|r1= [[Array]] | |r1= [[Array]] in format [weapon, muzzle, firemode, magazine, ammoCount, roundReloadPhase, magazineReloadPhase], where: | ||
* weapon: [[String]] | * weapon: [[String]] | ||
* muzzle: [[String]] | * muzzle: [[String]] | ||
Line 33: | Line 36: | ||
|s2= [[weaponState]] [vehicle, turretPath, weapon, muzzle, firemode] | |s2= [[weaponState]] [vehicle, turretPath, weapon, muzzle, firemode] | ||
|p21= | |p21= vehicle: [[Object]] | ||
|p22= | |p22= turretPath: [[Array]] | ||
|p23= | |p23= weapon: [[String]] - (Optional, default {{hl|""}}) weapon or muzzle name | ||
|p23since= arma3 1.70 | |||
|p24= | |p24= muzzle: [[String]] - (Optional, default {{hl|""}}) muzzle name | ||
|p24since= arma3 | |p24since= arma3 2.08 | ||
|p25= | |p25= firemode: [[String]] - (Optional, default {{hl|""}}) firemode name | ||
|p25since= arma3 2.08 | |p25since= arma3 2.08 | ||
|r2= [[Array]] in format [weapon, muzzle, firemode, magazine, ammoCount, roundReloadPhase, magazineReloadPhase], where: | |||
|r2= [[Array]] | |||
* weapon: [[String]] | * weapon: [[String]] | ||
* muzzle: [[String]] | * muzzle: [[String]] | ||
Line 65: | Line 66: | ||
|p42= weaponOrMuzzle: [[String]] | |p42= weaponOrMuzzle: [[String]] | ||
|r3= [[Array]] | |r3= [[Array]] in format [weapon, muzzle, firemode, magazine, ammoCount, roundReloadPhase, magazineReloadPhase], where: | ||
* weapon: [[String]] | * weapon: [[String]] | ||
* muzzle: [[String]] | * muzzle: [[String]] | ||
Line 71: | Line 72: | ||
* magazine: [[String]] | * magazine: [[String]] | ||
* ammoCount: [[Number]] | * ammoCount: [[Number]] | ||
* roundReloadPhase: [[Number]] - current ammo round reload phase (see [[weaponReloadingTime]]) | * {{GVI|arma3|2.06|size= 0.75}} roundReloadPhase: [[Number]] - current ammo round reload phase (see [[weaponReloadingTime]]) | ||
* magazineReloadPhase: [[Number]] - current magazine reload phase from 1 to 0, 0 - reload complete. > 0 - reload in progress | * {{GVI|arma3|2.06|size= 0.75}} magazineReloadPhase: [[Number]] - current magazine reload phase from 1 to 0, 0 - reload complete. > 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]]. | |seealso= [[weapons]] [[selectWeaponTurret]] [[loadMagazine]] [[magazinesTurret]] [[weaponsTurret]] [[weaponReloadingTime]]. | ||
}} | }} | ||
Line 90: | Line 93: | ||
<sqf> | <sqf> | ||
player selectWeapon "GL_3GL_F"; | 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 "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"; | _state = player weaponState "GL_3GL_F"; // ["arifle_MX_GL_ACO_F","GL_3GL_F","Single","1Rnd_HE_Grenade_shell",1,0,0] | ||
</sqf> | </sqf> | ||
In rifle mode, the result is different: | In rifle mode, the result is different: | ||
<sqf> | <sqf> | ||
player selectWeapon "arifle_MX_GL_ACO_F"; | 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 "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"; | _state = player weaponState "GL_3GL_F"; // ["arifle_MX_GL_ACO_F","GL_3GL_F","Single","1Rnd_HE_Grenade_shell",1,0,0] | ||
</sqf> | </sqf> | ||
Therefore, in order to gather all states of one multi-muzzle weapon, we have do | Therefore, in order to gather all states of one multi-muzzle weapon, we have to do some masochistic stuff: | ||
<sqf> | <sqf> | ||
fn_getWeaponStates = | fn_getWeaponStates = | ||
{ | { | ||
params ["_unit", "_weapon"]; | params ["_unit", "_weapon"]; | ||
private | private _origState = weaponState _unit select [0,3]; | ||
private _muzzles = [_weapon] | private _muzzles = [_weapon] + (getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles") select { _x != "this" }); | ||
private _states = []; | private _states = []; | ||
Line 113: | Line 116: | ||
} forEach _muzzles; | } forEach _muzzles; | ||
_unit selectWeapon | _unit selectWeapon _origState; | ||
_states | _states; | ||
}; | }; | ||
private _result = [player, primaryWeapon player] call fn_getWeaponStates; | 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] | |||
/ | ] | ||
*/ | |||
</sqf> | </sqf> | ||
}} | }} |
Latest revision as of 22:29, 30 March 2024
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.
- 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 1.70
- weapon: String - (Optional, default "") weapon or muzzle name
- since 2.08
- muzzle: String - (Optional, default "") muzzle name
- since 2.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:
- 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:
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
- 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:
In rifle mode, the result is different: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] ] */