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_serverchanger.lua | 84 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 lua/autorun/zone_serverchanger.lua (limited to 'lua/autorun/zone_serverchanger.lua') 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 -- cgit v1.2.3-70-g09d2