OnPlayerWeaponSwitch: Difference between revisions
Jump to navigation
Jump to search
m (Fix mistake) |
m ("Cancel effect" before "Example") |
||
Line 13: | Line 13: | ||
==Source== | ==Source== | ||
The [[event system#Event source|source]] of this event is the [[player]] that switched his weapon. | The [[event system#Event source|source]] of this event is the [[player]] that switched his weapon. | ||
==Cancel effect== | |||
If this event is [[Event system#Canceling|canceled]], then the player's weapon won't be switched. | |||
==Example== | ==Example== | ||
This example disables use of the minigun upon switch. It should be noted that this can be done more efficiently clientside. | This example disables use of the minigun upon switch. It should be noted that this can be done more efficiently clientside. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> |
Revision as of 15:57, 14 June 2023
This event is triggered whenever a player's equipped weapon slot changes. This means giveWeapon and takeWeapon will trigger this event if the equipped slot is forced to change.
Parameters
int previousWeaponID, int currentWeaponID
- previousWeaponID: An integer representing the weapon that was switched from.
- currentWeaponID: An integer representing the weapon that was switched to.
Source
The source of this event is the player that switched his weapon.
Cancel effect
If this event is canceled, then the player's weapon won't be switched.
Example
This example disables use of the minigun upon switch. It should be noted that this can be done more efficiently clientside.
WeaponID = { [31] = true, [36] = true, [38] = true, } --add an event handler for onPlayerWeaponSwitch addEventHandler ( 'onPlayerWeaponSwitch', getRootElement ( ), function ( previousWeaponID, currentWeaponID ) if ( WeaponID[currentWeaponID] ) then toggleControl ( source, 'fire', false ) --disable the fire button else toggleControl ( source, 'fire', true ) --enable it end 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