Prop spawning.

I want to make a function for my swep that creates a wood box that is frozen and collides with the player. Here is what I have.


function SWEP:PrimaryAttack()

self.Weapon:SetNextPrimaryFire( CurTime() + 0.1 )

self:EmitSound( ShootSound )
self:ShootEffects( self )

if (!SERVER) then return end

local Forward = self.Owner:EyeAngles():Forward()

local ent = ents.Create( "prop_physics" )
if ( ValidEntity( ent ) ) then
		ent:SetAngles( self.Owner:EyeAngles() )
		ent:SetSolid( SOLID_VPHYSICS )
		ent:SetPos( self.Owner:GetShootPos() + Forward * 50 )

ent:SetOwner( self.Owner )



This creates the box, but I do not collide with the box, nor does my physics gun beam. Also I want the box to be frozen and not move, but mine move. Please Help.

the problem is your using setowner do not use this.

Thank You! :smiley:

That worked but two things.

1.) Should I set the owner, is there a different way?

2.) I need the props to freeze the moment they spawn and stay frozen.


Nevermind. I found the solution. I was telling the prop to freeze before it was spawned. Changing the order fixed it.

No there’s not really a reason to set the owner unless your doing it for a specific reason that your aware in the function of SetOwner(). Gmod, or your admin addon already handles who the prop actually belongs to whenever you spawn it.

If its coming from a swep does it handle it?

ent:SetNWEntity(“owner” , player)

Should work with most prop protection systems.