Difference between revisions of "OnPlayerWeaponFire"

From Multi Theft Auto: Wiki
m (fix version)
(The source of this event is the player who fired the weapon.)
Line 13: Line 13:
 
*'''hitElement''': an [[element]] which was hit by a shot.
 
*'''hitElement''': an [[element]] which was hit by a shot.
 
*'''startX''', '''startY''', '''startZ''': [[float]] world coordinates representing the start of the bullet. Note: This is not the gun muzzle.
 
*'''startX''', '''startY''', '''startZ''': [[float]] world coordinates representing the start of the bullet. Note: This is not the gun muzzle.
 +
 +
==Source==
 +
The [[event system#Event source|source]] of this event is the [[player]] who fired the weapon.
  
 
==Example==
 
==Example==

Revision as of 23:40, 25 October 2016

This event is called when a player fires a weapon. This does not trigger for projectiles, melee weapons, or camera.

[[{{{image}}}|link=]] Note: This event works only with weapons which have enabled bullet sync.

Parameters

int weapon, float endX, float endY, float endZ, element hitElement, float startX, float startY, float startZ
  • weapon: an int representing weapon used for making a shot.
  • endX, endY, endZ: float world coordinates representing an end point.
  • hitElement: an element which was hit by a shot.
  • startX, startY, startZ: float world coordinates representing the start of the bullet. Note: This is not the gun muzzle.

Source

The source of this event is the player who fired the weapon.

Example

This code outputs the information on debug screen when a player shoots.

addEventHandler ("onPlayerWeaponFire", root, 
   function (weapon, endX, endY, endZ, hitElement, startX, startY, startZ)
       iprint (getPlayerName(source).. " just shot a " .. getElementType (hitElement) .. " at X: ".. endX .. " Y: " .. endY .. " Z: " .. endZ .. " from X: " .. startX .. " Y: ".. startY .. " Z: " .. startZ .. " with a ".. getWeaponNameFromID (weapon))
   end
)

See Also

Player events

Event functions