Issue with PlayerCanPickupWeapon and my script

Okay, I’ve ran into several issues on a script I’m making. It’s to replace the default picking up of weapons on Trouble in Terrorist Town, here’s what it currently looks like when you attempt to pick up a weapon when you already have one equipped in the slot.

The only issue with my script, is that to remove the default picking up of weapons when you walk over them, I have to return false in https://wiki.garrysmod.com/page/GM/PlayerCanPickupWeapon. I can’t think of a way to easily “pick” up weapons with E, I tried multiple ways. With returning false in PlayerCanPickupWeapon you can no longer use https://wiki.garrysmod.com/page/Player/Give. I was going to make it so when you press E, it removes the entity, you drop your current weapon in that slot and give the player the weapon with :Give(). Even if I can get that to work, the ammo would not be stored, so in theory, the player could pick up the weapon, drop the ammo, drop the weapon, pick it up again, drop ammo, etc. Since I’ll be using https://wiki.garrysmod.com/page/Player/Give to give them the weapon. Any ideas on how to correctly utilize my code?

Did you make a custom check in the CanPickUpWeapon that checks if the person has that weapon in their weapon invetory (so to speak, the scroll wheel shit) and returns false if they do or did you just return false?

*Edit

Post your hook code.

if weapon.isdropped then return false end

Replace isdropped with whatever variable is set on dropped weapons to identify them as dropped.

Why would I not want to be able to pick up dropped weapons?

Post you hook of your “dripped” weapons.

I’m currently not home, I will once I get home

And Fly, no, they can not pick up weapons they already have. That’s not my issue. My issue is, how can I make it so they can press E to pick up weapons, and not walking over it.

Make your hook false by deafult? Just force them to press E.
Find the hook in TTT that allows them to do that and remove it.

Something like this I believe:



hook.Add("PlayerCanPickupWeapon", "bullshit",
function(ply, wep)
     if not ply:KeyDown(IN_USE) then return false end
     -- Do not return anything by default or it'll break other hooks
end)


That would only make it so they can hold E and walk over the weapon to pick it up. If you can see from the image, they need to press E and it gives them the weapon, not walking over that. In theory, it’s a better way to choose the weapon you want out of a group of weapons. Not that they can pick up any weapon if they’re holding down E. Fly, I don’t believe you understand my question.

Then replace KeyDown with

Player:KeyPressed maybe? It should be true only on the tick when the key was actually pressed.

Dude, just set the hook to false.

–snip (El stupido <----)

Because you said that you’ll use Player.Give to give them the weapon.

I don’t think this guy knows what he wants. He says we wants player to not pick up certain weapons then all weapons then says he wants to be able to pick them up. Ffs

Fly, I don’t think you know how to basically read. The issue is not that I don’t want people to not be able to pick up weapons in all. If you straight up return it false, there is no way to pick up any sort of a weapon. I’m looking for a way to pick up the weapons the right way. I have tried setting a variable on the weapon when they click E on it so they can pick it up. Only issue with that, is that Traitor/Detective weapons do not properly work. You can’t buy them because it uses :Give I believe. When you return false :Give no longer works. The way I was using beforehand was using https://wiki.garrysmod.com/page/Player/PickupObject and setting the collision group of the weapon to word so it only collides with the world. It works great, but since I return false to anything without the variable, you can’t buy Traitor/Detective weapons.

On thr github it looks like they are using ENT:Touch, just find and remove those hooks.

Or if you want, even simpler, just create a var stored in the gun ent of the player64id as the key and the v is = true or false.

If the player press “E” on the gun then it sets his 64ID in the gun to true and allows it to be picked up and if he drops it or doesn’t press “E” on it to begin with, set it to false.

Then create your hook and everytime just check if the gun has the player ID set to true.

of course there is still the problem of the gun being abled to auto pick up as soon as it’s set to true so maybe just have your menu set it to true. (When he clicks “Ok” or whatever) instead of setting it to true when he presses “E”.

As I stated before, I have already done something such as that. The only issue is that Traitor and Detective weapons do not spawn from the menu. Everything else works fine.

Why can’t you make the T and D weapons spawn from the menu? And you haven’t stated doing anything like I said.

Even if I did not, your way wouldn’t matter. The only issue I’m having are credit bought weapons. I assume they use :Give

Nvm, I just re-read your post. So are you saying :Give() overall doesn’t work? For the credit weapons? Do you want the menu to work for T and D weapons so they can only buy it from your menu?