Entity/SetOwner

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m
Line 1: Line 1:
 
{{Func
 
{{Func
|Description=Sets the owner of this entity, disabling all physics interaction with it, the gravity gun picks up the entity regardless.
+
|Description=Sets the owner of this entity, disabling all physics interaction with it.
  
 
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.
 
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.
 +
 +
{{Note|The Gravity gun will be able to pick up the entity even if the owner can't collide with it}}
 
|Realm=Shared
 
|Realm=Shared
 
|IsClass=Yes
 
|IsClass=Yes

Revision as of 11:59, 1 November 2016

 Entity:SetOwner( )

Contents

Description

Sets the owner of this entity, disabling all physics interaction with it.

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.

NOTE

The Gravity gun will be able to pick up the entity even if the owner can't collide with it

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