Spawn Ents in front of player?

I am trying to spawn ents like DarkRP where it spawns at eyes trace but doesnt go farther than like 3 feet. Any help?

post code pls

I dont have much, I am needing the code to do it. Where you spawn a ent where your looking at but it cant got farther than 3 feet or whatever away from you.

[editline]13th November 2017[/editline]



net.Receive("spawnEnt", function()
	local enti = net.ReadString()
	local ply = net.ReadEntity()
	local tr = ply:GetEyeTrace()

	local ent = ents.Create(enti)
	ent:SetPos(tr.HitPos)
	ent:Spawn()
end)


I want the


ent:SetPos(tr.HitPos)

to do that but also to make it so where it cant go farther than like 3 feet from me

[editline]13th November 2017[/editline]

Found the solution in the darkrp source code.



net.Receive("spawnEnt", function()
	local enti = net.ReadString()
	local ply = net.ReadEntity()

	local trace = {}
    trace.start = ply:EyePos()
    trace.endpos = trace.start + ply:GetAimVector() * 85
    trace.filter = ply

    local tr = util.TraceLine(trace)

	local ent = ents.Create(enti)
	ent:SetPos(tr.HitPos)
	ent:Spawn()
end)




local tr = util.TraceHull( {
	start = ply:EyePos(),
	endpos = ply:EyePos() + ( ply:GetAimVector() * 64),
	filter = ply,
	mins = Vector( -4, -4, -4 ),
	maxs = Vector( 4, 4, 4 ),
} )
local spawnpos = tr.HitPos


[LUA]
net.Receive (“spawnEnt”, function(ply)
trace = util.TraceHull( {
start = ply:EyePos(),
endpos = ply:EyePos() + ( ply:GetAimVector() * 64),
filter = ply,
mins = Vector( -4, -4, -4 ),
maxs = Vector( 4, 4, 4 ),
} )

local ent = ents.Create ("entity")
ent:SetPos (trace.HitPos * ply:GetForward ())
ent:Spawn  ()

end)
[/LUA]

This should keep the in the relative forward position of the player and keep the object on the ground.