Server Switcher

Hello, im looking for a derma menu where you can select a server from a list, and it will connect you to one. and to open the menu by sayin “/servers” any help would be greatly appreciated :slight_smile:

[editline]08:57PM[/editline]

anybody?

I can do this, but do you want buttons that connect you to a certain server, Or something else?

[lua]local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 200, 250 )
DermaPanel:SetTitle( “connect to other server” )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()

local DermaButton = vgui.Create( “DButton” )
DermaButton:SetParent( DermaPanel )
DermaButton:SetText( “Some server” )
DermaButton:SetPos( 25, 50 )
DermaButton:SetSize( 150, 50 )
DermaButton.DoClick = function ()
LocalPlayer():ConCommand( “connect 192.168.1.1:27015” )–server ip here
end[/lua]

Don’t forget to include the function. -.-

and actually, a better way to do it is:
[lua]
hook.Add(“PlayerSay”, “Cmd”, function(pl,text)
if string.find(text, string.sub( “/connect”, 1) ) then
pl:ConCommand( string.sub( text, 2 ) ) return false
end
end)
[/lua]
I’ve just tested it, and it works.

cool thanks guys

[editline]11:42AM[/editline]

is this server side or client side, + if i wanted more than one server how would it look?

[editline]12:01PM[/editline]

  • can you tell me what to put the codes in and where please

im posting this on behalf of flapjack

that’s a good way to do it :stuck_out_tongue:

The code appears to have been wrecked by copy/pasting.

Now I’m unbanned, here it is.

[lua]// I would post this myself but unfortunately I’m banned.

local servers = { {name = “My server” , IP = “188.165.193.84:27023” },
{name = “My other server” , IP = “188.165.193.84:27014”}
}

concommand.Add(“servermenu” , function()

local dframe = vgui.Create("DFrame")
dframe:SetSize(ScrW() / 2 , ScrH() / 3)
dframe:SetTitle("Server Switcher")
dframe:Center()
dframe:MakePopup()

local dlistview = vgui.Create("DListView")
dlistview:SetParent(dframe)
dlistview:SetPos(0 , 22)
dlistview:AddColumn("Server")
dlistview:AddColumn("IP")

for k , v in pairs(servers) do
	dlistview:AddLine(v.name , v.IP)
end

dlistview.OnRowSelected = function(self , row)
	LocalPlayer():ConCommand("connect "..self:GetLine(row):GetValue(2))
end

end )[/lua]

thank you flapjack :slight_smile:

Forgot to SetSize the DListView. Just realised. Just pop in dlistview:SetSize(ScrW() / 2 , ScrH() / 3 - 22)