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 | |
| 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')
| -rw-r--r-- | gamemode/core/npc/sh_npcsystem.lua | 40 | ||||
| -rw-r--r-- | gamemode/npcsystem/sh_basenpc.lua | 50 | ||||
| -rw-r--r-- | gamemode/npcsystem/sh_humannpc.lua | 4 | ||||
| -rw-r--r-- | gamemode/npcsystem/sh_movingnpc.lua | 9 | ||||
| -rw-r--r-- | gamemode/npcsystem/sh_shop.lua | 2 | ||||
| -rw-r--r-- | gamemode/npcsystem/sh_talkablenpc.lua | 5 | ||||
| -rw-r--r-- | gamemode/npcsystem/sh_townie.lua | 2 |
7 files changed, 71 insertions, 41 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. diff --git a/gamemode/npcsystem/sh_basenpc.lua b/gamemode/npcsystem/sh_basenpc.lua index b3e7e49..32c203a 100644 --- a/gamemode/npcsystem/sh_basenpc.lua +++ b/gamemode/npcsystem/sh_basenpc.lua @@ -1,6 +1,7 @@ --[[ Defines some ai primitives for npc's ]] +print("Update from basenpc.lua!") local log = nrequire("log.lua") local reg = nrequire("sh_npcsystem.lua") @@ -8,25 +9,44 @@ local npc = {} npc.Name = "NPC Base" +--At this point we are the prototype table +local num_npcs = 0 function npc:Spawn() + num_npcs = num_npcs + 1 local e = ents.Create("art_npc") + local metas = {} + + setmetatable(self,{ + __index = function(self,key) + return e[key] + end, + __newindex = function(self,key,value) + e[key] = value + end, + __metatable = function(self) + return getmetatable(e) + end, + }) + + if self.Pos then e:SetPos(self.Pos) + else log.warn("NPC created without a position, this might be a bug!") end + + if self.Name then e:SetName(self.Name) + else e:SetName(string.format("npc_%d",num_npcs)) end + + if self.Ang then e:SetAngles(self.Ang) end + e:Spawn() + self.Entity = e +end - if self.Model then self:SetModel(self.Model) - else log.error("NPC created without model, this might be a bug!") end - - if self.Pos then self:SetPos(self.Pos) - else log.error("NPC created without a position, this might be a bug!") end - - self.talking = false - - if self.Name then self:SetName(self.Name) - else log.error("NPC created without a name! They won't be able to open doors!") end - - if self.Ang then self:SetAngles(self.Ang) end - if self.OnSpawn then self.OnSpawn(self) end +npc.Model = "models/editor/playerstart.mdl" - self.Entity = e - e:Spawn() +function npc:edit_hud() + return { + {"string","Model",self.Model}, + {"vector3","Start pos",self.Pos}, + {"string","Name",self.Name} + } end reg.RegisterNPC(npc) diff --git a/gamemode/npcsystem/sh_humannpc.lua b/gamemode/npcsystem/sh_humannpc.lua index b4a2b15..5cd31f8 100644 --- a/gamemode/npcsystem/sh_humannpc.lua +++ b/gamemode/npcsystem/sh_humannpc.lua @@ -18,7 +18,7 @@ setmetatable(npc,{__index = function(self,key) if key == "Model" then return human_models[math.random(#human_models)] else - return base1.key or base2.key + return base1[key] or base2[key] end end}) @@ -65,3 +65,5 @@ for k,v in pairs(learnable) do end reg.RegisterNPC(npc, "Human NPC Base") + +return npc diff --git a/gamemode/npcsystem/sh_movingnpc.lua b/gamemode/npcsystem/sh_movingnpc.lua index 21f302e..22ddad1 100644 --- a/gamemode/npcsystem/sh_movingnpc.lua +++ b/gamemode/npcsystem/sh_movingnpc.lua @@ -1,16 +1,19 @@ local reg = nrequire("sh_npcsystem.lua") local base = nrequire("sh_basenpc.lua") -local nextbot = scripted_ents.Get("base_nextbot") +local nextbot = nil --Nextbots aren't registered until after this script is run, +--So we need the hacks below to get a "real" nextbot. local npc = {} npc.Name = "Walkable NPC Base" setmetatable(npc,{__index = function(self,key) - return self[key] or base[key] or nextbot[key] + if nextbot == nil then nextbot = scripted_ents.Get("base_nextbot") end + return base[key] or nextbot[key] end}) function npc:Initalize() + if nextbot == nil then nextbot = scripted_ents.Get("base_nextbot") end if base.Initalize then base.Initalize(self) end if nextbot.Initalize then nextbot.Initalize(self) end print("After initalizeing walkable, self.loco is", self.loco) @@ -20,3 +23,5 @@ function npc:Face(ang_or_vec) print("trying to face:",ang_or_vec,type(ang_or_vec)) end reg.RegisterNPC(npc) + +return npc diff --git a/gamemode/npcsystem/sh_shop.lua b/gamemode/npcsystem/sh_shop.lua index c2b291d..31423b6 100644 --- a/gamemode/npcsystem/sh_shop.lua +++ b/gamemode/npcsystem/sh_shop.lua @@ -1,3 +1,5 @@ +print("No longer Hello from sh_shop.lua!") + local reg = nrequire("sh_npcsystem.lua") local base = nrequire("sh_talkablenpc.lua") diff --git a/gamemode/npcsystem/sh_talkablenpc.lua b/gamemode/npcsystem/sh_talkablenpc.lua index 9e1cfb9..85c5aaa 100644 --- a/gamemode/npcsystem/sh_talkablenpc.lua +++ b/gamemode/npcsystem/sh_talkablenpc.lua @@ -9,6 +9,11 @@ setmetatable(npc,{__index = base}) npc.Name = "Talkable NPC Base" +--Get the dialog for a particular player +function npc.getDialogFor(ply) + +end + reg.RegisterNPC(npc) return npc diff --git a/gamemode/npcsystem/sh_townie.lua b/gamemode/npcsystem/sh_townie.lua index 3b693c5..6f93c99 100644 --- a/gamemode/npcsystem/sh_townie.lua +++ b/gamemode/npcsystem/sh_townie.lua @@ -1,7 +1,7 @@ local reg = nrequire("sh_npcsystem.lua") local base1 = nrequire("sh_talkablenpc.lua") -local base2 = nrequire("sh_moveingnpc.lua") +local base2 = nrequire("sh_movingnpc.lua") local npc = {} local npc_m = {__index = function(self,key) |
