- Documentation
- Client events
- 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
onPlayerWeaponFireA 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.onClientPlayerHitAnother player's game reported a hit: adatatable with the target element number (target), damage (damage), weapon (w) and body part (bp).