ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Server events
  3. onPlayerWeaponFire

Event

onPlayerWeaponFire

A player fired a firearm. It arrives once per bullet, with the point the shot came from and the point it hit (a wall, the ground, a ped or the end of the range). The game reports shots only while some resource listens to this event, so it costs nothing without a listener.

Handler

addEventHandler("onPlayerWeaponFire", root, function(weapon, endX, endY, endZ, startX, startY, startZ) ... end)

Parameters

weaponint
Weapon number.
endX, endY, endZfloat
The point the bullet hit.
startX, startY, startZfloat
The muzzle position.Different type in MTA:SA: element hitElement

Differences from MTA:SA

  • Parameters in a different colour differ from MTA:SA.
  • These MTA:SA parameters are not here: float startZ

In MTA:SA

function(int weaponID, float endX, float endY, float endZ, element hitElement, float startX, float startY, float startZ)

Source

source is the player who fired.

Example

addEventHandler("onPlayerWeaponFire", root, function(weapon, ex, ey, ez, sx, sy, sz)
    local dist = getDistanceBetweenPoints3D(sx, sy, sz, ex, ey, ez)
    outputServerLog(("%s strzela z %d na %.1f m"):format(getPlayerName(source), weapon, dist))
end)

Notes

Instant-hit weapons only. Pistols, shotguns, SMGs, rifles, snipers (22-34) and the minigun (38). Grenades, rockets and the flamethrower do not trigger the event.

See also