OnClientWeaponFire: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Added outdated template with link to onClientPlayerWeaponFire)
(New)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Outdated|use [[onClientPlayerWeaponFire]]}}


This event is triggered when a player fires a weapon near the local client.
Weapon creation event.
 
Called post firing so properties can be changed per shot
 
Source is the weapon that fired
 
Can be cancelled with cancelEvent to prevent the shot.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onClientWeaponFire ( int weapon, int ammo, int ammoInClip, float fX, float fY, float fZ, element hitElement )
onClientWeaponFire ( entity hitEntity, posX, posY, posZ, normalX, normalY, normalZ, int materialType, int lighting, int pieceHit )
- hitEntity the entity it will hit
- posX the position it will hit
- posY the position it will hit
- posZ the position it will hit
- normalX the normal it hit ( see processLineOfSight )
- normalY the normal it hit ( see processLineOfSight )
- normalZ the normal it hit ( see processLineOfSight )
- materialType the material type it hit ( see processLineOfSight )
- lighting the lighting of the entity it hit ( see processLineOfSight )
- pieceHit the piece of the entity it hit ( see processLineOfSight )
</syntaxhighlight>  
</syntaxhighlight>  
==Variables==
* The source of this event is the player which fired the gun.
*'''weapon''': An integer representing the weapon that was fired.
*'''ammo''': An integer representing the player's remaining ammo.
*'''ammoInClip''': An integer representing the player's remaining ammo in clip.
*'''fX''': A floating point value representing the x coordinate of the hit.
*'''fY''': A floating point value representing the y coordinate of the hit.
*'''fZ''': A floating point value representing the z coordinate of the hit.
*'''hitElement''': Returns the element hit. Value is nil if nothing was hit.


==Example==  
==Example==  
This example calls server events, when an object was hit, or the player shot at something with a special gun.
This example calls server events, when an object was hit, or the player shot at something with a special gun.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--add an event handler for onClientWeaponFire
addEventHandler ( "onClientWeaponFire", getRootElement (), "gunfire" )
function gunfire ( weapon, ammo, ammoInClip, fX, fY, fZ, hitElement )
        --something was hit?
if ( hitElement ~= nil ) then
  triggerServerEvent( "object_hit" , getLocalPlayer () , hitElement )
        end
        -- filters if the player himself shot the gun, and if its weapon 33
if source == getLocalPlayer () and weapon == 33 then
  triggerServerEvent( "teleport_me" , getLocalPlayer () , fX, fY, fZ  )
        end
end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Event_functions}}
{{Event_functions}}

Revision as of 22:46, 25 August 2012


Weapon creation event.

Called post firing so properties can be changed per shot

Source is the weapon that fired

Can be cancelled with cancelEvent to prevent the shot.

Syntax

onClientWeaponFire ( entity hitEntity, posX, posY, posZ, normalX, normalY, normalZ, int materialType, int lighting, int pieceHit )
 - hitEntity the entity it will hit
 - posX the position it will hit
 - posY the position it will hit
 - posZ the position it will hit
 - normalX the normal it hit ( see processLineOfSight )
 - normalY the normal it hit ( see processLineOfSight )
 - normalZ the normal it hit ( see processLineOfSight )
 - materialType the material type it hit ( see processLineOfSight )
 - lighting the lighting of the entity it hit ( see processLineOfSight )
 - pieceHit the piece of the entity it hit ( see processLineOfSight )

Example

This example calls server events, when an object was hit, or the player shot at something with a special gun.


See Also