Entity.SetOwner

From GMod Wiki

Jump to: navigation, search
Function
Syntax Entity:SetOwner( Entity )
Description:
Sets the 'owner' of an entity. This disables collision between the entity and its owner. If the prop kills another entity, the owner of the prop will be the inflictor and will get credit for the kill.
Returns: nil
In Object: Entity
Available On:
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Entity.SetOwner]Entity.SetOwner [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Image:Notepad-48.png Entity:SetOwner should not normally be used unless you want to disable collision between two entities. Sure, Entity:GetOwner gets what's set by Entity:SetOwner, but Entity:SetOwner also disables collisions and gives kill credit to the "owner". If you simply want to give kill credit, use Entity:SetPhysicsAttacker


Examples

DescriptionSets target entity to be owned by you
Used on
Code
function ownd(ply)
local tr = utilx.GetPlayerTrace( ply, ply:GetCursorAimVector() )
local trace = util.TraceLine( tr )
trace.Entity:SetOwner(ply)
end
OutputNone.


Additional Notes

  • You can walk through an entity you own, and you can't physgun it.
  • Bullets goes through entities you own.
  • The owner does not have to be a player. It can be any type of entity.
  • This function (Or the C++ equivalent) is used for weapons. Hence why collision is disabled and the owner takes kill points.

See Also

Personal tools