How could I tell if a vector is in the skybox?

I made a function to find a random point on the ground, but if the map has a skybox camera room, then it sometimes picks up a point in there. I need a way to differentiate the normal areas from the skybox. Here’s my code, thank you very much.

function _Vec:IsEmpty()
local Contents = util.PointContents(self)
if Contents == 0 then return true end
return false

Getting the random point:
function GetRandomPoint()
local min, max = -16380, 16380
local Point
local function NewPoint()
local x, y, z = math.random(min,max), math.random(min,max), math.random(min,max)
Point = Vector(x, y, z)
if not Point:IsEmpty() then


while Point:IsEmpty() do
    return Point


function GetRandomGroundPoint()
local Point = GetRandomPoint()
local uptrace_data = {}
uptrace_data.start = Point
uptrace_data.endpos = Point + Vector(0,0,16380)
uptrace_data.mask = CONTENTS_SOLID
local uptrace = util.TraceLine(uptrace_data)
Point = uptrace.HitPos
local downtrace_data = {}
downtrace_data.start = Point - Vector(0,0,10)
downtrace_data.endpos = Point - Vector(0,0,16380)
local downtrace = util.TraceLine(downtrace_data)
Point = downtrace.HitPos + (downtrace.HitNormal * 25)

return Point


As you say, there’s a “camera” entity used in 3D skyboxes to define the center of the skybox. Get its position (if it’s deleted after the map starts you’ll have to use the “EntityKeyValue” hook, there are lots of examples everywhere) and you’ll have a way of defining whether an area is part of the skybox or not.

After that though, I’m not sure how you should find out if a point is in that area.
You could just use ents.FindInSphere, maybe by figuring out the size of the skybox room with a few traces and using that as radius.
You could also somehow make traces originating from the camera position and see if those traces connect with the point in question, but that might be hard since there are usually static props in 3D skyboxes (which become part of the world entity after the map starts and therefore can’t be differentiated from the world (AFAIK)).

Also, if this script is useful, give me some feedback about how well it’s working. I’m interested myself since I’ve made scripts that have had to rely on AI nodes, which unfortunately aren’t present in many maps. If you’re interested in a random spawning script (I find it very useful and fun myself, especially for survival horror), I’d be ready to share :slight_smile: It’s quite dynamic, and can spawn grouped-together squads containing different NPCs too. For maps without AI nodes, I’ve resorted to placing “spawn points” where players are, since logically if a player can be in a certain place, so should NPCs (of the same hull size).