Gamemodes/addons with examples of good network optimization?

I’m trying to glance at how people actually set up stuff so that the numbers in the netgraph 3 aren’t 3k each time. Or if that isn’t that large of a number?

What kind of stuff are you trying to do? If I may offer a few good (according to me) tips regarding usage of net messages:

  • Obviously do not send net messages every frame/at a very short interval. If you want a value that updates constantly, you could have it sent every 1 second or so but have some sort of prediction on the client.

  • Only send net messages to the players that need it.

  • If you can, do not use

net.WriteTable. This should be only used if you the netmessage recipient doesn’t know the structure of the table. I’m saying this because for every value in a table, the function writes the type of that value so that net.ReadTable knows what to read. Here’s a code illustrating what I mean:

[lua]
// Let’s suppose you have a table (within a player) which contains various info, and you want to network that table.
local tableInfo = {
Experience = 0,
Level = 1,
Money = 0,
Job = “Citizen”,
}

// OPTION 1: Easiest option to use, net.WriteTable
// Reading/writing it is a one-liner, but costs a few more bytes to send the types of the key/values.
// This can get big real fast when trying to network whole tables.
if (SERVER) then
net.Start(“network_info”)
net.WriteTable(tableInfo)
net.Send(ply)
else
net.Receive(“network_info”, function()
local myinfo = net.ReadTable()
end)
end

// OPTION 2: Write the values individually, assuming the client knows what to expect and in what structure.
// This means this is the method you should favor when writing a table with a fixed structure,
// because the client knows what values he wants and in what form they are.
// That way you don’t need to network the type of the values he wants to read, thus saving on some bytes
// Slightly longer but always worth it
if (SERVER) then
net.Start(“network_info”)
net.WriteUInt(tableInfo.Experience, 32)
net.WriteUInt(tableInfo.Level, 16)
net.WriteUInt(tableInfo.Money, 32)
net.WriteString(tableInfo.Job)
net.Send(ply)
else
net.Receive(“network_info”, function()
local myinfo = {
Experience = net.ReadUInt(32),
Level = net.ReadUInt(16),
Money = net.ReadUInt(32),
Job = net.ReadString(),
}
end)
end
[/lua]

There are probably other things I could mention later on but that’s usually the first stuff I tell to people when they start using net messages. If you have any other questions I’ll (try to) answer them

You should always use the net library. That is basically it. Besides that, try not to send things multiple times to clients when they only need information once.

[editline]26th August 2016[/editline]

Shen beat me to it. Their explanation is a lot more detailed however, and I would agree with all that.

I’m trying to do a lot of things, most of it I shouldn’t be that worried about? But when I’m alone on the server it’s fine, it just seems like other people who use RP schemas have 3k on the netgraph sending all the time.

It generally boils down to a lot of entities/players on the map, a lot of add-ons (which ends up in increasing the number of stuff networked) or bad coding practice