OnPlayerWeaponFire: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(9 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
{{Server event}} | {{Server event}} | ||
__NOTOC__ | __NOTOC__ | ||
{{New feature/item|3. | {{New feature/item|3.0153|1.5.3|9921| | ||
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 works only with weapons which have enabled bullet sync.}} | {{Note|This event works only with weapons which have enabled bullet sync. See [[Weapons]] for more information. }} | ||
==Parameters== | ==Parameters== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 11: | Line 11: | ||
*'''weapon''': an [[int]] representing [[weapons|weapon]] used for making a shot. | *'''weapon''': an [[int]] representing [[weapons|weapon]] used for making a shot. | ||
*'''endX''', '''endY''', '''endZ''': [[float]] world coordinates representing an end point. | *'''endX''', '''endY''', '''endZ''': [[float]] world coordinates representing an end point. | ||
*'''hitElement''': an [[element]] which was hit by a shot. | *'''hitElement''': an [[element]] which was hit by a shot. Currently this can be only another [[player]]. '''Note: hitElement could be incorrect and should not be relied upon.''' | ||
*'''startX''', '''startY''', '''startZ''': [[float]] world coordinates representing the start of the bullet. Note: This is not the gun muzzle. | *'''startX''', '''startY''', '''startZ''': [[float]] world coordinates representing the start of the bullet. '''Note: This is not the gun muzzle.''' | ||
==Source== | |||
The [[event system#Event source|source]] of this event is the [[player]] who fired the weapon. | |||
==Example== | ==Example== | ||
This code creates explosions when the source players shoots. | |||
This code | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
addEventHandler ("onPlayerWeaponFire", root, | addEventHandler ("onPlayerWeaponFire", root, | ||
function (weapon, endX, endY, endZ, hitElement, startX, startY, startZ) | function (weapon, endX, endY, endZ, hitElement, startX, startY, startZ) | ||
createExplosion(endX, endY, endZ, 2, source); | |||
end | end | ||
) | ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{See also/Server event|Player events}} |
Latest revision as of 21:03, 17 November 2024
This event is called when a player fires a weapon. This does not trigger for projectiles, melee weapons, or camera.
Parameters
int weapon, float endX, float endY, float endZ, element hitElement, float startX, float startY, float startZ
- weapon: an int representing weapon used for making a shot.
- endX, endY, endZ: float world coordinates representing an end point.
- hitElement: an element which was hit by a shot. Currently this can be only another player. Note: hitElement could be incorrect and should not be relied upon.
- 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 player who fired the weapon.
Example
This code creates explosions when the source players shoots.
addEventHandler ("onPlayerWeaponFire", root, function (weapon, endX, endY, endZ, hitElement, startX, startY, startZ) createExplosion(endX, endY, endZ, 2, source); end )
See Also
Player events
- onPlayerACInfo
- onPlayerBan
- onPlayerChangeNick
- onPlayerChat
- onPlayerClick
- onPlayerCommand
- onPlayerConnect
- onPlayerContact
- onPlayerDamage
- onPlayerJoin
- onPlayerLogin
- onPlayerLogout
- onPlayerMarkerHit
- onPlayerMarkerLeave
- onPlayerModInfo
- onPlayerMute
- onPlayerNetworkStatus
- onPlayerPickupHit
- onPlayerPickupLeave
- onPlayerPickupUse
- onPlayerPrivateMessage
- onPlayerQuit
- onPlayerScreenShot
- onPlayerSpawn
- onPlayerStealthKill
- onPlayerTarget
- onPlayerUnmute
- onPlayerVehicleEnter
- onPlayerVehicleExit
- onPlayerVoiceStart
- onPlayerVoiceStop
- onPlayerWasted
- onPlayerWeaponFire
- onPlayerWeaponSwitch
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled