Question about picking up a weapon

Is there a way to let a player pick up a weapon without having him to walk over the weapon?
(Like calling the Equip hook with the weapon entity or something)

Thanks in advance.

Weapon entities (on the ground) are usually implemented by the gamemode itself. Are you asking specifically for DarkRP?

Nope, TTT.

What do you exactly mean by that?

Some gamemodes create a custom entity instead of an entity instance of the weapon itself.

Anyways, you can use

ply:PickupObject( ent )

Hope this helps.

That’s not what I need.

I need something like a function that I can call that makes a player pickup a weapon entity.

(Like in CS:GO - Press E to pickup …)

Sry for late bump

disable the default auto-pickup, use hittrace to see if a weapon_* entity is infront of the player, with a distance of X HU, and if so, check for the Use hook and do the desired thing there.

How would I disable the default auto-pickup and what do you mean by the desired thing?



then if its the wanted entity, simply do ply:Give(“desired weapon”), and afterwards call Entity:Remove() on the entity.

UPDATE: well i tried disabling AllowPlayerPickup, but apparently it disables pressing USE on the weapon_* entity afterwards.

I wrote a small bit of code a while ago for a gamemode I was working on that allowed the user to pick up a weapon with their use key (default: E):

function PickupWeapon( ply, key )
	if( key == IN_USE )then -- If the key they are pressing down is the use key.
		local tr = util.TraceLine( {
			start = ply:EyePos(),
			endpos = ply:EyePos() + ply:EyeAngles():Forward() * 64,
			filter = ply
		} ) -- Run a line trace up to 64 units in front of the players eye position.

		local ent = tr.Entity -- The entity at the end of the trace.
		if( IsValid( ent ) )then -- Check if there is actually an entity there.
			if( ent:GetClass() and string.sub( ent:GetClass(), 1, 6 ) == "weapon" )then -- Check if it is a weapon (well, if it has weapon in its entity name)
				if( !ply:HasWeapon( ent:GetClass() ) )then -- Checks if the player has the weapon already.
					ply:Give( ent:GetClass() ) -- Gives the player the weapon.
					ent:Remove() -- Removes the entity from the map.
hook.Add( "KeyPress", "PickupWeapon_KeyPress", PickupWeapon )

The problem is that I want to make this system to work in TTT.
I can’t understand how TTT does handle ammo in general.

The code should work as an addon, also when did ammo come into this?

well now an kinda off-topic response here

I did the same as you did before, lol, I am only strugging with disabling the walk-over pickup, and only allow +USE pickup.