From 28affa22541b9ef251707793f6b1c1a26d663592 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 3 Nov 2018 18:23:45 -0400 Subject: Started on new npc system Started work on the new npc system --- gamemode/npcsystem/sh_basenpc.lua | 34 +++++++++++++++++ gamemode/npcsystem/sh_humannpc.lua | 67 +++++++++++++++++++++++++++++++++ gamemode/npcsystem/sh_movingnpc.lua | 22 +++++++++++ gamemode/npcsystem/sh_shop.lua | 16 ++++++++ gamemode/npcsystem/sh_talkablenpc.lua | 14 +++++++ gamemode/npcsystem/sh_townie.lua | 17 +++++++++ gamemode/npcsystem/sv_blockingdummy.lua | 2 +- gamemode/npcsystem/sv_dummy.lua | 2 +- gamemode/npcsystem/sv_rat.lua | 2 +- gamemode/npcsystem/sv_zombie.lua | 4 +- 10 files changed, 175 insertions(+), 5 deletions(-) create mode 100644 gamemode/npcsystem/sh_basenpc.lua create mode 100644 gamemode/npcsystem/sh_humannpc.lua create mode 100644 gamemode/npcsystem/sh_movingnpc.lua create mode 100644 gamemode/npcsystem/sh_shop.lua create mode 100644 gamemode/npcsystem/sh_talkablenpc.lua create mode 100644 gamemode/npcsystem/sh_townie.lua (limited to 'gamemode/npcsystem') diff --git a/gamemode/npcsystem/sh_basenpc.lua b/gamemode/npcsystem/sh_basenpc.lua new file mode 100644 index 0000000..b3e7e49 --- /dev/null +++ b/gamemode/npcsystem/sh_basenpc.lua @@ -0,0 +1,34 @@ +--[[ + Defines some ai primitives for npc's +]] +local log = nrequire("log.lua") +local reg = nrequire("sh_npcsystem.lua") + +local npc = {} + +npc.Name = "NPC Base" + +function npc:Spawn() + local e = ents.Create("art_npc") + + 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 + + self.Entity = e + e:Spawn() +end + +reg.RegisterNPC(npc) + +return npc diff --git a/gamemode/npcsystem/sh_humannpc.lua b/gamemode/npcsystem/sh_humannpc.lua new file mode 100644 index 0000000..b4a2b15 --- /dev/null +++ b/gamemode/npcsystem/sh_humannpc.lua @@ -0,0 +1,67 @@ +local reg = nrequire("sh_npcsystem.lua") +local log = nrequire("log.lua") + + +local base1 = nrequire("sh_talkablenpc.lua") +local base2 = nrequire("sh_movingnpc.lua") + +local human_models = {} +for i = 1,7 do + human_models[#human_models + 1] = string.format("models/Humans/Group01/Female_0%d.mdl",i) +end +for i = 1,9 do + human_models[#human_models + 1] = string.format("models/Humans/Group01/Male_0%d.mdl",i) +end + +local npc = {} +setmetatable(npc,{__index = function(self,key) + if key == "Model" then + return human_models[math.random(#human_models)] + else + return base1.key or base2.key + end +end}) + +npc.Name = "Human NPC Base" + +npc.canlearn = true + +--things that npcs can learn +local learnable = { + action = { + "name", -- Name of the action + "preconditions", --Things that must be true before we can do an action + "postconditions", --Things that must be true after we do an ation + }, + event = { + "name", -- The name of the event + "time", -- When the event happened + "who", --Who was involved in the event ? + "where", --Where did this event take place ? + }, + entity = { --NOT the same as source engine entities + "name", --The name of this person + "relations", --Things about this person + }, + thing = { + "name", -- The name of the thing + "location", -- Where is this thing? + "size", --How big is this thing? + }, +} +for k,v in pairs(learnable) do + npc["known_" .. k .. "s"] = {} + local capt = k:gsub("^%l", string.upper) + npc["Teach" .. capt] = function(self,tbl) + if self.canlearn == false then return end + for i,j in pairs(v) do + if tbl[j] == nil then + log.error(string.format("Tried to teach %s about %s %q without field %q",self.Name, k, tbl.Name, j)) + end + end + local kt = self["known_" .. k .. "s"] + kt[#kt + 1] = tbl + end +end + +reg.RegisterNPC(npc, "Human NPC Base") diff --git a/gamemode/npcsystem/sh_movingnpc.lua b/gamemode/npcsystem/sh_movingnpc.lua new file mode 100644 index 0000000..21f302e --- /dev/null +++ b/gamemode/npcsystem/sh_movingnpc.lua @@ -0,0 +1,22 @@ +local reg = nrequire("sh_npcsystem.lua") + +local base = nrequire("sh_basenpc.lua") +local nextbot = scripted_ents.Get("base_nextbot") +local npc = {} + +npc.Name = "Walkable NPC Base" + +setmetatable(npc,{__index = function(self,key) + return self[key] or base[key] or nextbot[key] +end}) + +function npc:Initalize() + 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) +end + +function npc:Face(ang_or_vec) + print("trying to face:",ang_or_vec,type(ang_or_vec)) +end +reg.RegisterNPC(npc) diff --git a/gamemode/npcsystem/sh_shop.lua b/gamemode/npcsystem/sh_shop.lua new file mode 100644 index 0000000..c2b291d --- /dev/null +++ b/gamemode/npcsystem/sh_shop.lua @@ -0,0 +1,16 @@ +local reg = nrequire("sh_npcsystem.lua") + +local base = nrequire("sh_talkablenpc.lua") +local npc = {} + +local npc_m = {__index = function(self,key) + return base[key] +end} + +setmetatable(npc,npc_m) + +npc.Name = "Shopkeep" + +reg.RegisterNPC(npc) + +return npc diff --git a/gamemode/npcsystem/sh_talkablenpc.lua b/gamemode/npcsystem/sh_talkablenpc.lua new file mode 100644 index 0000000..9e1cfb9 --- /dev/null +++ b/gamemode/npcsystem/sh_talkablenpc.lua @@ -0,0 +1,14 @@ +--[[ + Some basics for talking to npcs +]] +local reg = nrequire("sh_npcsystem.lua") + +local base = nrequire("sh_basenpc.lua") +local npc = {} +setmetatable(npc,{__index = base}) + +npc.Name = "Talkable NPC Base" + +reg.RegisterNPC(npc) + +return npc diff --git a/gamemode/npcsystem/sh_townie.lua b/gamemode/npcsystem/sh_townie.lua new file mode 100644 index 0000000..3b693c5 --- /dev/null +++ b/gamemode/npcsystem/sh_townie.lua @@ -0,0 +1,17 @@ +local reg = nrequire("sh_npcsystem.lua") + +local base1 = nrequire("sh_talkablenpc.lua") +local base2 = nrequire("sh_moveingnpc.lua") +local npc = {} + +local npc_m = {__index = function(self,key) + return base1[key] or base2[key] +end} + +setmetatable(npc,npc_m) + +npc.Name = "Townie" + +reg.RegisterNPC(npc) + +return npc diff --git a/gamemode/npcsystem/sv_blockingdummy.lua b/gamemode/npcsystem/sv_blockingdummy.lua index c40fc54..d29d33c 100644 --- a/gamemode/npcsystem/sv_blockingdummy.lua +++ b/gamemode/npcsystem/sv_blockingdummy.lua @@ -1,5 +1,5 @@ -local n = nrequire("sv_npcsystem.lua") +local n = nrequire("sh_npcsystem.lua") local NPC = {} NPC.Name = "Blocking Training Dummy" NPC.Desc = "A man made of straw. His dream is to have a brain." diff --git a/gamemode/npcsystem/sv_dummy.lua b/gamemode/npcsystem/sv_dummy.lua index 0bfa063..f527c03 100644 --- a/gamemode/npcsystem/sv_dummy.lua +++ b/gamemode/npcsystem/sv_dummy.lua @@ -1,4 +1,4 @@ -local n = nrequire("sv_npcsystem.lua") +local n = nrequire("sh_npcsystem.lua") local NPC = {} NPC.Name = "Training Dummy" diff --git a/gamemode/npcsystem/sv_rat.lua b/gamemode/npcsystem/sv_rat.lua index fadbc8d..bf2cc65 100644 --- a/gamemode/npcsystem/sv_rat.lua +++ b/gamemode/npcsystem/sv_rat.lua @@ -1,4 +1,4 @@ -local n = nrequire("sv_npcsystem.lua") +local n = nrequire("sh_npcsystem.lua") local NPC = {} NPC.Name = "Rat" NPC.Desc = "A nasty little guy" diff --git a/gamemode/npcsystem/sv_zombie.lua b/gamemode/npcsystem/sv_zombie.lua index a612e92..9f0f747 100644 --- a/gamemode/npcsystem/sv_zombie.lua +++ b/gamemode/npcsystem/sv_zombie.lua @@ -1,4 +1,4 @@ -local n = nrequire("sv_npcsystem.lua") +local n = nrequire("sh_npcsystem.lua") --local ncom = nrequire("sv_common.lua") local NPC = {} NPC.Name = "Zombie" @@ -154,7 +154,7 @@ end -- -- endpos =( self:GetForward() * 50) + self:GetPos() + Vector(0,0,50), -- -- filter = self -- -- }) --- +-- -- end --These are just here to tell the editors/develoeprs what functions are available.. dont un-comment them out, as this could affect all the items. -- cgit v1.2.3-70-g09d2