Page tree
Skip to end of metadata
Go to start of metadata


Introduced in

Version:1.19

Description

Description:Forces a unit to fire the given weapon.

Note I: For vehicles, it is recommended to use the alternative syntax.
Unit needs to be equipped with the respective weapon and ammo, in order to fire.
The weapon also has to be selected, in order for the AI to use it (so, especially for secondary weapons, it may be necessary to execute selectWeapon first).
Note II (V17.1.0+): With UCS (see Universal Component System (UCS) in the VBS Developer Reference), weapon muzzles are no longer statically defined inside the CfgWeapons class. Instead, weapon muzzles can be changed in-game through component attachment. This is why you need to use the alternative syntax with UCS weapons and specify the correct muzzle for the fire command to work correctly.

Syntax

Syntax:unit fire weapon
Parameters:
  • unit: Unit - Unit which is supposed to fire.
  • weapon: String - Class name of the weapon to be fired.
Return Value:Nothing

Alternative Syntax

Syntax:unit fire [muzzle, mode, magazine, position, aimfirst]
Parameters:
  • unit: Unit - Unit which is supposed to fire.
  • muzzle: String - Name of muzzle to use when firing.
    If the weapon muzzle property is only defined as "this", then the weapon name should be used.
  • mode: String - Firing mode to use (available modes depend on the weapon used, check the modes[] parameter in the weapon class using the Configuration Browser for valid modes). If the weapon mode property is only defined as "this", then the weapon name should be used.
  • magazine: String - Class name of magazine to use. For secondary weapons, the weapon class can be used instead (optional).
  • position: PositionASL - Position to fire at (optional).
  • aimfirst: Boolean - Whether unit should aim first, before firing (optional, V1.31+).
Return Value:Nothing

Examples

Examples:
// Unit fires its M16 (in the default direction)
_soldier fire "M16";                                       

// Unit throws a smoke grenade
_soldier fire ["throw","SmokeShell","SmokeShell"];         

//Fires whatever weapon/ammo 'soldier1' currently has selected
soldier1 fire [(weaponstate soldier1) select 1, (weaponstate soldier1) select 2, (weaponstate soldier1) select 3]

// Select and fire a grenade launcher
soldier1 doWatch target1;                                                     // make sure AI looks at target
soldier1 selectWeapon "vbs2_rpg7";                                            // select the launcher
waitUntil {(soldier1 call fn_vbs_selectedWeaponType)=="SECONDARY"};           // wait until launcher is active
soldier1 fire ["vbs2_rpg7","vbs2_rpg7","vbs2_rpg7",getPosASL target1,false];  // fire at target
Mission to demonstrate use of fire command, to have a player or AI fire at a specific position: fireAtPosition.zip

Additional Information

See also: doFire, commandFire, playerForceFire, turretFire, createShot, suppressFor, commandSuppressiveFire, setFireOwner
Multiplayer:
Problems:
  • If target position is closer than 2m, AI will not shoot, and player will be stuck in an animation jitter. (V1.40+)
  • The "aimfirst" property seems to work in reverse: If true, then the unit will not aim at all, and either fire in the current direction the weapon is pointing (player), or straight ahead of him (AI). If set to false (or not set at all), player or AI will first aim, and then shoot at the specified position. (V1.40+).
    It may still be necessary to first align the unit with the target, in order to it to shoot. This can be done by either explicitly setting its direction (via setDir), or by letting it watch the target (via doWatch).

Notes







20:20, 25 Aug 2009
Kronzky
If the fire command is applied to a vehicle, it should be issue to the vehicle itself, rather than the gunner.