Hey guys,
would it be a bad practice to make something like this?:
[CODE]
hook.Add("PlayerDeath", "stuff", function()
...CODE...
net.Start("Info")
net.WriteTable(Kill_Info)
net.Broadcast()
end
[/CODE]
I wanted to send some info to the client everytime the player dies, would this be ok?
Thanks in Advance :)
Make your net message name more unique and instead send each piece of data you need; don't use WriteTable.
[QUOTE=code_gs;52373133]Make your net message name more unique and instead send each piece of data you need; don't use WriteTable.[/QUOTE]
Thanks for the info :)
Should I always discard WriteTable and send them separately?
[QUOTE=Pwned231;52374459]Thanks for the info :)
Should I always discard WriteTable and send them separately?[/QUOTE]
WriteTable is fine for debugging but for anything else it can be incredibly slow and clog up the network.
[QUOTE=Pwned231;52374459]Thanks for the info :)
Should I always discard WriteTable and send them separately?[/QUOTE]
You should try to avoid it when possible since you know the structures of most tables you're sending. It just adds a lot of extra bloat since it has to send the length of the table and the type of each value.
[QUOTE=code_gs;52374951]You should try to avoid it when possible since you know the structures of most tables you're sending. It just adds a lot of extra bloat since it has to send the length of the table and the type of each value.[/QUOTE]
But between doing this:
[CODE]
for i=1, 20 do
net.Start("XP_PlayerDeathInfo")
net.WriteInt(InfoTest)
net.Broadcast()
end
[/CODE]
and
[CODE]
net.Start("XP_PlayerDeathInfo")
net.WriteTable(InfoTestTable)
net.Broadcast()
[/CODE]
WriteTable is the best no?
[QUOTE=Pwned231;52375824]But between doing this:
:snip:
and
:snip:
WriteTable is the best no?[/QUOTE]
You can send multiple values in a single net message. [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteTable]net.WriteTable[/url] will in 99.9% of cases be worse than sending the values in a structured way. The 0.1% of cases are when the keys and values you're sending are very sporadic and have absolutely no order or relation.
Pwned, instead of doing either of those. You should write number of values in say 8 bits, then loop through the data within the player sending just the number of bits necessary.
[CODE]net.Start("PlayerDeathInfo");
net.WriteInt(20, 8);
net.WriteInt(val1, 8);
net.WriteInt(val2, 8);
-- Do until val20
net.Broadcast();[/CODE]
Remember every bit doubles the prior value: (Although please consider whether it's signed or unsigned ((- & +) or +)
1 = 2 unsigned (0 or 1)
2 = 4 unsigned
3 = 8 unsigned
4 = 16 unsigned
...
8 = 256 unsigned [B]or[/B] -127 to 128 signed
16 = 65,535 unsigned [B]or[/B] −32,768 to 32,767 signed
...
Ok guys just one more question.
Can I use the same:
[CODE]
net.Start("JustATest123")
[/CODE]
In 2 different hooks?
I wanted to start the same "JustATest123" in 2 different files basically.
If you have the same send structure, yes.
[QUOTE=Pwned231;52376654]Ok guys just one more question.
Can I use the same:
[CODE]
net.Start("JustATest123")
[/CODE]
In 2 different hooks?
I wanted to start the same "JustATest123" in 2 different files basically.[/QUOTE]
You'll probably want to make a server-sided wrapper function which basically takes a player(s) and would send the information relevant to that player(s). So you could easily reuse it at any time.
Thanks for everything guys <3
Sorry, you need to Log In to post a reply to this thread.