Entity.SetParent

From GMod Wiki

Jump to: navigation, search
Function
Syntax Entity:SetParent( Entity Parent )
Description:
Sets (or clears) the entity's parent.
Returns: nil
In Object: Entity
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Entity.SetParent]Entity.SetParent [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionA SWEP that parents the stuff you shoot to yourself.
Used onNewerShared.png
Code
function SWEP:PrimaryAttack()
     local trace = self.Owner:GetEyeTrace() // Makes a tracer
     if( trace.HitNonWorld && trace.Entity:IsValid() ) then // Checks if the tracer hit something and if it's a valid Entity
          trace.Entity:SetParent( self.Owner ) // If it is, parent it to the person holding the SWEP
     end
end
OutputN/A


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox