Are networked values working properly?

Is it me or the networked variables (SetNWBool, SetNetworkedBool) are not working properly since Garry’s Mod updated?
When I try to send a networked variable to the client, sometimes it doesn’t work:

We don’t see the seconds on the timer, but after 30 seconds, the C4 explodes!
1/3 chance to work.

http://img262.imageshack.us/img262/1823/timery.jpg

All of that crap was working before Garry updates.

I had a similar problem yesterday.
I was connecting to my srcds server which had been running a while. Restarting the server fixed it.

Still don’t know where the problem came from as restarting the map or the client didn’t improve matters.

Using framenet? There’s your problem.
I was, but I stopped after I found that it made all the NWVars lag to hell, sometimes not show up and occasionally drop the server FPS to 2.

Use data tables when you can. They’re faster and don’t rely on the NWVar system.

No I don’t.

Hum I would like to use the data tables, but firstly I don’t know how and secondly I’ll need to change all my networked variables. Is it possible to have an exemple of a weapon or a gamemode that uses the data tables please?

Simple battery entity that uses datatables:

init.lua



AddCSLuaFile( "cl_init.lua" )

ENT.Type		=	"anim"
ENT.Base		=	"base_anim"
ENT.Spawnable		=	false
ENT.AdminSpawnable	=	false

function ENT:Initialize( )
	self:SetModel( "models/items/car_battery01.mdl" )

	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS )
	
	local phys

	phys = self:GetPhysicsObject( )

	if ValidEntity( phys ) then
		phys:Wake( )
		--Prevent impact damage so we don't break / kill things
		phys:AddGameFlag( FVPHYSICS_NO_IMPACT_DMG )
		phys:AddGameFlag( FVPHYSICS_NO_NPC_IMPACT_DMG )
		phys:AddGameFlag( FVPHYSICS_PENETRATING )
	end
end

function ENT:SetupDataTables( )
	self:DTVar( "Int", 0, "Power" )
end

function ENT:UpdatePower( i )
	if i <= 0 then
		self:SetColor( 100, 100, 100, 255 )
	end
	
	self.dt.Power = math.max( 0, i )
end

function ENT:TakePower( i )
	self:UpdatePower( self.dt.Power - i )
end

function ENT:GetPower( )
	return self.dt.Power
end


cl_init.lua



ENT.Type		=	"anim"
ENT.Base		=	"base_anim"
ENT.Spawnable		=	false
ENT.AdminSpawnable	=	false

ENT.CamPos		=	Vector( -4.8, -5.3, 2.5 )
ENT.CamAngle		=	Angle( 0, 90, -90 )
ENT.CamScale		=	.05

ENT.Width		=	212
ENT.Height		=	16

ENT.BatteryPower	=	1024

function ENT:SetupDataTables( )
	self:DTVar( "Int", 0, "Power" )
end

function ENT:DrawDisplay( )
	local r, g, b
	
	self.CurrentPower = math.Approach( self.CurrentPower or 0, self.TargetPower, FrameTime( ) * 2048 )
	
	f = math.Clamp( self.CurrentPower / self.BatteryPower, 0, 1 )
	
	surface.SetDrawColor( 000, 000, 000, 255 )
	surface.DrawRect( 0, 0, self.Width, self.Height )
	
	surface.SetDrawColor( ( 1 - f ) * 189, 189 * f, 0, 150 )
	surface.DrawRect( 0, 0, self.Width * f, self.Height )
end

function ENT:Draw( )
	local ok, err, pos, ang
	self:DrawModel( )
	
	pos = self:GetPos( ) + self:GetForward( ) * self.CamPos.x + self:GetRight( ) * self.CamPos.y + self:GetUp( ) * self.CamPos.z
	ang = self:GetAngles( )
	
	ang:RotateAroundAxis( ang:Right( )	, self.CamAngle.y )
	ang:RotateAroundAxis( ang:Up( )		, self.CamAngle.r )
	ang:RotateAroundAxis( ang:Forward( )	, self.CamAngle.p )
	
	self.TargetPower = self.dt.Power or 0
	
	cam.Start3D2D( pos, ang, self.CamScale )
		--Don't need to 
		ok, err = pcall( self.DrawDisplay, self )
		
		if not ok then
			ErrorNoHalt( err .. "
" )
		end
	cam.End3D2D( )
end


Each entity has a grand total of 24 different data variables it can have ( four int, float, bool, vector, ehandle, and angle ), which can lead to conflicts between different addons ( eg, I have an addon that uses two dt ints on npcs, but I use 2 and 3 to hopefully improve compatability as most people will start at 0 ).

As hinting above, the indices for the values range from 0 to 3, and the example code uses the literal table method, which isn’t really needed.

If you don’t want to use that, you can do this:



someent:SetDTInt( 3, 24 )


And then somewhere else, anywhere:



someint = someent:GetDTInt( 3 )


Not from me, but I’ll give you a quick run-through.

Firstly, you set your DTVars up with the function SWEP:SetupDataTables().
It might look a bit like this:
[lua]function SWEP:SetupDataTables()
self:DTVar(“Int”,0,“firemode”);
self:DTVar(“Bool”,0,“ironsights”);
self:DTVar(“Bool”,1,“silenced”);
self:DTVar(“Bool”,2,“scope”);
self:DTVar(“Float”,0,“scopezoom”);
self:DTVar(“Float”,1,“lastshoottime”);
end[/lua]
self:DTVar() has 3 arguments, type, id and identifier.
Type can be Angle, Bool, Entity, Float, Int or Vector.
id can be 0, 1, 2 or 3. This is because you can only have 4 DTVars for each type.
identifier is a human-readable name for your DTVar, such as the one you’d use in SetNWInt.
Once you have set them up, you will have the table ‘dt’ in your ‘self’ table, which is how you access the vars.
So if you had a NWInt called ‘fleeb’, you would set up a DT Version like this:
[lua]function SWEP:SetupDataTables()
self:DTVar(“Int”,0,“fleeb”);
end[/lua]
Then, any point where you would use self:GetNWInt(“fleeb”), you would replace that with self.dt.fleeb, and any point where you would use self:SetNWInt(“fleeb”,12), you would replace that with self.dt.fleeb = 12.
If you were feeling obtuse, you could also replace the get with self:GetDTInt(0) and the set with self:SetDTInt(0,12).

Hope that helps.

[editline]03:02PM[/editline]

Fffffffffff kogitsune >:(

[editline]03:04PM[/editline]

Oh, something to note, self.dt.name will return the default value for that type if you haven’t set it.
Thus, self.dt.power will start off at 0, and you don’t need that ‘or’. :smile:

:greatgift: :love:

Could you use ply:SetDTInt( “hello”, 1 ), ply:GetDTInt( “hello” )

etc?

No.

Entity:SetDT*( number:index, *:value )

So, no. You can only use 0, 1, 2, and 3 for the index.

Edit:

Payback D=

:3:

A big thank you for your great help!
I’ll try it now!

http://xibarmultimedia.net/forum/images/smiles/36_1_13.gif