# onClientPlayerWeaponFire (Client)

> Fired on this client after a player fires a shot, whether the local player or another one this client sees.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Event
- **Side**: Client
- **Category**: Peds
- **URL**: https://wiki.mymp.gg/en/onClientPlayerWeaponFire

## Syntax

```lua
addEventHandler("onClientPlayerWeaponFire", root, function(int weapon, int ammo, int ammoInClip, float hitX, hitY, hitZ, element|nil hitElement, float startX, startY, startZ) ... end)
```

## Handler parameters

| Name | Type | Description |
| --- | --- | --- |
| `weapon` | `int` | The weapon type, such as `22` for `PISTOL`. |
| `ammo` | `int` | The total ammo left after the shot. |
| `ammoInClip` | `int` | The ammo left in the clip after the shot. |
| `hitX, hitY, hitZ` | `float` | Where the shot hit or, if it hit nothing, the end of the weapon's range. For a shotgun, the first pellet. |
| `hitElement` | `element\|nil` | The element hit, or `nil` if the shot hit no element (the game's world is not an element). |
| `startX, startY, startZ` | `float` | Where the shot came from. |

## Source

The player who fired.

It covers instant-hit weapons only: melee weapons, projectiles (such as grenades), the flamethrower, the spray can and the camera do not fire it. It cannot be cancelled, since the shot has already happened.

The event arrives after the frame's simulation, so a handler can safely change the ped that fired, `killPedTask` included. Another player's shot is replayed on this client, so `hitX, hitY, hitZ` and `hitElement` say what it hit in the world this client sees, which can differ from what the shooter saw.

## Example

```lua
addEventHandler("onClientPlayerWeaponFire", localPlayer, function(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement)
    if hitElement and getElementType(hitElement) == "object" then
        print(weapon, ammoInClip, getElementHealth(hitElement))
    end
end)
```

### Coming from MTA

It exists for players only: MYMP has no `onClientPedWeaponFire`.

## See also

- [getPedWeapon (Client)](https://wiki.mymp.gg/en/getPedWeapon-client.md): Gets the weapon a ped or player is holding, as this client knows it.
- [giveWeapon (Server)](https://wiki.mymp.gg/en/giveWeapon.md): Gives a weapon with ammo to a ped or player.
- [onClientObjectDamage (Client)](https://wiki.mymp.gg/en/onClientObjectDamage.md): Fired on this client before an object takes damage. Cancelling the event prevents the damage.
- [setPedControlState (Client)](https://wiki.mymp.gg/en/setPedControlState.md): Presses or releases one of a ped's controls as if it were a key, for example to make it walk, jump or shoot.
