Problem with Entity:GetOwner()


function HasOwner(ent)
	Msg(tostring(ValidEntity( ent:GetOwner() )))
concommand.Add("HowWas", HasOwner)

Why he return false when I look an object with an owner ?


It is because ent in your function is player that executes the command. Simply, change line 2 to Msg(tostring(ValidEntity( ent:GetEyeTrace().Entity:GetOwner() )))

I still have the problem.

GetOwner() only returns what has been explicitly set with SetOwner().

So it’s impossible to know if the owner is the world or the player with GetOwner() ?

Whenever you’re unsure what a function does check it’s wiki page :

In this case the concept of prop protection isn’t builtin the source engine, it is implemented entirely through lua. You will need to find out what the prop protection system you have is using to store who owns what. It often is a Networked String called “Owner” so it might be worth a try.


Thank Crazy Quebec, my script works.

Prop ownership management really should be a part of GMod’s standard code. As it is now, every addon that needs to know the owner of a prop has to manage it by itself, since it can’t depend on the used prop protection addon.

That along with better addon management will probably have to wait until episode 3 engine. It certainly is possible to do both of these things but it doesn’t look like it’s going to happen.