aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/npc
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/core/npc')
-rw-r--r--gamemode/core/npc/sv_npcsystem.lua93
-rw-r--r--gamemode/core/npc/sv_shop.lua17
2 files changed, 99 insertions, 11 deletions
diff --git a/gamemode/core/npc/sv_npcsystem.lua b/gamemode/core/npc/sv_npcsystem.lua
index b41f4e6..1abbc67 100644
--- a/gamemode/core/npc/sv_npcsystem.lua
+++ b/gamemode/core/npc/sv_npcsystem.lua
@@ -1,4 +1,3 @@
-
local f = nrequire("concommands.lua")
local n = {}
local npcs = {} --Master table of npcs
@@ -12,28 +11,100 @@ function n.RegisterNPC(npc)
end
function n.CreateNPCByName(npcname, pos)
- print("Createing a " ,npcname ," at ", pos)
+ print("Createing a ", npcname, " at ", pos)
local npctbl = npcs[npcname]
local npc = ents.Create("npc_huntable")
npc:SetPos(pos)
- for k,v in pairs(npctbl) do
+
+ for k, v in pairs(npctbl) do
npc[k] = v
end
+
npc:Spawn()
+
return npc
end
+--Creates a shop npc with this tbl
+function n.CreateShop(npc)
+ print("Createing shop npc")
+ local npcent = ents.Create("npc_shop")
+ for k,v in pairs(npc) do
+ npcent[k] = v
+ end
+ npcent:Spawn()
+ print("Called spawn")
+end
-if SERVER then
- autocompletef = nil
-else
- autocompletef = f.AutocompleteFunction(npcs)
+--Creates a townie npc with this tbl
+function n.CreateTownie(tbl)
+ local npcent = ents.Create("npc_townie")
+ for k, v in pairs(tbl) do
+ npcent[k] = v
+ end
+ npcent:Spawn()
+end
+
+--Creates a new navigation node for npc's
+function n.CreateNavNode(tbl)
+ local nodeent = ents.Create("info_townienode")
+ assert(tbl ~= nil, "Tried to create a nil navnode")
+ for k, v in pairs(tbl) do
+ nodeent[k] = v
+ end
+ nodeent:Spawn()
+end
+
+--Ents to remove when refreshing the npc map
+local removeents = {"npc_townie", "info_townienode", "npc_shop"}
+
+-- "art_chest",
+for k, v in pairs(removeents) do
+ local eot = ents.FindByClass(v)
+ for i, j in pairs(eot) do
+ j:Remove()
+ end
+end
+
+local mapfields = {"navnodes", "npcs"}
+
+-- "chests",
+local function loadMap()
+ for k, v in ipairs(mapfields) do
+ local mapname = game.GetMap()
+ local fpath = string.format("artery/maps/%s/%s/*", mapname, v)
+ local files, dirs = file.Find(fpath, "DATA")
+
+ for i, j in pairs(files) do
+ if string.GetExtensionFromFilename(j) ~= "lua" then continue end
+ local itempath = string.format("artery/maps/%s/%s/%s", mapname, v, j)
+ local itemtxt = file.Read(itempath, "DATA")
+ assert(itemtxt ~= nil, "Found a file, but it looks like it can't be compiled:" .. itempath)
+ CompileString(itemtxt, itempath)()
+ end
+ end
end
-concommand.Add("artery_makenpc",function(ply,cmd,args)
+
+hook.Add("InitPostEntity", "artery_spawnmapnpcs", function()
+ loadMap()
+end)
+
+concommand.Add("artery_reloadmap", function()
+ for k, v in pairs(removeents) do
+ local eot = ents.FindByClass(v)
+
+ for i, j in pairs(eot) do
+ j:Remove()
+ end
+ end
+
+ loadMap()
+end)
+
+concommand.Add("artery_makenpc", function(ply, cmd, args)
if not ply:IsAdmin() then return end
local na = args[1]
- n.CreateNPCByName(na,ply:GetEyeTrace().HitPos)
-end,
-autocompletef)
+ n.CreateNPCByName(na, ply:GetEyeTrace().HitPos)
+end, autocompletef)
return n
diff --git a/gamemode/core/npc/sv_shop.lua b/gamemode/core/npc/sv_shop.lua
new file mode 100644
index 0000000..2e54f7e
--- /dev/null
+++ b/gamemode/core/npc/sv_shop.lua
@@ -0,0 +1,17 @@
+--[[
+ Create a shop npc
+]]
+
+local shop = {}
+
+function shop.CreateShop(npc)
+ print("Createing shop npc")
+ local npcent = ents.Create("npc_shop")
+ for k,v in pairs(npc) do
+ npcent[k] = v
+ end
+ npcent:Spawn()
+ print("Called spawn")
+end
+
+return shop