• Whats the best way to display data clientside
    13 replies, posted
For example, if I have a variable serverside called pl.Money, and I want to display every players money clientside on a scoreboard or whatever, what would be the best way to do it?
Using the Net Library. Not sure what would be the best way to keep it synchronized, maybe to avoid sending the data everytime the scoreboard is opened (which can be pretty often), you can be checking in a interval serverside if a player's money changes (or there can be a hook, depending onthe gamemode), and when it changes, broadcast it to every client, and when someone opens the scoreboard, he will see the proper amount of money for every player.
ent:SetNW2Int()
I don't think that's a good idea for a scoreboard -- IIRC entities that use NWVar2 only update when they're in the player's PVS.
Oh? what's PVS?
Transmitting all entity updates to all clients would be an unnecessary waste of bandwidth, as a player usually sees only a small subset of the world. In general a server needs to update only entities that are in the local vicinity of a player, but there are also cases where an entity is only of interest to players on a certain team or of a certain combat class. Areas or rooms visible from a player's position are called the Potential Visiblity Set. Networking Entities
You should only use NW(2)Vars and DTVars/NetworkVars for predicted data that will be set shared. Data sent purely serverside to clientside should be updated with the network library.
Always learning something - what's the reason for that? Do NW2Vars not simply get sent (once) straight to the clients whenever set serverside? What else do they do?
Their value is sent every few seconds from the server to client to verify the client's correctness of the value. As such, the client should already have calculated a close approximation of the server's value using predicted functions and hooks. Since the value is not immediately networked, you will experience worse results than the net library, as well as prediction errors which you can see with cl_showerror 2. The value of the NWVars/DTVars will also be reverted clientside in predicted hooks where IsFirstTimePredicted is false, which can cause some unforeseen behaviour if you're using the vars for things like money, player name, etc. More info can be found here.
thats some golden information that I somehow overlooked, thanks!
Their value is sent every few seconds from the server to client to verify the client's correctness of the value. Is this how source handles networkvars or is this how the devs decided to implement networkvars in gmod?
This is how CNetworkVars are implemented in Source - they send data as "snapshots."
Yes, but what do you mean by sent every few seconds? Are NW2Vars sent to the client even when they didn't change on the server? Also, if you're going to use net messages to synchronize state and want to support demos properly, you need to resend the net messages after the recording starts.
Data is packed into a snapshot and sent to the client every second to a few seconds - depends on net load and interp. NWVars are sent every so often to verify the client's correctness of the value, even if the value hasn't changed on the server. I don't remember if NW2Vars do this or not.
Sorry, you need to Log In to post a reply to this thread.