Hey guys, I'm wondering could someone help me out on this one? Pretty much all that I need is a chat command to run a console command.
What this is for is you type !connect Darkrp then it runs the console command connect "ip".
Thanks in advance
Dave
[lua]
function ConnectToAnotherServer ()
RunConsoleCommand ("connect" ,"127.0.0.1")
end
hook.Add( "PlayerSay", "!conect darkrp", ConnectToAnotherServer );
[/lua]
your welcome
by the way this is serverside so just in case you don't know where to put it . you can simply add it in a serverside lua script or simply make one and put it in
garrysmod\lua\autorun\server\WhateverNameYouWantToCallIt.lua
[QUOTE=gravelhunter;36130261]
function ConnectToAnotherServer () RunConsoleCommand ("connect" ,"127.0.0.1") end hook.Add( "PlayerSay", "!conect darkrp", ConnectToAnotherServer );
your welcome
by the way this is serverside so just in case you don't know where to put it . you can simply add it in a serverside lua script or simply make one and put it in
garrysmod\lua\autorun\server\WhateverNameYouWantToCallIt.lua[/QUOTE]
That won't work, it will try to run "connect" on the server which I think will do nothing.
You'll want to use ply:ConCommand( "connect 127.0.0.1" ), but I'm fairly sure "connect" is a blocked command.
Also that's not how... that hook... works...
[LUA]
hook.Add("PlayerSay","DarkRPConnect",function(ply,str,public)
if string.sub(str:lower(),1,9)=="!connect " then
ply:SendLua[[LocalPlayer():ConCommand("connect "..string.gsub(str,"!connect ",""))]]
return ""
end
end)
[/LUA]
Untested, but it should work.
[QUOTE=gravelhunter;36130261]
[lua]
function ConnectToAnotherServer ()
RunConsoleCommand ("connect" ,"127.0.0.1")
end
hook.Add( "PlayerSay", "!conect darkrp", ConnectToAnotherServer );
[/lua]
[/QUOTE]
FYI, the second arg on hook.Add is the unique name.
[QUOTE=BL00DB4TH;36130367]That won't work, it will try to run "connect" on the server which I think will do nothing.
You'll want to use ply:ConCommand( "connect 127.0.0.1" ), but I'm fairly sure "connect" is a blocked command.
Also that's not how... that hook... works...[/QUOTE]
im sorry to tell you but it does work . I have tested it out before I posted it and it works . try it yourself
[QUOTE=gravelhunter;36131027]im sorry to tell you but it does work . I have tested it out before I posted it and it works . try it yourself[/QUOTE]
Have you tested it in singleplayer?
my apologies for arguing BL00DB4TH it diddn't work it just drops me when i leave
Hi, Thank you for your comments guys.
I used
[LUA]
hook.Add("PlayerSay","DarkRPConnect",function(ply,str,public)
if string.sub(str:lower(),1,9)=="!connect " then
ply:SendLua[[LocalPlayer():ConCommand("connect "..string.gsub(str,"!connect ",""))]]
return ""
end
end)
[/LUA]
It never worked could you help me out please? :D
[editline]30th May 2012[/editline]
I've changed my mind, I'f that's okay :D
Gonna do !servers - opens a simple derma panel with each server listed click the server you wish to connect to then click the button connect. I can do all the derma crap just not sure how to get the chat command to work and the connect command to work.
Thanks again guys
I just whipped up this script, just in case you changed your mind:
[lua]
hook.Add("OnPlayerChat", "ChangeServers", function( ply, text, bTeamOnly, bPlayerIsDead )
/////////////---------How to add a Server to the list------------\\\\\\\\\\\\\\\\\\\\\\
/////////////["MyDarkRPServer"] = {"darkrp", "iptodarkrp"}
//////1.Specifies what its for| 2.Name of command after !connect | 3. The IP.^
//////DO NOT PUT A SPACE BEFORE THE --IP-- IN THE TABLE OR IT WILL NOT WORK.
//////Ex: "_5.121.194.121"
local servers = {
["MyDarkRPServer"] = {"darkrp", "iptodarkrp"},
["My2ndDarkRPServer"] = {"darkrp2", "iptodarkrp2"}
}
local explode = string.Explode(" ", text)
for k,v in pairs(servers) do
if explode[1] == "!connect" and explode[2] == servers[k][1] then
ply:ConCommand("connect "..servers[k][2])
end
end
end)
[/lua]
Oh nice thanks I give this ago quick :D
And yeah i did change my mind lol, Just finished the derma panel tbh ha. Thank for the reply
[QUOTE=DeathRowDave2;36132334]Oh nice thanks I give this ago quick :D
And yeah i did change my mind lol, Just finished the derma panel tbh ha. Thank for the reply[/QUOTE]
Yeah no problem. If you have any troubles with it(you shouldn't) just post the error. :)
Will do, thanks again
[editline]30th May 2012[/editline]
My mates thats testing on my server he says nothing happens when he types !connect. I uploaded the file to lua/autorun/server
[LUA]
hook.Add("OnPlayerChat", "ChangeServers", function( ply, text, bTeamOnly, bPlayerIsDead )
/////////////---------How to add a Server to the list------------\\\\\\\\\\\\\\\\\\\\\\
/////////////["MyDarkRPServer"] = {"darkrp", "iptodarkrp"}
//////1.Specifies what its for| 2.Name of command after !connect | 3. The IP.^
//////DO NOT PUT A SPACE BEFORE THE --IP-- IN THE TABLE OR IT WILL NOT WORK.
//////Ex: "_5.121.194.121"
local servers = {
["DarkRP"] = {"darkrp", "109.169.29.210:27015"},
["ZombieSurvival"] = {"Zombie Survival", "109.169.29.102:27035"},
["TTT"] = {"Trouble In Terrorist Town", "93.186.204.38:27015"}
}
local explode = string.Explode(" ", text)
for k,v in pairs(servers) do
if explode[1] == "!connect" and explode[2] == servers[k][1] then
ply:ConCommand("connect "..servers[k][2])
end
end
end)
[/LUA]
[QUOTE=DeathRowDave2;36132417]Will do, thanks again
[editline]30th May 2012[/editline]
My mates thats testing on my server he says nothing happens when he types !connect. I uploaded the file to lua/autorun/server
[LUA]
hook.Add("OnPlayerChat", "ChangeServers", function( ply, text, bTeamOnly, bPlayerIsDead )
/////////////---------How to add a Server to the list------------\\\\\\\\\\\\\\\\\\\\\\
/////////////["MyDarkRPServer"] = {"darkrp", "iptodarkrp"}
//////1.Specifies what its for| 2.Name of command after !connect | 3. The IP.^
//////DO NOT PUT A SPACE BEFORE THE --IP-- IN THE TABLE OR IT WILL NOT WORK.
//////Ex: "_5.121.194.121"
local servers = {
["DarkRP"] = {"darkrp", "109.169.29.210:27015"},
["ZombieSurvival"] = {"Zombie Survival", "109.169.29.102:27035"},
["TTT"] = {"Trouble In Terrorist Town", "93.186.204.38:27015"}
}
local explode = string.Explode(" ", text)
for k,v in pairs(servers) do
if explode[1] == "!connect" and explode[2] == servers[k][1] then
ply:ConCommand("connect "..servers[k][2])
end
end
end)
[/LUA][/QUOTE]
The hook is Clientside not Serverside, just place it in lua/autorun/client instead and it should be good to go. Also when you put down "Zombie Survival", make it [U]one word[/U] instead of [U]2[/U] because it is [U]looking for the first word[/U] and makes it simpler to the user who is typing it out.
Edit:
You said nothing happens when he types "!connect" well of course not.. You need to type "!connect darkrp" for anything to function properly. I would explain this better but i'm eating my lunch. :rolleyes:
Aaaah okay didnt notice that haha, so should i also change the trouble in terrorist town to TTT to?
[QUOTE=DeathRowDave2;36133330]Aaaah okay didnt notice that haha, so should i also change the trouble in terrorist town to TTT to?[/QUOTE]
In my opinion it would be easier to do:
[lua]
local servers = {
["DarkRP"] = {"darkrp", "109.169.29.210:27015"},
["ZombieSurvival"] = {"zs", "109.169.29.102:27035"},
["Trouble In Terrorist Town"] = {"ttt", "93.186.204.38:27015"}
[/lua]
Hehe thanks bro :D when I thought it wasnt working i carried on with my menu - [url]http://i.imgur.com/PvDiH.png[/url] what you think haha
[editline]30th May 2012[/editline]
Also you think i could maybe add you on steam?
Check your mail.
[QUOTE=DeathRowDave2;36133476]Hehe thanks bro :D when I thought it wasnt working i carried on with my menu - [url]http://i.imgur.com/PvDiH.png[/url] what you think haha
[editline]30th May 2012[/editline]
Also you think i could maybe add you on steam?[/QUOTE]
Perhaps you should try another selection of colors?
[QUOTE=Crap-Head;36133660]Perhaps you should try another selection of colors?[/QUOTE]
Yeah I will do I was messing around with the colors lol, any ideas on what color to set it to?
I know this is a bit of an old thread now, but I need something like this on the TTT server I'm a Co-owner on.
Basically, I edited the lua code to the commands and the IPs that I want to connect to, it works BUT it sends EVERY PLAYER in my team to another server instead of just myself. I was hoping to use it on the other servers, so we can hop from server to server in effect.
I'm a novice with programming in lua, so a lot of help would be appreciated.
-JamesFromTheUK
Yeah 2 year bump is a bit much...
This method of doing it is old and probably not the best. I would use a PlayerSay hook that then tells the player that said it to run "connect" to a server. I'm on mobile otherwise I would help more
I've read numerous times that "connect" is blocked in some way? I don't know if that's still true now. Any help with the code will be much appreciated.
Yes its blocked, no there is no way that I know of to get around this (short of cvar3). Stop bumping this.
[QUOTE=G4MB!T;45585984]Yes its blocked, no there is no way that I know of to get around this (short of cvar3). Stop bumping this.[/QUOTE]
but I do:
[code]
LocalPlayer():ConCommand("connect ip")
[/code]
Interesting. I thought recently Robot said it was block.
Only for RunConsoleCommand iirc
Sorry, you need to Log In to post a reply to this thread.