Save NPC Location

Im making a RP server and i was planning on making NPC’s. I was wondering what would be the best way to save them so that every time the map is loaded, the NPC are set. I was thinking sql? or maybe some sorta table? Please help

I’d go for GLON and a simple text file to save it in.

can you give me a example maybe? or somewhere i can learn more about this?

[lua]
– to define and save
local NPCLocations = {}
NPCLocations[1] = {Position = Vector(0,0,0)}
– define some more
local x = glon.encode(NPCLocations)
file.write(“npcs.txt”, x)

– to load
local file = file.read(“npcs.txt”)
local npcs = glon.decode(file)
– npcs is now the same as NPCLocations
[/lua]

Read more about it here: **[Glon.encode

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

thank you so much!

Or just as simple as this, in init.lua


hook.Add("InitPostEntity", "SpawnNPC", function() -- InitPostEntity is called when the server is done loading
    local pos = table.Random(points)
    local npc = ents.Create("npc_kleiner")
    npc:SetPos(Vector(0,0,0))
    npc:Spawn()
end)

Thanks for both responses, im going with Busymonkey’s method. It a lot easier, ill just add a if statement saying if its on this map use this hook if its on this other map use this hook. I dont plan on switching maps alot and it would only be 2 or 3 maps max. If you know how i could determine what the current map is so i can make my if statement, i would greatly appreciate it.

**[Game.GetMap

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