onClientPlayerWeaponFire
ClientEvent
Fired on this client after a player fires a shot, whether the local player or another one this client sees.
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
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 MTAIt exists for players only: MYMP has no
onClientPedWeaponFire.