OnClientPlayerWeaponFire: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
This event is called when a player fires a weapon. This does not trigger for projectiles, melee weapons, or camera. | This event is called when a player fires a weapon. This does not trigger for projectiles, melee weapons, or camera. | ||
{{Note|This event is only triggered for players that are streamed in}} | {{Note|This event is only triggered for players that are streamed in}} | ||
{{Note|This does not trigger for projectiles, melee weapons, or camera.}} | |||
==Parameters== | ==Parameters== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> |
Revision as of 10:28, 1 July 2018
This event is called when a player fires a weapon. This does not trigger for projectiles, melee weapons, or camera.
Note: This event is only triggered for players that are streamed in |
Note: This does not trigger for projectiles, melee weapons, or camera. |
Parameters
int weapon, int ammo, int ammoInClip, float hitX, float hitY, float hitZ, element hitElement, float startX, float startY, float startZ
- weapon: an int representing weapon used for making a shot.
- ammo: an int amount of ammo left for this weapon type.
- ammoInClip: an int amount 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.
- startX, startY, startZ: float world coordinates representing the start of the bullet. Note: This is not the gun muzzle.
Source
The source of this event is the streamed in player who fired the weapon.
Example
This example sends a warning to the local player if they shoot another player with a minigun.
--First, we create a function for the event handler to use. function onClientPlayerWeaponFireFunc(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement ) if weapon == 38 and getElementType(hitElement)=="player" then -- If the player shoots with a minigun, and hits another player... outputChatBox ( "Don't kill people with minigun, it's lame!", 255, 0, 0 ) -- We output a warning to him. end end -- Add this as a handler so that the function will be triggered every time the local player fires. addEventHandler ( "onClientPlayerWeaponFire", getLocalPlayer(), onClientPlayerWeaponFireFunc )
This example makes the Shotgun fire explosive rounds.
function onClientPlayerWeaponFireFunc(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) if (weapon == 25) then -- If the player shoots with a shotgun createExplosion(hitX, hitY, hitZ, 12, true, 0, true) -- Creates a tiny explosion where the bullet hit. end end -- Add this as a handler so that the function will be triggered every time a player fires. addEventHandler("onClientPlayerWeaponFire", root, onClientPlayerWeaponFireFunc)
Issues
Issue ID | Description |
---|---|
#7459 | [Fixed in 1.3.1-4916] onClientPlayerWeaponFire hitElement being nil sometimes with shotgun |
See Also
Client player events
- onClientPlayerChangeNick
- onClientPlayerChoke
- onClientPlayerDamage
- onClientPlayerHeliKilled
- onClientPlayerHitByWaterCannon
- onClientPlayerJoin
- onClientPlayerPickupHit
- onClientPlayerPickupLeave
- onClientPlayerQuit
- onClientPlayerRadioSwitch
- onClientPlayerSpawn
- onClientPlayerStealthKill
- onClientPlayerStuntFinish
- onClientPlayerStuntStart
- onClientPlayerTarget
- onClientPlayerVehicleEnter
- onClientPlayerVehicleExit
- onClientPlayerVoicePause
- onClientPlayerVoiceResumed
- onClientPlayerVoiceStart
- onClientPlayerVoiceStop
- onClientPlayerWasted
- onClientPlayerWeaponFire
- onClientPlayerWeaponSwitch
Client event functions
Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled