so I have few servers for my community but I dont know how to make a simple script which will allow users to join from TTT to like darkrp server
just by typing in game command such as !joindarkrp etc
how to create simple script like this? and where would I have to place it within the files?
Make your command (I don't know how you will/what you will do it with) and try adding this
[code]LocalPlayer():ConCommand("connect [ip here]")[/code]
PlayerSay hook on the server to detect it, send a net message to client, on the receive add LocalPlayer:ConCommand( "connect <IP>" )
Try this:
[code]hook.Add( "PlayerSay", 0, function( ply, text, team )
if ( string.sub( text, 1, 11 ) == "!joindarkrp" ) then
return LocalPlayer():ConCommand("connect [ip]")
end
end )[/code]
[QUOTE=imacc2009;45023939]Try this:
[code]hook.Add( "PlayerSay", 0, function( ply, text, team )
if ( string.sub( text, 1, 11 ) == "!joindarkrp" ) then
return LocalPlayer():ConCommand("connect [ip]")
end
end )[/code][/QUOTE]
hmmm:L either Im putting this in wrong file or the script doesnt work:L I bet its probably the first one
[QUOTE=snakethetroll;45024015]hmmm:L either Im putting this in wrong file or the script doesnt work:L I bet its probably the first one[/QUOTE]
Do you get any errors when using it?
[editline]7th June 2014[/editline]
Oh, try removing the "return" before the LocalPlayer()
[QUOTE=imacc2009;45024028]Do you get any errors when using it?
[editline]7th June 2014[/editline]
Oh, try removing the "return" before the LocalPlayer()[/QUOTE]
nah, no errors just typing down the command results into nothing
tried removing return same thing
Replace LocalPlayer() with ply
[QUOTE=imacc2009;45023939]Try this:
[code]hook.Add( "PlayerSay", 0, function( ply, text, team )
if ( string.sub( text, 1, 11 ) == "!joindarkrp" ) then
return LocalPlayer():ConCommand("connect [ip]")
end
end )[/code][/QUOTE]
PlayerSay is a serverside hook, and LocalPlayer is for clientside. Modify it so it sends a net message to the client, so it would be like so:
[B]autorun/sh_joinotherserver.lua[/B]
[lua]
if SERVER then
util.AddNetworkString( "joinotherserverone" )
hook.Add( "PlayerSay", 0, function( ply, text, team )
if ( string.sub( text, 1, 11 ) == "!joindarkrp" ) then
net.Start( "joinotherserverone" )
net.Send( ply )
return false
end
end )
end
if CLIENT then
net.Receive( "joinotherserverone", function( len )
LocalPlayer():ConCommand("connect [ip]")
end )
end
[/lua]
Its a shared file, so make sure its called on both server & client (if its not in the autorun folder)
[QUOTE=Sm63;45024821]Replace LocalPlayer() with ply[/QUOTE]
IIRC you can't make use connect with concommand on the server because its blocked (I think)
you could always just use OnPlayerChat clientside, something like this (not tested)
[LUA]
local servers = {
["darkrp"] = "192.168.0.1",
["ttt"] = "fsfkjsjbfk"
}
hook.Add( "OnPlayerChat", "ServerHop", function( ply, text )
local ip = servers[text:sub( 7 )]
if text:find( "^[!/]join%s" ) and ip then
if ply == LocalPlayer() then ply:ConCommand( ("connect %s"):format( ip ) ) end
return true
end
end )
[/LUA]
then !join darkrp
Sorry, you need to Log In to post a reply to this thread.