aboutsummaryrefslogtreecommitdiff
path: root/gamemode/npcsystem/sh_basenpc.lua
blob: 32c203a42dc567d467bf99df83620eb7339e9c42 (plain)
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
--[[
	Defines some ai primitives for npc's
]]
print("Update from basenpc.lua!")
local log = nrequire("log.lua")
local reg = nrequire("sh_npcsystem.lua")

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

npc.Model = "models/editor/playerstart.mdl"

function npc:edit_hud()
	return {
		{"string","Model",self.Model},
		{"vector3","Start pos",self.Pos},
		{"string","Name",self.Name}
	}
end

reg.RegisterNPC(npc)

return npc