owner of toolgun spawned entity

Moin moin,
how can I get the owner of an entity which was spawned by a tool gun? I’m at coding a gamemode where entities will cost money, but if you use OnEntityCreated(ent) you don’t get any owner and the sandbox hooks like GM:PlayerSpawnSENT( pl, ent ) don’t work for toolgun spawned entities. Somewhere in the forums I read something about undo and the entity table but I have no idea how to get this.

I hope you can help me.

You have to set it yourself when spawning the entity. Something like : [lua]local newent = ents.Create(“ent_class”)
newent.Owner = self.Owner[/lua]

hmm but I would need to modify every tool gun(wire) for that and I got my own way already, but anyway thank you :slight_smile:



function UsingTool( ply, tr, tm )
	timer.Simple( 0, SetEntOwner, ply, tr )		
	return true
end
hook.Add( "CanTool", "UsingTool", UsingTool )

function SetEntOwner( ply, tr )
	local found = ents.FindInSphere( tr.HitPos, 24 )
	for k, v in pairs(found) do
		if (not IsValid(v.Owner)) then
			v.Owner = ply
			print(v.Owner)
		end
	end
end