From daa59a7835c350a09dcb207c714acf57828137f3 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Mon, 7 Aug 2017 18:22:29 -0400 Subject: Inital Commit --- lua/autorun/zone_dungeon.lua | 146 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 lua/autorun/zone_dungeon.lua (limited to 'lua/autorun/zone_dungeon.lua') diff --git a/lua/autorun/zone_dungeon.lua b/lua/autorun/zone_dungeon.lua new file mode 100644 index 0000000..2e0d6b0 --- /dev/null +++ b/lua/autorun/zone_dungeon.lua @@ -0,0 +1,146 @@ +--[[ + A hunting ground zone will occasionally spawn a monster near a player that will go attack the player +]] +zones.RegisterClass("artery_dungeon",Color(255,0,255)) + +--Use this to set default properties. Only called on server. +hook.Add("OnZoneCreated","artery_dungeon",function(zone,class,zoneID) + if class == "artery_dungeon" then + zone.dungeoncontrol = nil + end +end) + +local monsters = scripted_ents.GetList() + +-- 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) + net.WriteString(zone.Name) + net.WriteUInt(zone.SpawnRate,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 frequence (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("Rat",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 -- cgit v1.2.3-70-g09d2