OnClientWeaponFire: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
 
(8 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Client event}}
{{Client event}}
__NOTOC__  
__NOTOC__  
This event will be triggered once a client fires his weapon.
This event triggers when a [[Element/Weapon|custom weapon]] fires a shot.
 
{{Note|This event is '''ONLY''' for custom weapons that were created with [[createWeapon]], for regular weapons use [[onClientPlayerWeaponFire]].}}
{{Note|This event is only triggered for custom weapons that are streamed in}}
==Parameters==  
==Parameters==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element hitElement, float posX,  float posY, float posZ, float normalX, float normalY, float normalZ, int materialType, int lighting, int pieceHit
element hitElement, float posX,  float posY, float posZ, float normalX, float normalY, float normalZ, int materialType, float lighting, int pieceHit
</syntaxhighlight>
</syntaxhighlight>
*'''hitElement:''' the element that was hit
*'''hitElement:''' the element that was hit
Line 22: Line 23:


==Cancel Effect==
==Cancel Effect==
If this event was [[Event system#Canceling|canceled]], then the show will be canceled.
If this event was [[Event system#Canceling|canceled]], then the weapon will not fire.


==Example==  
==Example==  
This example prevents the player from firing a Deagle.
This example prevents player damage from custom weapons.
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function noDeagle()
function noDamageToPlayersFromCustomWeapons(target)
local weaponID = getElementModel(source)
    if target == localPlayer then
-- Gets the ID of the weapon.
        cancelEvent() -- If the weapon hit the player, cancel the shot
if weaponID == 24 then  
    end
-- If the weapon ID is of the Deagle's then cancel the event.
cancelEvent()
end
end
end
addEventHandler("onClientWeaponFire", getRootElement(), noDeagle)
addEventHandler("onClientWeaponFire", root, noDamageToPlayersFromCustomWeapons)</syntaxhighlight>
-- Attach the event 'onClientWeaponFire' to the function.
</syntaxhighlight>
</section>


==See Also==
==See Also==
===Client event functions===
===Client event functions===
{{Client_event_functions}}
{{Client_event_functions}}
[[hu:onClientWeaponFire]]

Latest revision as of 17:30, 12 April 2019

This event triggers when a custom weapon fires a shot.

[[{{{image}}}|link=|]] Note: This event is ONLY for custom weapons that were created with createWeapon, for regular weapons use onClientPlayerWeaponFire.
[[{{{image}}}|link=|]] Note: This event is only triggered for custom weapons that are streamed in

Parameters

element hitElement, float posX,  float posY, float posZ, float normalX, float normalY, float normalZ, int materialType, float 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 weapon will not fire.

Example

This example prevents player damage from custom weapons.

function noDamageToPlayersFromCustomWeapons(target)
    if target == localPlayer then
        cancelEvent() -- If the weapon hit the player, cancel the shot
    end
end
addEventHandler("onClientWeaponFire", root, noDamageToPlayersFromCustomWeapons)

See Also

Client event functions