{"name":"fireAtTarget","operator":null,"title":"fireAtTarget","type":"command","url":"https://community.bistudio.com/wiki/fireAtTarget","revid":369417,"updated":"2024-09-03T18:48:49Z","groups":["Unit Control","Weapons"],"status":"ok","replaced_by":[],"games":[{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Remotely forces a unit to fire the given weapon. See also BIS_fnc_fire.","syntaxes":[{"syntax":"sourceVehicle fireAtTarget [targetVehicle, weaponMuzzleName]","since":null,"effect":null,"exec":null,"params":[{"name":"sourceVehicle","type":"Object","optional":false,"default":null,"description":"source vehicle to fire from","types":["Object"],"since":null,"text":"sourceVehicle: Object - source vehicle to fire from"},{"name":"targetVehicle","type":"Object","optional":false,"default":null,"description":"target vehicle to fire at","types":["Object"],"since":null,"text":"targetVehicle: Object - target vehicle to fire at"},{"name":"weaponMuzzleName","type":"String","optional":true,"default":null,"description":"weapon muzzle classname, optional parameter","types":["String"],"since":null,"text":"weaponMuzzleName: String - (Optional) weapon muzzle classname, optional parameter"}],"returns":{"type":"Boolean","types":["Boolean"],"description":"true if fired, false if not","text":"Boolean - true if fired, false if not"},"form":"binary","operator":null,"left":{"text":"sourceVehicle","types":["Object"]},"right":{"text":"[targetVehicle, weaponMuzzleName]","types":["Array"]}}],"examples":[{"text":"```sqf\n_handle = this fireAtTarget [groundtarget1, \"HellfireLauncher\"];\n```","code":["_handle = this fireAtTarget [groundtarget1, \"HellfireLauncher\"];"]},{"text":"```sqf\n_handle = Igla_AA_pod_TK_EP1 fireAtTarget [_helicopter, currentWeapon Igla_AA_pod_TK_EP1];\n```","code":["_handle = Igla_AA_pod_TK_EP1 fireAtTarget [_helicopter, currentWeapon Igla_AA_pod_TK_EP1];"]},{"text":"```sqf\n_handle = Igla_AA_pod_TK_EP1 fireAtTarget [helicopter];\n```","code":["_handle = Igla_AA_pod_TK_EP1 fireAtTarget [helicopter];"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["fire","doFire","commandFire","canFire","forceWeaponFire","commandArtilleryFire","commandSuppressiveFire","doArtilleryFire","doSuppressiveFire","isManualFire","aimedAtTarget","BIS_fnc_fire"],"notes":[{"user":"Dwarden","date":"2010-09-16T08:17:00Z","text":"Most likely only for missiles and for interaction with player only."},{"user":"ffur2007slx2_5","date":"2014-04-08T16:50:00Z","text":"(Arma 3 1.14) Source vehicle is only limited to manned vehicle while any other types won’t be able to active fireAtTarget handle, e.g.\n\n```sqf\n_handle = _infantryUnit fireAtTarget [_infantryTarget, weapons _infantryUnit select 0];\n// false & no bullet shoot\n```\n\nTarget has no limitation and can be any object:\n\n```sqf\n_handle = (vehicle _veh) fireAtTarget [objNull, weapons (vehicle _veh) select 0];\n// true & a bullet shoot\n```\n\nHandle returns false if weapon class name is inaccurate, e.g.\n\n```sqf\n_handle = (vehicle _veh) fireAtTarget [ObjNull, \"UnknownWeapon\"];\n// false & no bullet shoot\n```\n\nHandle still returns true even though the vehicle is unavailable to shoot any bullet:\n\n```sqf\n_weapon = weapons (vehicle _veh) select 0;\n(vehicle _veh) setAmmo [_weapon, 0];\n_handle = (vehicle _veh) fireAtTarget [objNull, _weapon];\n// true & no bullet shoot\n```\n\n#### Difference\n\n| command | Source | Target | Behavior | Workaround templets |\n|---|---|---|---|---|\n| fire | Either unit or manned vehicle | N/A | Fired aiming at air for infantry rifle | Together with selectWeapon,<br>suggested to work with \"throw\",\"put\" weapon type<br>for infantry, or vehicle entity indeed. |\n| fireAtTarget | Manned vehicle only | Any object | Normal shoot, won’t aim at target automatically | ```sqf<br>_veh doWatch _target;<br>waitUntil { _veh aimedAtTarget [_target] > 0 };<br>_veh fireAtTarget [_target];<br>``` |\n| forceWeaponFire | Either unit or manned aircraft (weapon operator) | N/A | Normal shoot, can change fire mode | ```sqf<br>// e.g. unit won't shoot until he is facing the target<br>_unit doWatch _tar;<br>waitUntil {<br>    _dir = direction _unit;<br>    _relative = [_unit,_tar] call BIS_fnc_relativeDirTo;<br>    if (_dir == _relative) exitWith {<br>        _unit forceWeaponFire [currentWeapon _unit, \"single\"];<br>    };<br>    false<br>};<br>``` |\n| doFire | Unit only | Either unit or vehicle | automatic aiming and shooting | No special example. |\n| commandFire | Unit only | Either unit or vehicle | automatic aiming and shooting | No special example. |\n| action [\"UseWeapon\"] | Either unit or manned vehicle | N/A | unexpected behavior | N/A |"}],"categories":["Arma 2: Operation Arrowhead: New Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 3: Scripting Commands","Command Group: Unit Control","Command Group: Weapons","Introduced with Arma 2: Operation Arrowhead version 1.50","Scripting Commands","Take On Helicopters: Scripting Commands"]}