ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Client events
  3. onClientPlayerWeaponFire

Event

onClientPlayerWeaponFire

A player fired a firearm: you or another nearby player whose shots are shown in your game. It arrives once per bullet, with the muzzle point and the hit point. The game collects shots only while some script listens to this event.

Handler

addEventHandler("onClientPlayerWeaponFire", 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 startX, float startY, float startZ

In MTA:SA

function(int weapon, int ammo, int ammoInClip, float hitX, float hitY, float hitZ, element hitElement, float startX, float startY, float startZ)

Source

source is the player who fired.

Example

addEventHandler("onClientPlayerWeaponFire", root, function(weapon, ex, ey, ez, sx, sy, sz)
    if source ~= localPlayer then
        local d = getDistanceBetweenPoints3D(sx, sy, sz, getElementPosition(localPlayer))
        outputChatBox(("%s strzela %.0f m od Ciebie"):format(getPlayerName(source), d))
    end
end)

Notes

Instant-hit weapons only. Weapons 22-34 and the minigun (38). Shots of far-away players do not arrive, because your game does not show them.

See also