OnClientPlayerWeaponSwitch: Difference between revisions
Jump to navigation
Jump to search
Dutchman101 (talk | contribs) m (clarify) |
Dutchman101 (talk | contribs) mNo edit summary |
||
Line 20: | Line 20: | ||
This example disables the use of aiming for the minigun. | This example disables the use of aiming for the minigun. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function disableMinigunOnSwitch ( prevSlot, | function disableMinigunOnSwitch(prevSlot, curSlot) | ||
if getPedWeapon( | if getPedWeapon(localPlayer, curSlot) == 38 then --if the switched weapon is the minigun | ||
toggleControl ( "aim_weapon", false ) --disable the aim button | toggleControl("aim_weapon", false) --disable the aim button | ||
else --if it isnt the minigun | else --if it isnt the minigun | ||
toggleControl ( "aim_weapon", true ) --renable the aim button | toggleControl("aim_weapon", true) --renable the aim button | ||
end | end | ||
end | end | ||
addEventHandler ( "onClientPlayerWeaponSwitch", localPlayer, disableMinigunOnSwitch ) | addEventHandler("onClientPlayerWeaponSwitch", localPlayer, disableMinigunOnSwitch) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 07:46, 1 March 2021
This event is triggered whenever the local player's equipped weapon slot changes. This means giveWeapon and takeWeapon will trigger this function if the equipped slot is forced to change.
Parameters
int previousWeaponSlot, int currentWeaponSlot
- previousWeaponSlot: An integer representing the previous weapon slot the player had before he switched.
- currentWeaponSlot: An integer representing the new weapon slot the player has after he switched.
Source
The source of this event is the player who changed his weapon. (Local player only)
Cancel effect
If this event is canceled, then the weapon will not be switched.
Example
This example disables the use of aiming for the minigun.
function disableMinigunOnSwitch(prevSlot, curSlot) if getPedWeapon(localPlayer, curSlot) == 38 then --if the switched weapon is the minigun toggleControl("aim_weapon", false) --disable the aim button else --if it isnt the minigun toggleControl("aim_weapon", true) --renable the aim button end end addEventHandler("onClientPlayerWeaponSwitch", localPlayer, disableMinigunOnSwitch)
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
- triggerLatentServerEvent
- triggerServerEvent
- Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled