summaryrefslogtreecommitdiff
path: root/lua/autorun/zone_huntingground.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-08-07 18:22:29 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2017-08-07 18:22:29 -0400
commitdaa59a7835c350a09dcb207c714acf57828137f3 (patch)
treeae2c00da0e546447ca17a9c5d8492310e5e93f27 /lua/autorun/zone_huntingground.lua
downloadartery_editor-daa59a7835c350a09dcb207c714acf57828137f3.tar.gz
artery_editor-daa59a7835c350a09dcb207c714acf57828137f3.tar.bz2
artery_editor-daa59a7835c350a09dcb207c714acf57828137f3.zip
Inital Commit
Diffstat (limited to 'lua/autorun/zone_huntingground.lua')
-rw-r--r--lua/autorun/zone_huntingground.lua176
1 files changed, 176 insertions, 0 deletions
diff --git a/lua/autorun/zone_huntingground.lua b/lua/autorun/zone_huntingground.lua
new file mode 100644
index 0000000..cc494a1
--- /dev/null
+++ b/lua/autorun/zone_huntingground.lua
@@ -0,0 +1,176 @@
+--[[
+ 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 = 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
+
+-- 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)")
+ 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
+ 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()
+ 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