onClientPlayerWeaponFire | Multi Theft Auto: Wiki Skip to content

onClientPlayerWeaponFire

Client-side
Server-side
Shared

This event is called when a player fires a weapon. This event does not trigger for melee weapons. Projectile weapons or the camera will only trigger the event if fired by the local player.

This event is only triggered for players that are streamed in

This does not trigger for any player's melee weapons or for remote player's projectile weapons or cameras

Parameters

int weapon, int ammo, int ammoInClip, float hitX, float hitY, float hitZ, element hitElement, float startX, float startY, float startZ
  • weapon: an int representing weapon used for firing a shot.
  • ammo: an int amount of ammo left for this weapon type.
  • ammoInClip: an int amount of ammo left for this weapon type in clip.
  • hitX: float world X coordinate representing the hit point.
  • hitY: float world Y coordinate representing the hit point.
  • hitZ: float world Z coordinate representing the hit point.
  • hitElement: an element which was hit by a shot.
  • startX: float world X coordinate representing the start of the bullet. Note: This is not the gun muzzle.
  • startY: float world Y coordinate representing the start of the bullet.
  • startZ: float world Z coordinate representing the start of the bullet.

Source

element: The source of this event is the streamed in player who fired the weapon.

Code Examples

client

This example implements custom gunshot sounds.

function playGunfireSound(weaponID)
local muzzleX, muzzleY, muzzleZ = getPedWeaponMuzzlePosition(source)
local dim = getElementDimension(source)
local int = getElementInterior(source)
setAmbientSoundEnabled ("gunfire", false)
local weaponSounds = {
[22] = "sounds/weap/colt45.ogg",
[23] = "sounds/weap/silenced.ogg",
[24] = "sounds/weap/deagle.ogg",
[25] = "sounds/weap/shotgun.ogg",
[26] = "sounds/weap/sawed-off.ogg",
[27] = "sounds/weap/combat shotgun.ogg",
[28] = "sounds/weap/uzi.ogg",
[30] = "sounds/weap/ak-47.ogg",
[31] = "sounds/weap/m4.ogg",
[32] = "sounds/weap/tec9.ogg",
[34] = "sounds/weap/sniper.ogg",
}
if weaponSounds[weaponID] then
sound = playSound3D(weaponSounds[weaponID], muzzleX, muzzleY, muzzleZ)
setSoundMaxDistance(sound, 90)
setElementDimension(sound, dim)
setElementInterior(sound, int)
setSoundVolume(sound, 0.6)
end
end
addEventHandler("onClientPlayerWeaponFire", root, playGunfireSound)

See Also