aboutsummaryrefslogtreecommitdiff
path: root/gamemode/server/sv_mapconfig.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-08-09 17:53:52 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2016-08-09 17:53:52 -0400
commitd4f197a35c207c9891d3f4dc5e9708af48c935de (patch)
treeee8fd3960c3a3fb4ecaf0f62b50d251f007ebaf3 /gamemode/server/sv_mapconfig.lua
parent2fe3c4551344870e3784733fce2d95027b5c8382 (diff)
downloadartery-d4f197a35c207c9891d3f4dc5e9708af48c935de.tar.gz
artery-d4f197a35c207c9891d3f4dc5e9708af48c935de.tar.bz2
artery-d4f197a35c207c9891d3f4dc5e9708af48c935de.zip
Added some weapons
Diffstat (limited to 'gamemode/server/sv_mapconfig.lua')
-rw-r--r--gamemode/server/sv_mapconfig.lua71
1 files changed, 59 insertions, 12 deletions
diff --git a/gamemode/server/sv_mapconfig.lua b/gamemode/server/sv_mapconfig.lua
index 67a20ae..b9a93b8 100644
--- a/gamemode/server/sv_mapconfig.lua
+++ b/gamemode/server/sv_mapconfig.lua
@@ -1,19 +1,66 @@
--Loads map config form a file
-local chests = file.Read("artery/maps/" .. game.GetMap() .. "/chests.txt")
-local npcs = file.Read("artery/maps/" .. game.GetMap() .. "/npcs.txt")
+function ART.CreateTownie(tbl)
+ local npcent = ents.Create("npc_townie")
+ for k,v in pairs(tbl) do
+ npcent[k] = v
+ end
+ npcent:Spawn()
+end
+
+function ART.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
-if chests == nil then return end
-if npcs == nil then return end
+local removeents = {
+ "npc_townie",
+-- "art_chest",
+ "info_townienode",
+}
-for _,line in pairs(string.Explode("\n",chests,false)) do
- local chest = util.JSONToTable(line)
- local chestent = ents.Create("art_chest")
- for k,v in pairs(chest.data) do
- chestent[k] = v
+for k,v in pairs(removeents) do
+ local eot = ents.FindByClass(v)
+ for i,j in pairs(eot) do
+ j:Remove()
end
- for k,v in pairs(chest.procedures) do
- chestent[k](unpack(v))
+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
- chestent:Spawn()
end
+
+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)