diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2019-05-04 16:05:01 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2019-05-04 16:05:01 -0400 |
| commit | 100342bdd0a979f283f90875663784f20282dd5e (patch) | |
| tree | 8188ab5f9dd979d552df3d41fb31b1166b01d150 /gamemode/core/npc | |
| parent | faa8312074e6ea8a96efd70d6188ef592f81e579 (diff) | |
| download | artery-100342bdd0a979f283f90875663784f20282dd5e.tar.gz artery-100342bdd0a979f283f90875663784f20282dd5e.tar.bz2 artery-100342bdd0a979f283f90875663784f20282dd5e.zip | |
Started on the NPC overhual
Added some bits to start on the npcs overhaul
Diffstat (limited to 'gamemode/core/npc')
| -rw-r--r-- | gamemode/core/npc/sh_npcsystem.lua | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/gamemode/core/npc/sh_npcsystem.lua b/gamemode/core/npc/sh_npcsystem.lua index 501f21c..9b43965 100644 --- a/gamemode/core/npc/sh_npcsystem.lua +++ b/gamemode/core/npc/sh_npcsystem.lua @@ -7,8 +7,15 @@ local f = nrequire("concommands.lua") local log = nrequire("log.lua") local n = {} local npcs = {} --Master table of npcs +local npc_metas = {} local autocompletef +function npc_tostring(npctbl) + return function(self) + return string.format("<NPC %q : %s",npctbl.Name,self.Name) + end +end + ---Registers an NPC. -- Adds an npc to the global table. NPC's should have unique .Name fields, if they don't, this function will error. --@see npctbl @@ -17,7 +24,9 @@ function n.RegisterNPC(npc) assert(npc ~= nil, "Attempted to register a nil npc") assert(type(npc) == "table", "Attempted to regsiter an npc that was not a table, it was a " .. type(npc)) assert(npc.Name ~= nil, "Attempted to register an npc without a name") + log.info("Added npc:",npc.Name) npcs[npc.Name] = npc + npc_metas[npc.Name] = {__index = npc, __tostring = npc_tostring(npc)} autocompletef = f.AutocompleteFunction(npcs) end @@ -37,16 +46,9 @@ if SERVER then 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") - npc:SetPos(pos) - - for k, v in pairs(npctbl) do - npc[k] = v - end - + local npc = {Pos = pos} + setmetatable(npc,npc_metas[npcname]) npc:Spawn() - return npc end @@ -55,14 +57,10 @@ if SERVER then --@see shopnpctbl --@tparam table npc The shop npc's table. function n.CreateShop(npc) - --print("Createing shop npc") - local npcent = ents.Create("art_npc") - local shopkeep = n.GetNPC("Shopkeep") - setmetatable(npc,{__index = function(self,key) - return shopkeep[key] or npcent[key] - end}) + local npc = {} + setmetatable(npc,npc_metas["Shopkeep"]) npc:Spawn() - --print("Called spawn") + return npc end ---Creates a townie. @@ -70,12 +68,10 @@ if SERVER then --@see townienpctbl --@tparam table npc The townie npc's table. function n.CreateTownie(tbl) - local npcent = ents.Create("art_npc") - local townie = n.GetNPC("Townie") - setmetatable(tbl,{__index = function(self,key) - return townie[key] or npcent[key] - end}) - tbl:Spawn() + local npc = {} + setmetatable(tbl,npc_metas["Townie"]) + npc:Spawn() + return npc end ---Create an area of intrest. |
