GMod’s Networked Vars

Right now in GMod the entity’s custom variables are networked using an internal usermessage system. When you join the server it sends you a bunch of usermessages containing all the entity’s variables, then after that it sends updates every time the entity changes. This isn’t ideal, but it was the best I could do at the time, since the default network code wasn’t able to handle the amount of variables we needed on some things.

But this presents a problem when dealing with prediction, because the new networked vars might arrive early, or late, and be processed by the wrong tick etc. So networked vars don’t work well for that stuff.

So in the next update I’ve added DTVars, Data Table Vars. The base entity in GMod has a 24 extra variables on it, networked. This is kind of icky, but it’s the best way to do it. There’s 4 of each type available – int, float, vector, angle, ehandle, bool. On the ground level there’s functions for each type to get and set these variables – ent:SetDTBool( int, value ) – ent:GetDTBool( int ).

Higher up, in SENTs, to make things easier, things work like this (this funtion gets automatically called at the right times (in initialize and onrestore))

function ENT:SetupDataTables()

self:DTVar( "Int", 0, "Key" );
self:DTVar( "Bool", 0, "On" );
self:DTVar( "Vector", 0, "vecTrack" );
self:DTVar( "Entity", 0, "entTrack" );
self:DTVar( "Entity", 1, "Player" );

end

Then you can access them via -

self.dt.Key
self.dt.On
self.dt.vecTrack

- just like they were normal variables – except they will be automatically syced between client and server.

I’m recommending that if you can fit all your SENT/SWEP’s data in this variables, then use them. They’re the best option for networked variables. String data, or other variables should use the old method.