OnPlayerWeaponSwitch: Difference between revisions
Jump to navigation
Jump to search
m (Replace to predefined variables) |
(Fix example) |
||
(One intermediate revision by one other user not shown) | |||
Line 18: | Line 18: | ||
==Example== | ==Example== | ||
This example | This example allows you to disable shoot ability for certain weapons, it should be noted that it will be more efficient if done on client-side. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local | local weaponsToBlock = { | ||
[38] = true, -- minigun | |||
[38] = true, | |||
} | } | ||
function onPlayerWeaponSwitch(previousWeaponID, currentWeaponID) | |||
local blockFire = (not weaponsToBlock[currentWeaponID]) -- reverse bool, true/worthy will give us false, and false/unworthy will give us true | |||
toggleControl(source, "fire", blockFire) -- toggle player control to fire weapon | |||
end | |||
addEventHandler("onPlayerWeaponSwitch", root, onPlayerWeaponSwitch) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{See also/Server event|Player events}} | {{See also/Server event|Player events}} |
Latest revision as of 09:44, 16 November 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 allows you to disable shoot ability for certain weapons, it should be noted that it will be more efficient if done on client-side.
local weaponsToBlock = { [38] = true, -- minigun } function onPlayerWeaponSwitch(previousWeaponID, currentWeaponID) local blockFire = (not weaponsToBlock[currentWeaponID]) -- reverse bool, true/worthy will give us false, and false/unworthy will give us true toggleControl(source, "fire", blockFire) -- toggle player control to fire weapon end addEventHandler("onPlayerWeaponSwitch", root, onPlayerWeaponSwitch)
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