Entity:NetworkVar
Description
Creates a network variable on the entity and adds Set/Get functions for it. This function should only be called in ENTITY:SetupDataTables.
See Entity:NetworkVarNotify for a function to hook NetworkVar changes.
So if you use the PVS(default), then the NetworkVars can be different for each client.
Combining this function with util.TableToJSON can also provide a way to network tables as serialized strings.
Default Arguments
String
(up to 511 characters)Bool
Float
Int
(32-bit signed integer)Vector
Angle
Entity
0
, a bool in slot 0
and a float in slot 0
etc. You can't have two ints in slot 0
, instead you would do a int in slot 0
and another int in slot 1
.
The max slots for strings 4
- so you should pick a number between 0
and 3
.
The max slots for everything else 32
- so you should pick a number between 0
and 31
.
This can be omitted entirely (arguments will shift) and it will use the next available slot.
Foo
you would add two new functions on your entity - SetFoo()
and GetFoo()
. So be careful that what you call it won't collide with any existing functions (don't call it Pos
for example).KeyName
- Allows the NetworkVar to be set using Entity:SetKeyValue.
- This is required for the entity editing to work.
This is useful if you're making an entity that you want to be loaded in a map. The sky entity uses this.
Edit
- The edit key lets you mark this variable as editable. See Editable Entities for more information.
Argument Overload: Slot argument is omitted
String
(up to 511 characters)Bool
Float
Int
(32-bit signed integer)Vector
Angle
Entity
Foo
you would add two new functions on your entity - SetFoo()
and GetFoo()
. So be careful that what you call it won't collide with any existing functions (don't call it Pos
for example).KeyName
- Allows the NetworkVar to be set using Entity:SetKeyValue.
- This is required for the entity editing to work.
This is useful if you're making an entity that you want to be loaded in a map. The sky entity uses this.
Edit
- The edit key lets you mark this variable as editable. See Editable Entities for more information.
Example
Setting up data tables