• .net libary questions
    14 replies, posted
Hello, I'm now trying to update myself on how the G13 works out, so I got a bit stuck with the new .net libary. I got this code in my serverside autorun/server folder: [lua] util.AddNetworkString( "test" ) function Send() net.Start("test") net.WriteString("test text") net.Broadcast() end concommand.Add("testnet", Send) [/lua] But when I do type testnet in game, it says command not found. I suppose something is wrong with the function, but I don't get any errors. Any ideas what I could've done wrong here? Thanks!
It's [b]net[/b], not .net or .NET They're completely different things. And this question is not related to the net library, it's about console commands...
show me the clientside part.
[QUOTE=SweetTea;38299770]show me the clientside part.[/QUOTE] The clientside part is irrelevant (for now), the concommand isn't recognized so there's a problem loading the file
[lua] function Receive() net.Receive( "test", function( length, client ) print( "I got it! It's:"..net.ReadString() ) end ) end hook.Add("Think", "Think", Receive) [/lua]
[QUOTE=Drakehawke;38299786]The clientside part is irrelevant (for now), the concommand isn't recognized so there's a problem loading the file[/QUOTE] Oh I'm a such fast reader -- Where'd you put the code?
Client: garrysmod/lua/autorun/client Server: garrysmod/lua/autorun/server
[QUOTE=Blt950;38299901]Client: garrysmod/lua/autorun/client Server: garrysmod/lua/autorun/server[/QUOTE] it's garrysmod/garrysmod/ not garrysmod/
[QUOTE=Blt950;38299790][lua] function Receive() net.Receive( "test", function( length, client ) print( "I got it! It's:"..net.ReadString() ) end ) end hook.Add("Think", "Think", Receive) [/lua][/QUOTE] Calling net.Receive just once is enough. The continuous checking part is handled by Garry.
[QUOTE=vercas;38300024]Are you serious? Calling net.Receive just once is enough. The continuous checking part is handled by Garry.[/QUOTE] As I said, new to net. Removed it now.
How are you running the server? Are you starting a singleplayer game/hosting multiplayer or using SrcDS? I find a lot of trouble trying to do both client and server specific things without a copy of SrcDS running. I don't know if the issue has been resolved in any update but when GM13 went live I found countless synching problems between client and local server. So try SrcDS if you aren't right now.
[QUOTE=KingofBeast;38301373]How are you running the server? Are you starting a singleplayer game/hosting multiplayer or using SrcDS? I find a lot of trouble trying to do both client and server specific things without a copy of SrcDS running. I don't know if the issue has been resolved in any update but when GM13 went live I found countless synching problems between client and local server. So try SrcDS if you aren't right now.[/QUOTE] Running a pretty clear version of SRCDS. I don't do such stuff in Gmod on Listed servers, they only mess up.
I used the If ( SERVER / CLIENT ) as a reference for you, so you know which is being called where. Technically speaking, this code can be shared: [lua] -- Localize dem variablz cuz i herd dey mak gud perform local concommand = concommand; local table = table; local net = net; local util = util; -- Add the network strings. if ( SERVER ) then util.AddNetworkString( "ServerToClient" ); util.AddNetworkString( "ClientToServer" ); end -- Serverside 'net.Receive' has two arguments, which is the sender and the length. if ( SERVER ) then net.Receive( "ClientToServer", function( t_Sender, t_Length ) MsgC( Color( 0, 255, 0, 225 ), "[Client->Server]: Received message from \"" .. t_Sender .. "\": " .. net.ReadString() ); end ); end -- Clientside 'net.Receive' only has one argument, which is the length. if ( CLIENT ) then net.Receive( "ServerToClient", function( t_Length ) MsgC( Color( 0, 255, 0, 225 ), "[Server->Client]: Received message from server: " .. net.ReadString() ); end ); end -- Broadcast the message to all players. if ( SERVER ) then local function BroadcastMessage( t_Message ) net.Start( "ServerToClient" ); net.WriteString( t_Message ); net.Broadcast(); end end -- Add the console command serverside. if ( SERVER ) then concommand.Add( "broadcast_message", function( t_Player, t_Command, t_Arguments ) if ( t_Arguments[1] ~= nil && #t_Arguments > 0) then BroadcastMessage( tostring( table.concat( t_Arguments, " " ) ) ); end end ); end -- Add the console command clientside. if ( CLIENT ) then concommand.Add( "send_message", function( t_Player, t_Command, t_Arguments ) if ( t_Arguments[1] ~= nil && #t_Arguments > 0) then net.Start( "ClientToServer" ); net.WriteString( table.concat( t_Arguments, " " ) ); net.SendToServer(); end end ); end[/lua]
You know that you can add all the server part in the same statement and all the client part in another one, right?
Stupid DumbAss Thats Not Even Valid Lua Code Wtf Are You Trying To Do
Sorry, you need to Log In to post a reply to this thread.