diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-05-07 13:47:40 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-05-07 13:47:40 -0400 |
| commit | 9e0537b0aa417e88a6a61238484ddcef74080ae0 (patch) | |
| tree | e2bd590ec3de41d384aa5f6206b14e1a73647846 /gamemode/core/npc/sv_npcsystem.lua | |
| parent | 191ba416c8b611ea4901cead138789a357c56134 (diff) | |
| download | artery-9e0537b0aa417e88a6a61238484ddcef74080ae0.tar.gz artery-9e0537b0aa417e88a6a61238484ddcef74080ae0.tar.bz2 artery-9e0537b0aa417e88a6a61238484ddcef74080ae0.zip | |
Added tons of stuff
Diffstat (limited to 'gamemode/core/npc/sv_npcsystem.lua')
| -rw-r--r-- | gamemode/core/npc/sv_npcsystem.lua | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/gamemode/core/npc/sv_npcsystem.lua b/gamemode/core/npc/sv_npcsystem.lua index 1abbc67..78b041f 100644 --- a/gamemode/core/npc/sv_npcsystem.lua +++ b/gamemode/core/npc/sv_npcsystem.lua @@ -11,6 +11,7 @@ function n.RegisterNPC(npc) end function n.CreateNPCByName(npcname, pos) + assert(npcs[npcname],string.format("No npc named %q, valid names are:\n%s",npcname,table.concat(table.GetKeys(npcs),"\n"))) print("Createing a ", npcname, " at ", pos) local npctbl = npcs[npcname] local npc = ents.Create("npc_huntable") @@ -66,23 +67,32 @@ for k, v in pairs(removeents) do end end -local mapfields = {"navnodes", "npcs"} +local function ExecuteOnFolder(dir, recursive, func) + local path = "" + local fpath = table.concat({path,dir,"/*"}) + local files, directories = file.Find(fpath,"DATA") + for k,v in pairs(files) do + local callpath = table.concat({path,dir,"/",v}) + func(callpath) + end + if not recursive then return end + for k,v in pairs(directories) do + local npath = table.concat({dir,"/",v}) + ExecuteOnFolder(npath,true,func) + end +end --- "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 + local mapname = game.GetMap() + + local foldername = "artery/maps/" .. mapname + ExecuteOnFolder(foldername,true,function(path) + print("I want to run",path) + local filetxt = file.Read(path,"DATA") + print("File text is", filetxt) + CompileString(filetxt,path)() + print("I want to execute",path) + end) end hook.Add("InitPostEntity", "artery_spawnmapnpcs", function() |
