New Hand Swep problem

I salvaged some code from an old and buggy hands swep i found at

to make my own and learn something.

My biggest problem right now is that the prop one is holding is not colliding with anything. If you pick it up, you can drop it out of world easily or into other props.
I reckon it’s because i just set the position and angles in a no-compromise way thus forcing it to stay at the position even if it collides with something, i just cant figure out another way to do it.

The second, minor issue is, that I need a filter for what one can pickup, usually i would do this by



if (tr.Entity:GetClass()=="prop_physics)" then
--pick it up
end


For some reason that just doesnt work. I have to exclude every single type of prop or entity to deny pickup.



if (tr.Entity:GetClass()=="func_door_rotating" || tr.Entity:GetClass()=="func_door" || tr.Entity:GetClass()=="prop_dynamic" || tr.Entity:GetClass()=="prop_static")" then
--pick it up
end


Here’s the full code:



--Hands
if (SERVER) then
	AddCSLuaFile( "shared.lua" )
	SWEP.Weight				= 5
	SWEP.AutoSwitchTo		= false
	SWEP.AutoSwitchFrom		= false
end

if ( CLIENT ) then
	SWEP.Author			= "ProudOne"
	SWEP.Contact		= ""
	SWEP.Purpose		= ""
	SWEP.Instructions	= "Primary picks things up, puts them down, or punches people in their faces, secondary throws things away."
end
 
SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true

SWEP.ViewModel			= ""
SWEP.WorldModel			= ""

SWEP.Primary.ClipSize		= -1
SWEP.Primary.DefaultClip	= -1
SWEP.Primary.Automatic		= false
SWEP.Primary.Ammo			= "none"

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Ammo			= "none"

/*---------------------------------------------------------
	Drop all on respawn
---------------------------------------------------------*/

function SWEP:Deploy()
	HeldEnt = nil  
end

/*---------------------------------------------------------
	Reload does nothing
---------------------------------------------------------*/
function SWEP:Reload()
end

/*---------------------------------------------------------
   Think holds the stuff in place
---------------------------------------------------------*/
function SWEP:Think()
	if ( !HeldEnt ) then return end  
		local ent = HeldEnt
		local phys_ent = HeldEnt:GetPhysicsObject( )
		if (!ent:IsValid() || !ent:GetClass()=="prop_physics" ) then
			HeldEnt = nil  
		end  
	local pos = self.Owner:GetShootPos()
	local ang = self.Owner:GetAimVector()
	ent:SetPos(pos+(ang*80)) 
	ent:SetAngles(self.Owner:GetAngles())

end


/*---------------------------------------------------------
	PrimaryAttack
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
	if ( HeldEnt ) then  
			local phys_ent = HeldEnt:GetPhysicsObject( )
			if ( HeldEnt:IsValid() ) then 
				phys_ent:EnableMotion(true) 
				phys_ent:ApplyForceCenter(self.Owner:GetForward()*100)
				HeldEnt:SetOwner()
				HeldEnt = nil
			end			
	else
		
		local pos = self.Owner:GetShootPos()  
		local ang = self.Owner:GetAimVector()  
		local armlength = {}  
		armlength.start = pos  
		armlength.endpos = pos+(ang*75)  
		armlength.filter = self.Owner  
	
		local tr = util.TraceLine(armlength)
	
		if ( tr.HitWorld || !tr.Entity || !tr.Entity:IsValid() || tr.Entity:GetClass()=="func_door_rotating" || tr.Entity:GetClass()=="func_door" || tr.Entity:GetClass()=="prop_dynamic" || tr.Entity:GetClass()=="prop_static") then 
			return 
		end
		
		if ( tr.Entity:IsPlayer() || tr.Entity:IsNPC() ) then 
			util.BlastDamage(self.Owner, self.Owner, tr.Entity:GetPos(), 1, 3)
			return
		end
		
		local ent = tr.Entity
		local player = self.Owner
		local phys_ent = ent:GetPhysicsObject( )
		phys_ent:EnableMotion(true) 
			if ( phys_ent:GetMass() > 50 ) then
				phys_ent:ApplyForceCenter( (Vector( self.Owner:GetAimVector() ) * 75) + self.Owner:GetShootPos() * 29 )
			end
		HeldEnt = ent
		HeldEnt:SetOwner( player )
	end
end
/*---------------------------------------------------------
	SecondaryAttack
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
if ( HeldEnt ) then  
			local phys_ent = HeldEnt:GetPhysicsObject( )
			if ( HeldEnt:IsValid() ) then 
				phys_ent:EnableMotion(true) 
				phys_ent:ApplyForceCenter(self.Owner:GetForward()*10000)
				HeldEnt:SetOwner()
				HeldEnt = nil
			end	
			end	
end

/*---------------------------------------------------------
   Name: ShouldDropOnDie
   Desc: Should this weapon be dropped when its owner dies?
---------------------------------------------------------*/
function SWEP:ShouldDropOnDie()
	return false
end


Modified the code to make it suitable for multiplayer, the problem still persists though.

I have Msg’d the entity names for prop_physics and for some reason it’s “Physics Prop” ingame, when i tried putting that into the if-function it didn’t work though. Strange, isn’t it?

Make it so when you drop it it creates it as a prop_physics and prop_solid, that might work.

That’s not a bad idea, basically saving the prop instead of really holding it out, still, i wonder if there’s another possibility?

Try using prop_physics_multiplayer? That may work.

theres usually… prop_ragdoll, prop_physics and prop_physics_multiplayer those are usually the main things. carrys a dead body HURRAY!

Exclusion works now, thank you guys. The larger problem(s) persist, i tried making it multiplayable by binding all ent-info and variables to the player (pl.ent) but it just gives me errors.

Plus, i can still throw stuff through world and props - no collision while carrying them around ;_;

Any ideas?

Make it so when you pick it up it also sets it as prop_physics_multiplayer and prop_solid, so it is always a prop_physics_multiplayer and always a prop_solid. I’m not sure how to do this but I’m sure it’s someone on the wiki lol

That’s really not the problem because if you’re careful, you can let what you carry collide with props and chuck them around with what you carry. The problem is when you’re moving with normal speed things go through props and world.

Wait, I’m Confused…Is it nocolliding when you throw it or when you move, and do you want it to collide when your holding it or not?

When i throw it, it collides with stuff.

As soon as i pick it up it hovers in front of me.

If i carefully move the surface of the prop i carry, lets say a wooden box, against another prop, lets say a barrel, i can tip over the barrel with the box. If i move the box faster, it will go throgh the barell and nothing happens.

Plus, if the box touches a wall or the floor or the ceiling, it goes right through, wich means i could throw props into the void or any room connected to the one i am standing in.

Yes, i need the box to collide whil i am carrying it, much like the gravity or phys gun.

Thanks for your interest.

hm, well if you wanted to go about it in a slightly different way you can just make it so when you go to throw it it destroys the old one and just create a new prop, same model and material. I think that would solve the no-collide with world

Needs to create it exactly at the same coordinates :v:

I tried it, it’s not helping. If you stand infront of a wall and throw the prop it goes through nonetheless, same goes for other props.

Hmm, this might seem dumb but I remember from another thread about something related to the gravity gun and a hook called WAS_THROWN or something. Try that. (Don’t pick up explosives :v:)

Thank god someone is making a hands swep that actually picks things up!!! I’ve been working to set up a server using CakeScript, and #1 the hands swep it provides doesn’t allow picking up of objects… lol … Anyways I’ve been looking around at hands sweps and I came across this video, which is absolutely a perfect hands swep: http://www.youtube.com/watch?v=hw8EcLo2jBU
I wish the desc. would have a link to dload it or something but it doesn’t give one.
-Anyways, back on topic, Good luck with your hands swep! Can’t wait for a release!

Well, you bumped a 2 months old thread which is probably dead, but to help you out:
http://www.facepunch.com/showthread.php?t=739507

Wow, holy shit. Thank you so much! Haha, yeah I guess I just wasn’t looking hard enough. Anyways thank you a ton! That really helps a lot! :smiley: