How to get a player's last used weapon?

I need a method of getting a player’s last used weapon.

It’d be easy if there was a SwitchWeapons() hook, but there isn’t (at least, I can’t find anything)

I also thought about getting the weapons on their quickswitch, but I don’t know if that’s possible.

So… help?

Thank you.

If you’re trying to make the player swap their weapons when they press ‘q’ then all you need to do is create a keypress hook to ‘q’ and when it is called, simply run the console command ‘lastinv’ on them.

I’m trying to get the weapon object they last had out

Well, you could make a custom SWEP that on the holster call it sets some kind of networked variable to tell the server that the last weapon you were using was that one, and simply overwrite that variable when you holster another weapon.

That’d only work once though, for example if I went from SWEP->Shotgun->AR2, it’d only get the shotgun switch.

Thanks for the idea though

Inefficient method but works:

On player join, log the current weapon in a variable x
Just after that create a timer that runs every y seconds: if the weapon is not the same as the variable, change the variable to the new weapon.

I know it is very inefficient, but it’s the best i can do in my condition.

A foolproof solution is to use only scripted weapons. There are perfectly fine lua versions of the default weapons that you can use.

This is probably the only way I can see of doing it, so I guess it’ll have to be this. Thanks for the help