aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/npc/sv_npcsystem.lua
blob: b41f4e6b3fd606abe0566a562f9303b8de99deb9 (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
local f = nrequire("concommands.lua")
local n = {}
local npcs = {} --Master table of npcs
local autocompletef

function n.RegisterNPC(npc)
	assert(npc ~= nil, "Attempted to register a nil npc")
	assert(npc.Name ~= nil, "Attempted to register an npc without a name")
	npcs[npc.Name] = npc
	autocompletef = f.AutocompleteFunction(npcs)
end

function n.CreateNPCByName(npcname, pos)
	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
	npc:Spawn()
	return npc
end


if SERVER then
	autocompletef = nil
else
	autocompletef = f.AutocompleteFunction(npcs)
end
concommand.Add("artery_makenpc",function(ply,cmd,args)
	if not ply:IsAdmin() then return end
	local na = args[1]
	n.CreateNPCByName(na,ply:GetEyeTrace().HitPos)
end,
autocompletef)

return n