summaryrefslogtreecommitdiff
path: root/lua/autorun/zone_town.lua
blob: a068021b30e01a57f560f92c50fe956ea4806925 (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
--[[
	A hunting ground zone will occasionally spawn a monster near a player that will go attack the player
]]
zones.RegisterClass("artery_town",Color(0,255,0))

--Use this to set default properties. Only called on server.
hook.Add("OnZoneCreated","artery_town",function(zone,class,zoneID)
	if class == "artery_town" then
		zone.npctbl = {}
	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_town",function(zone,class,DPanel,zoneID,DFrame)
	if class == "artery_town" then
		local w,h = 500, 400

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

		function synctbl()
			net.Start("artery_town_settbl")
			net.WriteFloat(zoneID)
			net.WriteTable(zone.npctbl)
			net.SendToServer()
		end

		print("Displaying table, my table is")
		PrintTable(zone.npctbl)
		
		local monsterlb = vgui.Create("DLabel",DPanel)
		monsterlb:Dock(TOP)
		monsterlb:SetText("Town name:")
		monsterlb:SetDark(true)
		monsterlb:SizeToContents()
		local groundsname = vgui.Create("DTextEntry",DPanel)
		groundsname:SetText(zone.npctbl.Name or "")
		groundsname:Dock(TOP)
		groundsname.OnEnter = function()
			zone.npctbl.Name = groundsname:GetValue()
			synctbl()
		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_town_settbl")
	net.Receive("artery_town_settbl",function(len,ply)
		print("Server change received!")
		local id, new = net.ReadFloat(), net.ReadTable()
		print("New table is:")
		PrintTable(new)
		if not ply:IsAdmin() then return end
		zones.List[id].npctbl = new
		zones.Sync()
	end)
end