1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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")
|