OnClientWeaponFire: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This event is triggered when a player switches weapons.
This event is triggered when a player fires a weapon near the local client.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onClientWeaponFire ( [[weapon]] weapon, int ammo, int ammoInClip, float fX, float fY, float fZ, [[element]] hitElement )
void onClientWeaponFire ( int weapon, int ammo, int ammoInClip, float fX, float fY, float fZ, element hitElement )
</syntaxhighlight>  
</syntaxhighlight>  


==Variables==
==Variables==
* The source of this event is (clientside) the player which fired the gun.
* The source of this event is the player which fired the gun.
*'''weapon''': An integer representing the weapon that was fired
*'''weapon''': An integer representing the weapon that was fired.
*'''ammo''': An integer representing the remaining ammo
*'''ammo''': An integer representing the player's remaining ammo.
*'''ammoInClip''': An integer representing the remaining ammo in clip
*'''ammoInClip''': An integer representing the player's remaining ammo in clip.
*'''fx fy fz''': The coordinates where the shot hit
*'''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.
*'''hitElement''': Returns the element hit. Value is nil if nothing was hit.


==Example==  
==Example==  

Revision as of 14:42, 21 March 2007

This event is triggered when a player fires a weapon near the local client.

Syntax

void onClientWeaponFire ( int weapon, int ammo, int ammoInClip, float fX, float fY, float fZ, element hitElement )

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

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

--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

See Also