Entity/SetOwner

From Garry's Mod
Revision as of 11:59, 1 November 2016 by Jvs (Talk | contribs)
Jump to: navigation, search
 Entity:SetOwner( )

Contents

Description

Sets the owner of this entity, disabling all physics interaction with it, the gravity gun picks up the entity regardless.

This function is generally used to disable physics interactions on projectiles being fired by the owner, but can also be used for normal ownership in case physics interactions are not involved at all.

Arguments

Entity owner=NULL

The entity to be set as owner.

Examples

Example

Taken from Garry's Flechette gun , shoots a hunter's flechette and sets the owner of the flechette to the player using the weapon.

function SWEP:PrimaryAttack()
	self:SetNextPrimaryFire( CurTime() + 0.1 )
	
	if (!SERVER) then return end

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

	local ent = ents.Create( "hunter_flechette" )
	
	if ( IsValid( ent ) ) then

		ent:SetPos( self.Owner:GetShootPos() + Forward * 32 )
		ent:SetAngles( self.Owner:EyeAngles() )
		ent:Spawn()
		ent:SetVelocity( Forward * 2000 )
		ent:SetOwner( self.Owner )
	end
end


Personal tools
Navigation