Weapon Disable

I don’t really know where to put this thread, so I put it here.

Alright, you know how everyone saves your weapon in a weapontable, and then strip them when they are in some kinda vehicle/UI/something, where they don’t want the player to be able to shoot.
Wouldn’t it be better if there were something like **[Player.Lock

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Player.Lock)** but that disables ONLY weapon shooting?

[lua]function SWEP:PrimaryAttack()
if self.Owner.WeaponLocked then return end

end[/lua]

Throw that into your SWEP base. Obviously won’t work for HL2 default weapons, but for everything else, it’s fine - and you can just remake the HL2 weapons as SWEPs to make this affect them as well.

Well, I ain’t making any SWEP base. So you point out that I should remake all the HL2 weapons, and change all the bases of the custom weapons on my server, to be able to lock the owner’s weapon? No, it can’t be that hard for garry to code some WeaponFire hook.

**[Weapon.SetNextPrimaryFire

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Weapon.SetNextPrimaryFire)** and **[Weapon.SetNextPrimaryFire

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Weapon.SetNextPrimaryFire)** with a unnessessary long time like 999999

I don’t know why they say it’ll only work on scripted weapons, I’m fairly sure it works on anything. I can only remember that you have to set this every time in a think hook when using it on weapon_pistol though.

One way would be to remove all the ammo, but I wish there was a primaryattack gamemode function where you could ovewrite that…

The OP doesn’t want a work around, he is asking why doesn’t Garry implement a default function that does this.

You could store the ammo. Strip it, and then give it back.
Or, find a way to block the command, same way you would jump, crouch, or forward.

Like, BindPress hook or something?

That would be the same hack used to disable flashlights before there was a way to actually disable flashlights. People just put in impulse 102.

Thing is, the thing I really hate about the storing, stripping and retrieving is those popup thingies that comes on the righthand side of the screen, showing you’ve picked up a weapon, when you really haven’t.

My method works,
[lua]
function DisableEveryonesWeapons()
for k,v in pairs(player.GetAll()) do
for k2,v2 in pairs(v:GetWeapons()) do
v2:SetNextPrimaryFire(CurTime()+99999)
v2:SetNextSecondaryFire(CurTime()+99999)
end
end
end
hook.Add(“Think”, “DisableEveryonesWeapons”, DisableEveryonesWeapons)
[/lua]

Think? Really now?

That makes sure that the weapon is never reactivated, and pistol has to be set every (frame?) time because it resets and gets shootable again in my experiences with doing a holstering feature in a rp.

You can give a player ammo without that thing showing up.
[lua]
ply:GiveAmmo(999,“AR2”,true) --true makes the thing not appear.
[/lua]

[editline]12th February 2011[/editline]

Does that work on hl2 weapons? If so, awesome.

Yes it does, that’s what I’ve been trying to say all the time.