Quick, simple question...

How do I network a function? For example, Set/Get Color, Set/Get Material, GetBonePosition, GetBoneMatrix, SetNoDraw, and the ManipulateBone functions all perform actions that are obviously on the client, but they can be called from the server. How does this work? Let’s say I want to make a function that sets an entity’s render bounds from the server; how would I do that?

The net system is to send flags between the client and the server. What you do is send a flag to the client from the server with instructions.

Those instructions can be interpreted on the client to call the client-side function. Don’t network functions, network instructions to call functions.

For setting render bounds, you can do that on the server. If you want the client to tell the server to do it…

As a crude example:

[lua]net.Start( “MessageName” )
net.WriteString( “SetRenderBounds” )
net.WriteString( Entity:EntIndex( ) )
net.SendToServer( )[/lua]

The server receives it

[lua]util.AddNetworkString( “MessageName” )
net.Receive( “MessageName”, function( byte, Player )
local _string = net.ReadString( )
local _entIndex = tonumber( net.ReadString( ) )
if ( _string == “SetRenderBounds” ) then
// Do something
Entity( _entIndex ):SetRenderBounds( vector_origin )
end
end )[/lua]

SetRenderBounds is client only… also, how would I get the net.Receive to the client / clients ??

It’s the same function. It can be called on the server or the client.

So if a server calls net.Broadcast( ), that message is sent to all clients. The client-side code needs to have a net.Receive for them to understand the message or to perform logic based on the message or contents. If the server calls net.Send( Player ), then it sends the message to one player, still though, the client-side code needs to have the net.Receive which correlates with that message.

Like-wise the other way around, if the client uses net.SendToServer( ), the server-side code needs a net.Receive which is for that particular message.

But how would I get the net.Receive to the clients?

Here’s a TTT end round music system I give out to users:

https://dl.dropboxusercontent.com/u/26074909/ttt_end_round.rar

It shows the server sending data, and the client receiving the data. I hope this helps.