Prevent Weapon Switching When Weapon is Picked Up?

Im trying to make a swep that once the weapon is picked up, the player can’t switch to other weapons. They must first drop that weapon to switch to their other weapons.

Anyone know of this is possible? What’s the code?

I don’t know of any clean ways this can be done, but you can use the PlayerSwitchWeapon hook, which is called just after a weapon switch, to select the previous weapon if it was a certain class.

[lua]hook.Add(“PlayerSwitchWeapon”, “PreventWeaponSwitch”, function(ply, old)
–GAMEMODE:PlayerSwitchWeapon(ply, old) to override.
if !IsValid(old) || !IsValid(ply) then return end
local oc = old:GetClass()
if oc == “your_weapon_class” then ply:SelectWeapon(oc) end

You’d then enable AutoSwitchTo and disable AutoSwitchFrom in your SWEP information, so that the weapon is selected immediately after pickup.

function SWEP:Equip( pl )
  pl:SelectWeapon( self:GetClass( ) )

function SWEP:Holster( )
  self.Owner:GetViewModel( ):RemoveEffects( EF_NODRAW )
  return false

You’ll need to make the player drop the weapon on your own, but that should do the trick.

Ah cool. Thanks :smiley: