Problem: How do I spawn a NPC where I can choose the pos?

Hi, I am trying to make a Zombiesurvaval game, and a big problem is how can make the server spawn a zombie each 10 seconds at a position I can define in my code.

[lua]timer.Create( 10, 0, function()
–Code here
end)[/lua]

You could also create a table of co-ordinates as spawn locations, just go to the palces you want as spawn positions and theres a command which gives you your exact co-ordinates, forgot it though, and then put them in a table.

And call it in the function with table.random(tablename)

[editline]08:27PM[/editline]

Or if you want a seperate spawn position you could use

[lua]local spawnpos = “positionhere”[/lua]

I could do so. If I knew how to spawn an npc…

[lua]
timer.Create(“SpawnZombie”, 10, 0, function()
local Zombie = ents.Create(“npc_zombie”)
Zombie:SetPos(Vector(X,Y,Z))
Zombie:Spawn()
end)
[/lua]

X Y and Z is the Positions, Example: Vector(-2000,1300,20)

you can also use something like this to spawn your npc when the map start[lua]hook.Add( “InitPostEntity”, “Createspawpoint”, function()
local NpC=ents.Create(“npc_gman”)
NpC:SetPos(Vector(-4771, 1497, -383))
NpC:Spawn()
end)[/lua]

Ok. Thanks a lot. But is there any way to find out where I am standing so I can spawn a zombie there. (msg my current pos for example) And make a table with some different locations?

[lua]
concommand.Add(“ZombieSpawnPos”, function( ply )
local POS = ply:GetPos()
timer.Create(“SpawnZombie”, 10, 0, function()
local Zombie = ents.Create(“npc_zombie”)
Zombie:SetPos(POS)
Zombie:Spawn()
end)
end)
[/lua]

This would make so when you enter the command: “ZombieSpawnPos”, it will create a timer there of 10 seconds that spawns zombies there.

Ok. So if I want to find my pos I can use

Msg((ply:GetPos())) ?

Or do I have to define ply first? In case how to?

If you want to find out your position, you could create a command for it.
[lua]
concommand.Add(“GetMyPos”, function( ply )
local Pos = ply:GetPos()
Msg(“Vector(”…Pos.x…","…Pos.y…","…Pos.z…")")
end)
[/lua]
That would print your position.

Nice! One step closer my gamemode! Ticker owns! (I found out there was a new post in my thread with it)

Or just type getpos in the console?

Lol! Ill do it now and make a table fr different positions.

But where to put the code? Server or client?

Server as it is the server spawning the zombies.

Ok. Thanks.

Dude, this does not work… The gamemode dont load when I start the game.

[editline]03:59PM[/editline]

OK. This time I put the code in shared.lua, but stil doesent work.
Error:

Can’t find factory for entity: npc_zombie
Timer Error: zombiekiller\gamemode\shared.lua:23: Tried to use a NULL entity!
Can’t find factory for entity: npc_zombie
Timer Error: zombiekiller\gamemode\shared.lua:23: Tried to use a NULL entity!

[editline]04:02PM[/editline]

This code did I use:
[lua]
timer.Create(“SpawnZombie”, 10, 0, function()
local Zombie = ents.Create(“npc_zombie”)
Zombie:SetPos(Vector(3817.039795, -1362.936646, -79.968750))
Zombie:Spawn()
end)
[/lua]

[editline]04:27PM[/editline]

Problem fixed!!!

Hey! Something weird is happening! When the server spawns a zombie, it does not"see" me (it does not follow me) unless I move very close to it, or attack it. Sometimes, they move away from me!!!

Because it’s an NPC.

Make a Scripted NPC. (Tutorial at Wiki)

But when you spawn one manually in sandbox, they see me, even if I dont attack it.

[editline]12:21PM[/editline]

Just try.

The map may not be noded for npcs.