Auto Spawning an SNPC

So I have this SNPC and I would like to know, how to automatically spawn it each time the server starts.

Its name is snpc_hatlady

I just need some code that will make the “Hat Lady” Appear at certain coordinates of the map each time the server starts.

Thanks!

Not sure if this is the most efficient way, but here you go.
[lua]

NPCSpawns = {}
NPCSpawns[1] = {Name = “snpc_hatlady”, Vector = Vector(0,0,0)}

function NPCSpawnStart()
if ( game.GetMap( ) == “RP_EvoCity_v2d” ) then
for k, v in pairs(NPCSpawns) do
local npc = ents.Create(v.Name)
npc:SetPos(v.Vector)
npc:Spawn()
npc:Activate()
end
end
end
hook.Add( “InitPostEntity”, “MapStartTrigger”, NPCSpawnStart )
[/lua]

[lua]local function SpawnHatLady()
if SERVER then
local hatlady = ents.Create( “snpc_hatlady” )
hatlady:SetPos( Vector(0,0,0) )
hatlady:SetAngles( Angle(0,0,0) )
hatlady:Spawn()
end
end
hook.Add( “InitPostEntity”, “SpawnHatLady”, SpawnHatLady )[/lua]

To figure out the position and angles type cl_showpos 1 in the console.

edit: Ninja’d. I do like Lyeol’s way of looking at it, tough you’ll probably want to add the angles too so she doesn’t face a wall or something. :slight_smile:

Thank you so much! I will edit my post with an extra thanks if this works :3

Dude, I gave you the code in your other topic. -.-

Thought this question seemed familiar.

For position print the players position in the console to make your life easier instead.

cl_showpos shows the position of the camera at eye view and will make NPC’s spawn in the air.

GetPos() gets the position at your feet.

Didn’t work.

Crazy’s didn’t work either. :expressionless:

Then you need to take a look at wiki.garrysmod.com and learn some more lua. We can’t fix ALL of YOUR errors. You have to learn to debug for yourself.

Did he not look at mine? The code I gave you works perfectly.

I see no code on your post O.o

Nevermind, IE error. That would work, but he’s making a gamemode as well, and I gave him the damn code to spawn it in the init.lua… I don’t know how he can expect to code a gamemode when he can’t debug for himself. (No offense)

Indeed.

Quick tip : When code doesn’t work do 2 things first.
1 - Make sure it prints no errors to the console. If it does and you can’t figure it out post the error, the code and point out which line gives the error.
2 - Make sure it actually gets ran. To do this add something like print(“It works”) in it.

The following code worked : [lua]
local function SpawnHatLady()
if SERVER then
local hatlady = ents.Create( “npc_alyx” )
hatlady:SetPos( Vector(0,0,0) )
hatlady:SetAngles( Angle(0,0,0) )
hatlady:Spawn()
end
end
hook.Add( “InitPostEntity”, “SpawnHatLady”, SpawnHatLady )[/lua]
It is in a file in garrysmod/lua/autorun. If your code did get run then it’s your hat lady that has a problem.

I just found out that my modules aren’t even being ran and my autorun folder is fucked up. Ugh. Great that was the whole problem. :|. Thank you for the functions. As soon as I fix this I will try them.