OnPlayerWeaponFire: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Server event}} __NOTOC__ {{New feature/item|3.0160|1.5.3|9921| This event is called when a player fires a weapon. This does not trigger for projectiles, melee weapons, or ...")
 
Line 18: Line 18:


{{See also/Server event|Player events}}
{{See also/Server event|Player events}}
<section name="Server" class="server" show="true">
This code outputs the information on debug screen when a player shoots.
<syntaxhighlight lang="lua">
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
)
</syntaxhighlight>
</section>

Revision as of 23:13, 11 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.

Example

Accessories-text-editor.png Script Example Missing Event OnPlayerWeaponFire needs a script example, help out by writing one.

Before submitting check out Editing Guidelines Script Examples.
-- TODO


See Also

Player events


Event functions



Click to collapse [-]
Server

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
)