onClientPlayerWeaponSwitch | Multi Theft Auto: Wiki Skip to content

onClientPlayerWeaponSwitch

Client-side
Server-side
Shared

This event is triggered whenever the local 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 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

element: The source of this event is the player who switched their weapon (Local player only)

Canceling

If this event is canceled, then the weapon will not be switched.

Code Examples

client

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