• Sending argumets via ConCommand
    3 replies, posted
I have failed miserably in creating arguments that are being sent to the server from the client and vice versa. So I need an example how to send some args through ConCommand or RunConsoleCommand or some other way. an explanation or example would really help.
First of all, you'll need to know that RunConsoleCommand( cmd, args ) ([url]http://wiki.garrysmod.com/page/Global/RunConsoleCommand[/url]) handles arguments a bit differently to Player:ConCommand( cmd ) ([url]http://wiki.garrysmod.com/page/Player/ConCommand[/url]). Unlike Player:ConCommand, with RunConsoleCommand you must pass each argument as a new string, not separating them with a space. For example: [CODE] RunConsoleCommand( "developer", "1" ) [/CODE] Compared to how you would do it with Player:ConCommand: [CODE] Player:ConCommand( "developer 1" ) [/CODE] I hope that helps. :)
I'd recommend using net messages to communicate with the server and to receive responses. Here's an example: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/networking/networking_booleans.lua.html[/url]
[lua]//examples of args being sent to/from server //1 //server to client via sendlua local args = "you are gay" for k, v in pairs(player.GetAll()) do v:SendLua([[RunConsoleCommand("say", ]] args [[)]]) end //2 // client to server via networking //server util.AddNetworkString("a") net.Receive("a", function(len, ply) local str = net.ReadString() print(str) end) //client net.Start("a") net.WriteString("true") net.SendToServer() [/lua] hope this might help somewhat
Sorry, you need to Log In to post a reply to this thread.