EDIT: I replaced my usage of byte with bit as that is actually what i'm looking for.
First Creating and sending a packet as such.
Code: Select all
net.Begin( "UpdatePlayer" ) - Converted to a numeric header for the packet and starts my packet assembler. (This method will allow custom net packets for modders to use)
net.Write( 127 , 8 ) -- First is the value to send, Second is the number of bits. (Will be unsigned regardless no negative numbers needed)
net.Send() - Send the packet to the specified targets on server or to server on client and clears the packet assembler.
net.Broadcast() - Send the packet to all clients on the server except for specified. (would be called in place of 'net.Send()')
Code: Select all
net.Receive( "UpdatePlayer" , function()
local value = net.Read( 8 ) -- Read the first eight bits which would return the 127 value.
end )
Code: Select all
net.WriteString = function( txt )
net.Write( string.len( txt ) , 8 ) -- Send the length of the string up to 255 characters.
for k , c in pairs( txt ) do
net.write( string.byte( c ) , 8 ) -- Here would be a converter to binary from string.
end
end
net.ReadString = function()
local len = net.Read( 8 ) -- Read the length of the string from the first byte.
local txt = {}
for i = 1 , len do
txt[ i ] = string.char( net.Read( 8 ) )
end
return table.concat( txt )
end