Garry's Mod Wiki

net.Start

net.Start

  boolean net.Start( string messageName, boolean unreliable = false )

Description

Begins a new net message. If another net message is already started and hasn't been sent yet, it will be discarded.

Each net message has a length limit of 65,533 bytes (approximately 64 KiB) and your net message will error and fail to send if it is larger than this.

The message name must be pooled with util.AddNetworkString beforehand!

Net messages will not reliably reach the client until the client's GM:InitPostEntity hook is called.

Arguments

1 string messageName
The name of the message to send
2 boolean unreliable = false
If set to true, the message is not guaranteed to reach its destination

Returns

1 boolean
true if the message has been started.

Example

Adds a console command that sends a message to all clients.

if ( SERVER ) then util.AddNetworkString( "my_message" ) concommand.Add( "send_msg", function( ply, cmd, args, str ) if ( str == "" ) then str = "No message given" end net.Start( "my_message" ) net.WriteString( str ) net.WriteColor( ply:GetColor(), false ) net.Broadcast() end ) else net.Receive( "my_message", function( len, ply ) -- Important: reading in the same order as we write! local message = net.ReadString() local color = net.ReadColor( false ) print( "Message from server received." ) MsgC( color, message ) end ) end

Special Pages


Wikis

?

Render Time: 26ms

DB GetPage 3
Generate Html 6
SaveChanges (1) 6
Render Body 0
Render Sidebar 7