Disallowing props being spawned where spawn is?

How would I go about not allowing people to make props near the spawn area? Thanks.

Add a function to these hooks:
PlayerSpawnObject
PlayerSpawnSENT
PlayerSpawnVehicle
PlayerSpawnNPC

Then in the function check if they are inside the spawn area and return false if they are.

I made a function for checking if they are inside a vector box, but it could probably be more efficient if anyone wants to improve it:


function inrange( v, v2, v3 )
	local minV = Vector()
	local maxV = Vector()
	if v2.x < v3.x then
		minV.x = v2.x
		maxV.x = v3.x
	else
		minV.x = v3.x
		maxV.x = v2.x
	end
	if v2.y < v3.y then
		minV.y = v2.y
		maxV.y = v3.y
	else
		minV.y = v3.y
		maxV.y = v2.y
	end
	if v2.z < v3.z then
		minV.z = v2.z
		maxV.z = v3.z
	else
		minV.z = v3.z
		maxV.z = v2.z
	end
	
	if v.x > minV.x and v.x < maxV.x and v.y > minV.y and v.y < maxV.y and v.z > minV.z and v.z < maxV.z then
		return true
	else
		return false
	end
end

Basically, use it as this:

inrange( The player’s position, one corner of the box, the other corner of the box)
ex: inrange( ply:GetPos(), v1, v2 )

If the spawn is a round area you could just check the distance from the center.

Feel free to ask more questions if something is unclear :slight_smile:

or simply **[Ents.FindInBox

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Ents.FindInBox)**

The problem with that is that it doesn’t return the LocalPlayer() if run clientside in my testing. This makes prediction harder, but I guess it could be easy to just write another batch of code using LocalPlayer() instead for the client only. I used that function for other code as well, so that’s why I needed it. Guess I overcomplicated it though.

Yeah, but this pretty much solves the OP’s problem. Check if there are entities in the “spawning box” (or sphere if need be) and remove them.

Yeah, I didn’t think of that when I posted the first one.

You could just use Distance with the spawn coordinates and the object being spawned.

That gives you a sphere; what if the spawn is a box?