how to make props shot from a gun stick to a wall

Ok, I know it has already been done, but im trying to make a harpoon swep.

I am very new to lua, but i know how to make a basic prop launching gun, The one I have now shoots out a harpoon, and I would like to know how I can make it so that if I shoot an npc that is in front of a wall the harpoon will pin the npc to the wall.

Thanks in advance! First to answer goes in the credits for my release!

I think it’s part of the model, not part of the weapon.

Constraint.Weld

If you use the same harpoon then in Half Life 2 then yes it should automatically pin the NPCs to the wall, just like the sawblade always slices zombies.

Well, you’ll need to make the projectile into an entity. After you do that, simply use this code, adjusting where necessary… Tested, and working.
[lua]function ENT:PhysicsCollide( data, phys )

if self:GetVelocity():Length() < 250 then
	self:Disable()
	return
end
local Ent = data.HitEntity
if !(ValidEntity( Ent ) || Ent:IsWorld()) then return end
if Ent:IsWorld() then
	if data.OurOldVelocity:Normalize():Dot( data.HitNormal ) > .5 then
		self:SetPos( data.HitPos )
		self:SetAngles( data.OurOldVelocity:Angle() )
		self:GetPhysicsObject():EnableMotion( false )
		util.Decal( "ManhackCut", data.HitPos + data.HitNormal, data.HitPos - data.HitNormal )
		self:EmitSound( self.Hit[math.random(1,#self.Hit)] );
	end
	self:Disable()
elseif Ent.Health then
	if not(Ent:IsPlayer() || Ent:IsNPC() || Ent:GetClass() == "prop_ragdoll") then 
		util.Decal( "ManhackCut", data.HitPos + data.HitNormal, data.HitPos - data.HitNormal )
		self:EmitSound( self.Hit[math.random(1,#self.Hit)] );
	end
	Ent:TakeDamage( 18, self:GetOwner() )
	self:SetPos( data.HitPos )
	self:SetParent( Ent )
	Ent:DeleteOnRemove( self )
	self:Disable()
	if (Ent:IsPlayer() || Ent:IsNPC() || Ent:GetClass() == "prop_ragdoll") then 
		local effectdata = EffectData()
		effectdata:SetStart( data.HitPos )
		effectdata:SetOrigin( data.HitPos )
		effectdata:SetScale( 1 )
		util.Effect( "BloodImpact", effectdata )
		self:EmitSound( self.FleshHit[math.random(1,#self.Hit)] );
		self:Remove() --Go ahead and drop this line or comment it if you want it to stick to npcs.
	end
end

end[/lua]

i dont own any of the half life games on pc :frowning:

[editline]03:40PM[/editline]

thank you!

How can this work? “ent:isplayer()” It should be ent:IsPlayer()

It removed his capitals when it was quoted.

how do you make the prop perjectile into an entity because this is my second weapon and i wana make my gun shoot a knife i modeled

You need to make a normal entity, set the model to your model, then add this code to the entity. In your SWEP you need to make it shoot this entity with speed.

yes i am aware that asking that is totaly dumb but o well and thanks for the help

If you want me to do it add me on steam.

[editline]26th March 2011[/editline]

I will try my best. (Not expert :P)

no thanks im doing this for school so i wana my own codeing