Gmod Net.send and Net.recieve tutorials?

I was wondering if there was a place i can learn how to open derma with net.send and net.recieve as usermessage no longer works.
I just get


Warning: Unhandled usermessage 'test'

The code is:
In init.lua i have done


AddCSLuaFile("cl_teammenu.lua");

cl_teammenu.lua


function chooseteammenu()
	local TeamMenu = vgui.Create( "DFrame" )
	local choosebutton = vgui.Create( "DButton" )
		TeamMenu:SetPos( ScrW()/2 -150, ScrH()/2 -100 )
		TeamMenu:SetSize( 300, 200 )
		TeamMenu:SetTitle( "Team Selection" )
		TeamMenu:SetVisible( true )
		TeamMenu:SetDraggable( false)
		TeamMenu:ShowCloseButton( true )
		TeamMenu:MakePopup()
	end
end
usermessage.Hook( "test", chooseteammenu )


In init.lua:


include("shared.lua")

AddCSLuaFile("cl_init.lua");
AddCSLuaFile("shared.lua");
AddCSLuaFile("cl_teammenu.lua");

--Automatically setting teams on join.
function GM:PlayerInitialSpawn( ply )
 
    ply:SetTeam( 3 ) 
 
end
-- Opening the team menu
function GM:ShowSpare2( ply )	
	umsg.Start( "test", ply )
	umsg.End()
end

The wiki explains it pretty well.

Net Library Usage

Ok, thanks i really appreciate it :slight_smile:

[editline]22nd December 2013[/editline]

Well, i do know some more things about net libary’s, But i still cant open the derma menu using it. Thanks anyways man

[lua]
include(“shared.lua”)
util.AddNetworkString( ‘open_vgui’ )
AddCSLuaFile(“cl_init.lua”);
AddCSLuaFile(“shared.lua”);
AddCSLuaFile(“cl_teammenu.lua”);

–Automatically setting teams on join.
function GM:PlayerInitialSpawn( ply )

ply:SetTeam( 3 ) 

end
– Opening the team menu
function GM:ShowSpare2( ply )
net.Start( ‘open_vgui’ )
net.Send( ply )
end
[/lua]

[lua]
function chooseteammenu()
local TeamMenu = vgui.Create( “DFrame” )
local choosebutton = vgui.Create( “DButton” )
TeamMenu:SetPos( ScrW()/2 -150, ScrH()/2 -100 )
TeamMenu:SetSize( 300, 200 )
TeamMenu:SetTitle( “Team Selection” )
TeamMenu:SetVisible( true )
TeamMenu:SetDraggable( false)
TeamMenu:ShowCloseButton( true )
TeamMenu:MakePopup()
end
end
net.Receive( ‘open_vgui’, chooseteammenu )
[/lua]

Basically do util.AddNetworkString to use it, net.Start to start the transmission, send it to ply without writing anything, then just receive it.

Aye, as Arcaneex stated, you need to include this on the serverside; only once.
[lua] util.AddNetworkString( ‘name’ ) [/lua ]

Sending it from Client to server, something usermessages didn’t do is roughly similar. You still need to create a networkString, however, the receive goes on the serverside.

Server:
[lua]
–[[ Net Message Prep. ]]–
util.AddNetworkString( ‘clientToServer’ )

–[[ Receive from Server ]]–
net.Receive( ‘clientToServer’, function()

	--blah

end )

[/lua]

Client:
[lua]
–[[ Send to Server ]]–
function mycoolthing()

	net.Start( 'clientToServer' )
	net.WriteEntity( LocalPlayer() )
	net.SendToServer()

end

[/lua]
Note that it uses net.SendToServer(), rather than just net.Send( ent ). Normally, you write the entity of the player to specifically use them on the serverside content as well.

Note, you don’t (and shouldn’t) send the LocalPlayer() in your netmessage from client to server. The second argument of the function in net.Receive is the player being received from. The first is the length of the message in bytes. Doing it the above way is a security flaw.



net.Receive("clientToServer", function(length, sender)
end)

function mycoolthing()
	
		net.Start( 'clientToServer' )
		net.SendToServer()
	
	end


Net messages received by the client obviously don’t have a sender and only have the length argument.

May have worded that wonky; meant it more as you if you want the server to do something specific to the client who did the clientside action you can use net.WriteEntity( ent ) of the player or object. Alternatively, you can write their ID as a string and compare it to every player’s ID and fit it accordingly.

Ok thanks, P.s: Love your youtube lua series :slight_smile:

Just tried it out, No errors in my server console or in game console.
Just the vgui does not open.

I have checked all the names


function dermatest()
	local TeamMenu = vgui.Create( "DFrame" )
		TeamMenu:SetPos( ScrW()/2 -150, ScrH()/2 -100 )
		TeamMenu:SetSize( 300, 200 )
		TeamMenu:SetTitle( "Team Selection" )
		TeamMenu:SetVisible( true )
		TeamMenu:SetDraggable( false)
		TeamMenu:ShowCloseButton( true )
		TeamMenu:MakePopup()
	end
end
net.Receive( 'open_teammenu', dermatest )


include("shared.lua")
AddCSLuaFile("cl_init.lua");
AddCSLuaFile("shared.lua");
AddCSLuaFile("cl_teammenu.lua");
util.AddNetworkString( 'open_teammenu' )

--Automatically setting teams on join.
function GM:PlayerInitialSpawn( ply )
 
    ply:SetTeam( 3 ) 
 
end

function GM:ShowSpare2( ply )	
	net.Start( 'open_teammenu' )
	net.Send( ply )
end

Thats what is currently running

Are you sure there’s no errors? Because there seems to be an extra “end” in your cl_teammenu.lua that will most definitely trigger a syntax error.

From what i see the first end closes the derma menu, the second one closes the function, Or am i wrong?

you’re wrong, you only need an end to ‘close’ the function.

Ok, i will try removing the tabbed end

also make sure you’re including cl_teammenu.lua in cl_init.lua, otherwise nothing will happen!

At my first post they are included already :stuck_out_tongue:

[editline]22nd December 2013[/editline]

No success, I cant see whats wrong

No I mean you need include(“cl_teammenu.lua”) in your cl_init.lua, which you haven’t shown us and I’m assuming given your initial error that it isn’t there.

Oh my god i feel dumb, Thanks for the help. I can now get started.
Thanks matt i looooove you :wink: