How would I go about getting the player entity that owns a prop? I currently have a loop that gets every prop, and filtered it to several props. But how would I get the owner as a player entity, as in who spawned that prop and/or other ent? I know ents.GetOwner() doesn't work. Any help?
There is no way to get it in vanilla gmod so you need to set that value manually like this :
[lua]function SpawnedProp(ply, model, ent)
ent.Owner = ply
end
hook.Add("PlayerSpawnedProp", "playerSpawnedProp", SpawnedProp)[/lua]
And retrieve it like this :
ply = ent.Owner
If you want the value to be accessible both serverside and clientside you would do this :
[lua]function SpawnedProp(ply, model, ent)
ent:SetNetworkedEntity("Owner", ply)
end
hook.Add("PlayerSpawnedProp", "playerSpawnedProp", SpawnedProp)[/lua]
And retrieve it like this :
ply = ent:GetNetworkedEntity("Owner")
:eng101:
[url]http://wiki.garrysmod.com/?title=Gamemode.PlayerSpawnedProp[/url]
[url]http://wiki.garrysmod.com/?title=Entity.SetNetworkedEntity[/url]
[url]http://wiki.garrysmod.com/?title=Entity.GetNetworkedEntity[/url]
To see how to hook in the creation of other kind of entities see here :
[url]http://wiki.garrysmod.com/?title=Gamemode_Hooks[/url]
Ah, thank you very much!
Sorry, you need to Log In to post a reply to this thread.