summaryrefslogtreecommitdiff
path: root/lua/autorun/zone_huntingground.lua
blob: 57847ca560f48e231445218134cffdbe28a4bb27 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
--[[
	A hunting ground zone will occasionally spawn a monster near a player that will go attack the player
]]
zones.RegisterClass("artery_huntingground",Color(255,255,0))

--Use this to set default properties. Only called on server.
hook.Add("OnZoneCreated","artery_huntingground",function(zone,class,zoneID)
	if class == "artery_huntingground" then
		zone.npctbl = {}
	end
end)

--[[
local monsters = {
	--Skyrim
	"npc_draugr_wight",
	"npc_draugr",
	"npc_draugr_deathlord",
	"npc_draugr_overlord",
	"npc_draugr_scourge",
	"npc_draugr_wight",
	"npc_draugr_restless",
	"npc_scrib",
	"npc_falmer",
	"npc_falmer_gloomlurker",
	"npc_falmer_nightprowler",
	"npc_falmer_shadowmaster",
	"npc_falmer_skulker",
	"npc_mudcrab",
	"npc_deathclaw",
	--Fallout
	"npc_tunneler",
	"npc_tunneler_queen",
}
]]
local monsters
local function find_monsters()
	if monsters == nil then
		monsters = scripted_ents.GetList()
		local sub = {}
		for k,v in pairs(monsters) do
			if k:find("npc_") then
				sub[#sub+1] = k
			end
		end
		monsters = sub
	end
end
-- Use this hook to let a player change a zone after making it or with the edit tool.
-- class is zone.class, zone is the zone's full table, DPanel is a panel to parent your things to, zoneID is the zone's ID, DFrame is the whole frame.
-- Return your preferred width and height for the panel and the frame will size to it.
hook.Add("ShowZoneOptions","artery_huntingground",function(zone,class,DPanel,zoneID,DFrame)
	if class == "artery_huntingground" then
		local w,h = 500, 400

		local scroll = vgui.Create( "DScrollPanel",DPanel)
		scroll:Dock(FILL)

		function synctbl()
			net.Start("artery_hunting_settbl")
			net.WriteFloat(zoneID)
			net.WriteTable(zone.npctbl or {})
			net.WriteString(zone.Name or "")
			net.WriteUInt(zone.SpawnRate or 0,16)
			net.SendToServer()
		end

		print("Displaying table, my table is")
		PrintTable(zone.npctbl)

		local headerbar = vgui.Create("DPanel",scroll)
		headerbar:Dock(TOP)
		local monsterlb = vgui.Create("DLabel",headerbar)
		monsterlb:Dock(LEFT)
		monsterlb:SetText("Monster Type:")
		monsterlb:SetDark(true)
		monsterlb:SizeToContents()
		local freqlb = vgui.Create("DLabel",headerbar)
		freqlb:Dock(RIGHT)
		freqlb:SetText("Spawn frequency (0-100) : Health")
		freqlb:SetDark(true)
		freqlb:SizeToContents()

		local groundslb = vgui.Create("DLabel",DPanel)
		groundslb:Dock(TOP)
		groundslb:SetText("Hunting ground name:")
		groundslb:SetDark(true)
		groundslb:SizeToContents()
		local groundsname = vgui.Create("DTextEntry",DPanel)
		groundsname:SetText(zone.Name or "")
		groundsname:Dock(TOP)
		groundsname.OnEnter = function()
			zone.Name = groundsname:GetValue()
			synctbl()
		end

		local spawnratelb = vgui.Create("DLabel",DPanel)
		spawnratelb:Dock(TOP)
		spawnratelb:SetText("Spawn Rate (in seconds, around 20 is good, lower is more frequent):")
		spawnratelb:SetDark(true)
		spawnratelb:SizeToContents()
		local spawnrate = vgui.Create("DTextEntry",DPanel)
		spawnrate:SetText(zone.SpawnRate or "20")
		spawnrate:Dock(TOP)
		spawnrate:SetNumeric(true)
		spawnrate.OnEnter = function()
			zone.SpawnRate = tonumber(spawnrate:GetValue())
			synctbl()
		end

		local function mkrow(name,freq)
			local thisbar = vgui.Create("DPanel",scroll)
			thisbar:Dock(TOP)

			local monstertype = vgui.Create("DComboBox",thisbar)
			monstertype:Dock(LEFT)
			for i,j in pairs(monsters) do
				monstertype:AddChoice(j)
			end
			monstertype:SetValue(name)
			monstertype.OnSelect = function(panel,index,value)
				zone.npctbl[name] = nil
				zone.npctbl[value] = freq
				synctbl()
			end
			monstertype:SetSize(120,20)

			local frequency = vgui.Create("DTextEntry",thisbar)
			frequency:SetText(freq)
			frequency:SetNumeric( true )
			frequency:Dock(RIGHT)
			frequency:SizeToContents()
			
			local delete = vgui.Create("DButton",thisbar)
			delete:SetText("-")
			delete:Dock(RIGHT)
			delete.DoClick = function()
				print("Attempting to remove",thisbar)
				zone.npctbl[name] = nil
				thisbar:Remove()
			end

			function frequency.OnEnter()
				zone.npctbl[name] = tonumber(frequency:GetValue())
				synctbl()
			end
			
			local health = vgui.Create('DTextEntry',thisbar)
			health:SetText(100)
			health:SetNumeric(true)
			health:Dock(RIGHT)
			health:SizeToContents()
		end

		print("Before drawing npctbl was")
		PrintTable(zone.npctbl)
		for k,v in pairs(zone.npctbl) do
			mkrow(k,v)
		end

		local newpanelbut = vgui.Create("DButton",DPanel)
		newpanelbut:SetText("+")
		newpanelbut:Dock(BOTTOM)
		newpanelbut.DoClick = function()
			if not monsters then find_monsters() end
			mkrow(monsters[1],0)
		end

		return w, h -- Specify the width and height for the DPanel container. The frame will resize accordingly.

	end
end)

if SERVER then
	util.AddNetworkString("artery_hunting_settbl")
	net.Receive("artery_hunting_settbl",function(len,ply)
		print("Server change received!")
		local id, new, name, rate = net.ReadFloat(), net.ReadTable(), net.ReadString(), net.ReadUInt(16)
		print("New table is:")
		PrintTable(new)
		if not ply:IsAdmin() then return end
		zones.List[id].Name = name
		zones.List[id].npctbl = new
		zones.List[id].SpawnRate = rate
		zones.Sync()
	end)
end