OnClientWeaponFire: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
{{Client event}}
__NOTOC__  
__NOTOC__  


Weapon creation event.
This event will be triggered once a client fires his weapon.
 
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.


==Parameters==  
==Parameters==  
Line 23: Line 18:
*'''lighting:''' the lighting of the entity it hit ( see processLineOfSight )
*'''lighting:''' the lighting of the entity it hit ( see processLineOfSight )
*'''pieceHit:''' the piece of the entity it hit ( see processLineOfSight )
*'''pieceHit:''' the piece of the entity it hit ( see processLineOfSight )
==Source==
The [[event system#Event source|source]] of this event is the weapon that was fired.
==Cancel Effect==
If this event was [[Event system#Canceling|canceled]], then the show will be canceled.


==Example==  
==Example==  
This example calls server events, when an object was hit, or the player shot at something with a special gun.
This example prevents the player from firing a Deagle.
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function noDeagle(hitElement)
local weaponID = getElementModel(source)
-- Gets the ID of the weapon.
if weaponID == 24 then
-- If the weapon ID is of the Deagle's then cancel the event.
cancelEvent()
end
end
addEventHandler("onClientWeaponFire", getRootElement(), noDeagle)
-- Attach the event 'onClientWeaponFire' to the function.
</syntaxhighlight>
</syntaxhighlight>
</section>
==See Also==
===Client event functions===
{{Client_event_functions}}

Revision as of 15:35, 25 April 2013


This event will be triggered once a client fires his weapon.

Parameters

element hitElement, float posX,  float posY, float posZ, float normalX, float normalY, float normalZ, int materialType, int lighting, int pieceHit
  • hitElement: the element that was 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 )

Source

The source of this event is the weapon that was fired.

Cancel Effect

If this event was canceled, then the show will be canceled.

Example

This example prevents the player from firing a Deagle.

Click to collapse [-]
Client
function noDeagle(hitElement)
	local weaponID = getElementModel(source) 
	-- Gets the ID of the weapon.
	if weaponID == 24 then 
		-- If the weapon ID is of the Deagle's then cancel the event.
		cancelEvent() 
	end
end
addEventHandler("onClientWeaponFire", getRootElement(), noDeagle)
-- Attach the event 'onClientWeaponFire' to the function.

See Also

Client event functions