Find a prop's owner?

Is there a better way? I get ‘NULL ENTITY’.



for k, v in pairs ( ents.GetAll() ) do

if v:GetClass( ) == "prop_physics" then

print(v:GetOwner())

end

end


GetOwner() returns the entity set by SetOwner() which “'Sets the “owner” of the entity, which will disable the collision and damage receiving for this entity.”. The ‘owner’ of a weapon will also get points when that weapon kills. It is NOT for recording which player spawned (owns) a prop.

Prop protection systems should use the CPPI standard, and you should be able to do v:GetCPPIOwner().

If your prop protection system hasn’t implemented CPPI then it might be setting a variable on the pprop called Owner and/or OwnerID. You can try printing v.Owner or v.OwnerID and see if that gives you anything.

If you aren’t using a prop protection system, then I don’t think there is any way to get the owner of a prop - default gmod has no system for ‘owning’ props.

I think it’s cause GetOwner() return an entity instead of a string try to do it like this:


for k, v in pairs ( ents.GetAll() ) do

if v:GetClass( ) == "prop_physics" then

print(v:GetOwner():Name()) --return a string instead of an entity

end

end

Ok thanks, I’ve tried both methods from you guys but didn’t get any result. Perhaps I could figure a way through the use of FPtje’s prop protection.

Just hook into the function that’s called when a prop is spawned by a player and manually assign some field to refer to the player who spawned it, then you can access it whenever you need to find the owner of an entity.

Alright, but I couldn’t find a hook yesterday. Maybe I mislooked.

If you are using FPP then you should be able to call CPPIGetOwner (just noticed there is a typo in my previous post, I wrote GetCPPIOwner).

Otherwise, the hooks you are looking for are http://wiki.garrysmod.com/page/Category:SANDBOX_Hooks

Here you go.
**[Lua/Hooks/Sandbox/PlayerSpawnedProp

http://gmodwiki.net/favicon.ico](http://gmodwiki.net/Lua/Hooks/Sandbox/PlayerSpawnedProp)**

-snip-

Didn’t realize it was 3 years old, sorry