diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-08-07 18:22:29 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-08-07 18:22:29 -0400 |
| commit | daa59a7835c350a09dcb207c714acf57828137f3 (patch) | |
| tree | ae2c00da0e546447ca17a9c5d8492310e5e93f27 /lua/autorun | |
| download | artery_editor-daa59a7835c350a09dcb207c714acf57828137f3.tar.gz artery_editor-daa59a7835c350a09dcb207c714acf57828137f3.tar.bz2 artery_editor-daa59a7835c350a09dcb207c714acf57828137f3.zip | |
Inital Commit
Diffstat (limited to 'lua/autorun')
| -rw-r--r-- | lua/autorun/gcompute_plugin.lua | 130 | ||||
| -rw-r--r-- | lua/autorun/setupzones.lua | 14 | ||||
| -rw-r--r-- | lua/autorun/sv_npc.lua | 121 | ||||
| -rw-r--r-- | lua/autorun/tab.lua | 16 | ||||
| -rw-r--r-- | lua/autorun/town.lua | 141 | ||||
| -rw-r--r-- | lua/autorun/zone_dungeon.lua | 146 | ||||
| -rw-r--r-- | lua/autorun/zone_huntingground.lua | 176 | ||||
| -rw-r--r-- | lua/autorun/zone_serverchanger.lua | 84 | ||||
| -rw-r--r-- | lua/autorun/zone_town.lua | 62 |
9 files changed, 890 insertions, 0 deletions
diff --git a/lua/autorun/gcompute_plugin.lua b/lua/autorun/gcompute_plugin.lua new file mode 100644 index 0000000..02d0e6e --- /dev/null +++ b/lua/autorun/gcompute_plugin.lua @@ -0,0 +1,130 @@ +if SERVER then return end +if engine.ActiveGamemode() ~= "sandbox" then return end +print('Hello from the gcompute plugin!') + +local self, info = GCompute.IDE.ViewTypes:CreateType ("NavView") +info:SetAutoCreate (true) +info:SetDefaultLocation ("Bottom/Right") +self.Title = "Nav View" +self.Icon = "icon16/heart.png" +self.Hideable = true + +local function find_selected_code() + local i = GCompute.IDE:GetInstance() + local selectedpanel + for k,v in pairs(i.ViewManager.ViewsById) do + if v.CodeEditor ~= nil and v.Container:IsVisible() then + selectedpanel = v + break + end + end + print("Found selected panel!") +end + +--Returns an array of nav nodes +local function find_nav_nodes() + +end + +--Returns the name of the npc, "???" if undetermined +local function find_name() + local sp = find_selected_code() + print("Found sp:",sp) +end + +--Create the thing that shows possible nav nodes +function self:ctor (container) + local editor = vgui.Create("DPanel",editorframe) + editor:Dock(FILL) + + --Edit name + local namelabel = vgui.Create("DLabel",editor) + namelabel:SetText("Townie Name:") + namelabel:Dock(TOP) + namelabel:SetDark(true) + local nameentry = vgui.Create("DTextEntry",editor) + nameentry:Dock(TOP) + nameentry:SetText(data.Name) + nameentry:SetUpdateOnType(true) + nameentry.OnValueChange = function(self,value) + data.Name = value + end + + --Edit model + local modellabel = vgui.Create("DLabel",editor) + modellabel:SetText("Townie Model:") + modellabel:Dock(TOP) + modellabel:SetDark(true) + local modelentry = vgui.Create("DTextEntry",editor) + modelentry:Dock(TOP) + modelentry:SetText(data.Model) + modelentry:SetUpdateOnType(true) + modelentry.OnValueChange = function(self,value) + data.Model = value + end + + --Edit navnodes + local navnodelist = vgui.Create("DListLayout",editor) + navnodelist:Dock(FILL) + local allnavents = ents.FindByClass("info_townienode") + + local function create_navnode_panel(v) + local navnodeitm = vgui.Create("DPanel") + + local navname = vgui.Create("DComboBox",navnodeitm) + for i,j in pairs(navnode_info) do + navname:AddChoice(j.Name) + end + navname:SetValue(v) + navname:Dock(LEFT) + navname.OnSelect = function(self,index,value) + data.NavNodes[index] = value + end + + local navdelete = vgui.Create("DButton",navnodeitm) + navdelete:SetText("-") + navdelete.DoClick = function() + print('Tryint to get rid of nav node', v) + --delete it from the data + for i,j in pairs(data.NavNodes) do + if j == v then + for k = i, #data.NavNodes do + data.NavNodes[i] = data.NavNodes[i+1] + end + break + end + end + --and remove the panel + navnodeitm:Remove() + end + navdelete:Dock(RIGHT) + + return navnodeitm + end + + for k,v in pairs(data.NavNodes) do + local navnodeitm = create_navnode_panel(v) + navnodelist:Add(navnodeitm) + end + local addbutton = vgui.Create("DButton",editor) + addbutton:SetText("+") + addbutton.DoClick = function() + local navnodeitm = create_navnode_panel("select") + navnodelist:Add(navnodeitm) + end + addbutton:Dock(BOTTOM) +end + +function self:dtor () + if self.HTMLPanel and self.HTMLPanel:IsValid () then + self.HTMLPanel:Remove () + end + self.HTMLPanel = nil +end + +-- Persistance +function self:LoadSession (inBuffer) +end + +function self:SaveSession (outBuffer) +end diff --git a/lua/autorun/setupzones.lua b/lua/autorun/setupzones.lua new file mode 100644 index 0000000..bf1da4a --- /dev/null +++ b/lua/autorun/setupzones.lua @@ -0,0 +1,14 @@ +--[[ + Add a few differnt zone types to sandbox that can be placed around +]] +AddCSLuaFile("zones.lua") +include("zones.lua") + +print("Hello from artery_editor.lua") +if not zones then error("You must have the zones addon installed for artery_editor to work!") return end + + +zones.RegisterClass("artery_town",Color(0,255,255)) +zones.RegisterClass("artery_outpost",Color(0,255,0)) +zones.RegisterClass("artery_huntingground",Color(255,255,0)) +zones.RegisterClass("artery_dungon",Color(255,0,255)) diff --git a/lua/autorun/sv_npc.lua b/lua/autorun/sv_npc.lua new file mode 100644 index 0000000..2d7322d --- /dev/null +++ b/lua/autorun/sv_npc.lua @@ -0,0 +1,121 @@ +if CLIENT then return end +include("town.lua") +local f = nrequire("concommands.lua") +local npcs = {} --Master table of npcs +local autocompletef + +function 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 CreateNPCByName(npcname, pos) + assert(npcs[npcname],string.format("No npc named %q, valid names are:\n%s",npcname,table.concat(table.GetKeys(npcs),"\n"))) + --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 + +--Creates a shop npc with this tbl +function n.CreateShop(npc) + --print("Createing shop npc") + local npcent = ents.Create("npc_shop") + for k,v in pairs(npc) do + npcent[k] = v + end + npcent:Spawn() + --print("Called spawn") +end + +--Creates a townie npc with this tbl +function n.CreateTownie(tbl) + local npcent = ents.Create("npc_townie") + for k, v in pairs(tbl) do + npcent[k] = v + end + npcent:Spawn() +end + +--Creates a new navigation node for npc's +function n.CreateNavNode(tbl) + local nodeent = ents.Create("info_townienode") + assert(tbl ~= nil, "Tried to create a nil navnode") + for k, v in pairs(tbl) do + nodeent[k] = v + end + nodeent:Spawn() +end + +--Ents to remove when refreshing the npc map +local removeents = {"npc_townie", "info_townienode", "npc_shop"} + +-- "art_chest", +for k, v in pairs(removeents) do + local eot = ents.FindByClass(v) + for i, j in pairs(eot) do + j:Remove() + end +end + +local function ExecuteOnFolder(dir, recursive, func) + local path = "" + local fpath = table.concat({path,dir,"/*"}) + local files, directories = file.Find(fpath,"DATA") + for k,v in pairs(files) do + local callpath = table.concat({path,dir,"/",v}) + func(callpath) + end + if not recursive then return end + for k,v in pairs(directories) do + local npath = table.concat({dir,"/",v}) + ExecuteOnFolder(npath,true,func) + end +end + +local function loadMap() + local mapname = game.GetMap() + + local foldername = "artery/maps/" .. mapname + ExecuteOnFolder(foldername,true,function(path) + --print("I want to run",path) + local filetxt = file.Read(path,"DATA") + --print("File text is", filetxt) + CompileString(filetxt,path)() + --print("I want to execute",path) + end) +end + +hook.Add("InitPostEntity", "artery_spawnmapnpcs", function() + loadMap() +end) + +concommand.Add("artery_reloadmap", function() + for k, v in pairs(removeents) do + local eot = ents.FindByClass(v) + + for i, j in pairs(eot) do + j:Remove() + end + end + + loadMap() +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 diff --git a/lua/autorun/tab.lua b/lua/autorun/tab.lua new file mode 100644 index 0000000..358715e --- /dev/null +++ b/lua/autorun/tab.lua @@ -0,0 +1,16 @@ +print("Hello from a lua refresh!") +if CLIENT then + + spawnmenu.AddCreationTab( "Artery", function(...) + + local panel = vgui.Create("DPanel") + + local zoneeditor = vgui.Create("DButton", panel) + zoneeditor:SetText("Zone Editor Tool") + zoneeditor:SetConsoleCommand("give","weapon_zone_designator") + zoneeditor:SizeToContents() + + + return panel + end ) +end diff --git a/lua/autorun/town.lua b/lua/autorun/town.lua new file mode 100644 index 0000000..2805f7c --- /dev/null +++ b/lua/autorun/town.lua @@ -0,0 +1,141 @@ +--[[ + This file loads and saves towns and stuff +]] +if engine.ActiveGamemode() ~= "sandbox" then return end +print("Hello from town.lua!") +local currentfile +--A fake nrequire +local npcs = {} +local fakes = { + ["sv_npcsystem.lua"] = { + CreateTownie = function(tbl) + print("got create townie table:") + PrintTable(tbl) + print("Spawning townie!") + --Make sure this townie dosen't already exist + for k,v in pairs(ents.FindByClass("info_towniespawn")) do + if v.File == currentfile then return end + end + --Spawn the townie editor + local e = ents.Create("info_towniespawn") + e:SetPos(tbl.Pos) + e:Spawn() + e.File = currentfile + e.data = {} + for k,v in pairs(tbl.NavNodes) do + e.data[#e.data + 1] = k + end + print("Ent's data is") + PrintTable(e.data) + end, + CreateNavNode = function(tbl) + print("got navnode table:",tbl) + PrintTable(tbl) + --Make sure this nav node dosen't already exist + for k,v in pairs(ents.FindByClass("info_edit_townienode")) do + print("Looking for nodes that connect to ", currentfile, v.File) + if v.File == currentfile then return end + end + --Spawn this navnode + local e = ents.Create("info_edit_townienode") + e:SetPos(tbl.Position) + e:Spawn() + e.File = currentfile + e.Name = tbl.Name + end, + CreateShop = function(tbl) + --Make sure this townie dosen't already exist + for k,v in pairs(ents.FindByClass("info_townieshop")) do + if v.File == currentfile then return end + end + --Spawn the townie editor + local e = ents.Create("info_towniespawn") + e:SetPos(tbl.Pos) + e:Spawn() + e.File = currentfile + end, + RegisterNPC = function(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, + CreateNPCByName = function(npcname, pos) + assert(npcs[npcname],string.format("No npc named %q, valid names are:\n%s",npcname,table.concat(table.GetKeys(npcs),"\n"))) + --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 + }, + ["inventory/item.lua"] = { + GetItemByName = function(string) + return {} + end + } +} +fakes["core/npc/sv_npcsystem.lua"] = fakes["sv_npcsystem.lua"] +local calls = {} +function nrequire(string) + print("nrequire called") + + local ntbl = {} + local nmeta = {} + nmeta.__index = function(self,key) + print("a table from nrequire was called",string,key) + local record = calls[string] + record[#record+1] = key + print("REturning", fakes[string][key]) + return fakes[string][key] + end + setmetatable(ntbl,nmeta) + calls[string] = ntbl + return ntbl +end + +local function ExecuteOnFolder(dir, recursive, func) + local path = "" + local fpath = table.concat({path,dir,"/*"}) + local files, directories = file.Find(fpath,"DATA") + for k,v in pairs(files) do + local callpath = table.concat({path,dir,"/",v}) + func(callpath) + end + if not recursive then return end + for k,v in pairs(directories) do + local npath = table.concat({dir,"/",v}) + ExecuteOnFolder(npath,true,func) + end +end + +function loadtownies() + --Remove any current townie things + for k,v in pairs(fakes) do + for i,j in pairs(ents.FindByClass(k)) do + j:Remove() + end + end + + local mapname = game.GetMap() + + local foldername = "artery/maps/" .. mapname + ExecuteOnFolder(foldername,true,function(path) + print("I want to run",path) + local filetxt = file.Read(path,"DATA") + print("File text is", filetxt) + currentfile = path + CompileString(filetxt,path)() + print("I want to execute",path) + end) +end + +concommand.Add("artery_loadtownies",loadtownies) +hook.Add("InitPostEntity","load_lua",loadtownies) 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 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 diff --git a/lua/autorun/zone_serverchanger.lua b/lua/autorun/zone_serverchanger.lua new file mode 100644 index 0000000..afb92a6 --- /dev/null +++ b/lua/autorun/zone_serverchanger.lua @@ -0,0 +1,84 @@ +--[[ + A server changer will "teleport" the player between instances +]] + +zones.RegisterClass("artery_serverchange",Color(255,255,255)) + +--Use this to set default properties. Only called on server. +hook.Add("OnZoneCreated","artery_serverchange",function(zone,class,zoneID) + if class == "artery_serverchange" then + zone.toserver = game.GetIPAddress() + zone.topos = Vector(0,0,0) + + 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_serverchange",function(zone,class,DPanel,zoneID,DFrame) + if class == "artery_serverchange" then + local w,h = 500, 400 + + local tobl = Label("To Server:") + tobl:SetParent(DPanel) + tobl:Dock(TOP) + tobl:SetTextColor(color_black) + tobl:SizeToContents() + + local to = vgui.Create("DTextEntry",DPanel) --parent to the panel. + to:Dock(TOP) + to:SetValue(zone.toserver) + function to:OnChange(new) + print("server's onvaluechanged has been called") + net.Start("artery_serverchange") + net.WriteFloat(zoneID) + net.WriteString(new) + net.SendToServer() + end + + local poslbl = Label("To position:") + poslbl:SetParent(DPanel) + poslbl:Dock(TOP) + poslbl:SetTextColor(color_black) + poslbl:SizeToContents() + + for k,v in pairs({"x","y","z"}) do + local post = vgui.Create("DTextEntry",DPanel) + post:SetValue(zone.topos[v]) + post:Dock(TOP) + post:SetNumeric( true ) + function post:OnChange(new) + print("Sending pos change") + net.Start("artery_poschange") + net.WriteFloat(zoneID) + net.WriteString(v) + net.WriteString(self:GetText()) + net.SendToServer() + end + 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_serverchange") + util.AddNetworkString("artery_poschange") + net.Receive("artery_serverchange",function(len,ply) + print("Server change received!") + local id, new = net.ReadFloat(), net.ReadString() + if not ply:IsAdmin() then return end + zones.List[id].toserver = new + zones.Sync() + end) + net.Receive("artery_poschange",function(len,ply) + print("poschange received!") + local id,v,w = net.ReadFloat(), net.ReadString(), net.ReadString() + if not ply:IsAdmin() then return end + zones.List[id].topos[v] = tonumber(w) or 0 + zones.Sync() + print("zone",id,"is now set to") + PrintTable(zones.List[id]) + end) +end diff --git a/lua/autorun/zone_town.lua b/lua/autorun/zone_town.lua new file mode 100644 index 0000000..a068021 --- /dev/null +++ b/lua/autorun/zone_town.lua @@ -0,0 +1,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 |
