OnClientPlayerWeaponFire: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 1: Line 1:
{{Client event}}
__NOTOC__  
__NOTOC__  
This event is called when player shoots a weapon.
This event is called when player shoots a weapon.  This does not trigger for projectiles based, or melee weapons.


==Syntax==  
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onClientPlayerWeaponFire ( int weapon, int ammo, int ammoInClip, float hitX, float hitY, float hitZ, element hitElement )
int weapon, int ammo, int ammoInClip, float hitX, float hitY, float hitZ, element hitElement
</syntaxhighlight>  
</syntaxhighlight>  
==Parameters==
*'''weapon''':  an [[int]] representing [[weapons|weapon]] used for making a shot.
*'''weapon''':  an [[int]] representing [[weapons|weapon]] used for making a shot.
*'''ammo''': an [[int]] ammount of ammo left for this weapon type.
*'''ammo''': an [[int]] ammount of ammo left for this weapon type.
Line 16: Line 15:
==Source==
==Source==
The [[event system#Event source|source]] of this event is the player who fired the weapon.
The [[event system#Event source|source]] of this event is the player who fired the weapon.


==Example==  
==Example==  
Line 28: Line 26:
end
end
-- don't forget to add the onClientPlayerWeaponFireFunc function as a handler for onClientPlayerWeaponFire
-- don't forget to add the onClientPlayerWeaponFireFunc function as a handler for onClientPlayerWeaponFire
addEventHandler ( "onPlayerSpawn", getRootElement(), onClientPlayerWeaponFireFunc )
addEventHandler ( "onClientPlayerWeaponFire", getRootElement(), onClientPlayerWeaponFireFunc )
</syntaxhighlight>
</syntaxhighlight>

Revision as of 13:23, 22 October 2007

This event is called when player shoots a weapon. This does not trigger for projectiles based, or melee weapons.

Parameters

int weapon, int ammo, int ammoInClip, float hitX, float hitY, float hitZ, element hitElement
  • weapon: an int representing weapon used for making a shot.
  • ammo: an int ammount of ammo left for this weapon type.
  • ammoInClip: an int ammount of ammo left for this weapon type in clip.
  • hitX, hitY, hitZ: float world coordinates representing a hit point.
  • hitElement: an element which was hit by a shot.

Source

The source of this event is the player who fired the weapon.

Example

This example shows player a warning if he hits any other player with minigun.

-- trigger the event every time player shots
function onClientPlayerWeaponFireFunc(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement )
    if weapon == 38 and getElementType(hitElement)=="player" then -- if player shots from minigun and he hits another player...
         outputChatBox ( "Don't kill people with minigun, it's lame!", source ) -- then we output him a warning
    end
end
-- don't forget to add the onClientPlayerWeaponFireFunc function as a handler for onClientPlayerWeaponFire
addEventHandler ( "onClientPlayerWeaponFire", getRootElement(), onClientPlayerWeaponFireFunc )