Server Switcher

Hello fellows,

I’ve never touched one line of lua code, but I really need something I’ve never found before (even by searching ! incredible !)
So, as I get more two GMod servers, I thought it should be great if we could switch from one to another by writing a command or clicking on a button… The first one is a Sandbox and the other one is a Fretta gamemodes one.
After some thoughts, the best way to do this might be from a command wirtten in the chatbox, because it won’t overweight the interface, and is quite simple to do still. Well, actually I can do it by passing through the motd, on which I put steam links to the servers, but it isn’t sexy at all…
So, if someone can code this more or less fastly, I hope this will be useful to more than a person :slight_smile:


simple enough, PM me your server ips/names

Someone’s already on the case, he’s doing something awesome :slight_smile:
Thanks though.

Here’s something simple, that should do what you want:

[lua]local Servers = {
{serv=“rp”, ip=“”, fullname=“DarkRP”},
{serv=“roleplay”, ip=“”, fullname=“DarkRP”}
hook.Add(“OnPlayerChat”,“ChangeServer”,function(ply, msg)
if not (ply == LocalPlayer()) then return end

msg = string.lower(msg)
if (string.Left(msg,6) == "/join ") then
	local join = string.sub(msg, 7)
	for _,v in pairs( Servers ) do
		if (join == v.serv) or (join == string.lower(v.fullname)) then
			chat.AddText( Color(50,100,255), "Joining ", Color(50,255,100), v.fullname, Color(255,100,50), "!")
			timer.Simple(5, ply:ConCommand("connect " ..v.ip) )
	chat.AddText( Color(255,100,50), "Server not found!")


Just edit the Servers table, and add your servers, then put it in a client-side file

ply:ConCommand("connect "), is blocked, if I remember correctly

Nope, I tested it, it worked

I made the same mistake in another thread. For some strange reason, it’s only blocked using RunConsoleCommand()

/Server Sided/

local Servers = {
roleplay = “ip”;
build = “ip”;
ttt = “ip”;

hook.Add(“PlayerChat”, “JoinListener”, function(ply, txt, pub)
local chattab = string.Explode(" ", text)

if( chattab[1] == "/join" ) then
	table.remove(chattab, 1);

	local sChoice 	= string.lower( chattab[2] );
	if( Servers[ tostring( sChoice ) ] ) then 
		chat.AddText(Color(146, 236, 0), "Joining ", Color(18, 62, 171), sChoice, Color(251, 0, 13), "!")
		timer.Simple(3, function()
			ply:ConCommand("connect "..Servers[ tostring( sChoice ) ]);

	return "";


[editline]22nd January 2012[/editline]

Can you say… Unnecessary looping?