setWeaponTarget | Multi Theft Auto: Wiki Skip to content

setWeaponTarget

Client-side
Server-side
Shared
Needs checking

This function was partially migrated from the old wiki. Please review manually:

  • Missing section: Syntax (target an element)
  • Missing section: Syntax (target a position)
  • Missing section: Syntax (rotational target)

Pair: getWeaponTarget

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function sets the target of a custom weapon. There are 3 different targeting modes, which are explained below.

Note

Custom weapons fire targets with no recoil (so they never miss a shot). If you want a custom weapon to take into account recoil, you will have to script it by firing at fixed coordinates.

Syntax

setWeaponTarget ( )

Code Examples

client

This example creates a Uzi and a pedestrian in the center of the map when the resource which contains it starts and makes the weapon fire the new ped's head non-stop.

local function createWeaponFiringPedHead()
-- Create the weapon and set a flag of it
local weapon = createWeapon("uzi", 0, 0, 10)
setWeaponFlags(weapon, "instant_reload", true)
-- Set the weapon target to a ped and fire it forever
setWeaponTarget(weapon, createPed(8, 0, 0, 5), 8)
setWeaponState(weapon, "firing")
end
addEventHandler("onClientResourceStart", resourceRoot, createWeaponFiringPedHead)

See Also