OnDrop hook does nothing? (TTT)

Im trying to write a code that
-gives you a Pointshop item when you pickup weapons
-removes Pointshop items when you drop a weapon

Here is the code i wrote

local function getpickedupweapon(ply,wep)
	if ply:PS_HasItem(wep:GetClass()..'_ps') then
		return false
		return true
hook.Add('PlayerCanPickupWeapon', 'receive_pickedup_weapon', getpickedupweapon)

local function dropweaponremovesitem()
hook.Add('OnDrop', 'ins_dropwep_removes',dropweaponremovesitem)

The first part works just as i want it to, but droping the weapon does nothing (in this case it should print “hi” in the console)

I tried OnRemove/OnContextMenuOpen aswell, doesnt work either

No error code, no bugs, it just doesnt happen anything when you drop the weapon

Any idea for a fitting hook?

OnDrop is a SWEP hook (

SWEP:OnDrop). There is no gamemode hook for it.

So no way to track if players dropped a weapon?

[editline]25th October 2017[/editline]

The thing is I could add the code i want into EVERY weapon I have but, that would be like 150 or something, so I hoped there is a way to do this universally

Yeah, it’s unfortunately a missing feature. I made a request here for it: https://github.com/Facepunch/garrysmod-requests/issues/1037

You can call your own hook when

Player:DropWeapon is called.

[lua]local pmeta = debug.getregistry().Player
pmeta.oldGive = pmeta.oldGive or pmeta.Give

function pmeta:Give( weapon )
local newWeapon = pmeta:oldGive( weapon )

local oldDrop = weapon.OnDrop
newWeapon.OnDrop = function( weapon )
    hook.Call( "PlayerDroppedWeapon", GAMEMODE, weapon.Owner, weapon )
    oldDrop( weapon )


Hacky method, but should work. Detours SWEP:OnDrop with that function.

[lua]hook.Add( “PlayerDroppedWeapon”, “MessageDropWeapon”, function( player, weapon )
print( tostring( player ) … " dropped " … tostring( weapon ) )
end )[/lua]

[editline]26th October 2017[/editline]

Sorry, better explanation:

Detours Player:Give( weapon ) function so that once the weapon is given, it can retrieve that weapon. Then it works by Detouring that weapons SWEP:OnDrop() function with a hook.Call, it will still call the old SWEP:OnDrop() so you shouldn’t lose any functionality in any of your weapons OnDrop functions.

Using the PlayerDroppedWeapon hook, you can now do whatever you need to.

Oh god im sorry, I just found a simple way to do this
just put this in weapon_tttbase line 382 (SWEP:PreDrop())


Sorry for making you write a code if I just find the answer myself ._.

(Yes this does not work with weapons that are not based on weapon_tttbase I know ^^)