Randomly Spawn Certain NPC's?

Is there a way to spawn NPCs in a certain area on a map? Using Lua?

Or would I have to mod Hammer?

You would have to do random positions and traces to find the ground. Shouldent be too hard if you know what your doing

Here’s the basic code you need to spawn a NPC.

[lua]local npc = ents.Create(“npc_zombie”)
npc:SetPos(Vector(0,0,0))
npc:Spawn()[/lua]

The rest is scripting a timer to run this function and having either a pre-made list of vectors or entities, or a script to find suitable locations.

If you are making a map yourself then I strongly recommend you place npc spawns in the map yourself, it’s much easier. You would simply place a simple point entity at the correct spawn point and give it a special class name (like info_spawn_zombie) then in lua you would spawn zombies on top of these.

Thanks, I will try finding a timer script and putting it together.

Question, if I made all of the spawns the same area, would it put one to each or random with one?