Network library initally not working on client

Ok, so I posted in WDYNHO thread but nobody answered back and I need to fix this as fast as possible.

So I just got rid of NWVars and trying out the new net library. Now when I load up my gamemode for some strange reason the variables I have added do not work on the client. Meaning I don’t believe they are being sent over for some reason. HOWEVER when I save a clientside file (reload clientside) the network library decides to start working for me on clientside.

I have a setup that is called from load.lua so it plays out to this:


load.lua (util.NetworkAddString located here) -> cl_networking.lua (net.Recive is in here)
                                              -> sv_player_ext.lua (net.Send is here)


I get no errors what so ever, and have to reload clientside to actually receive data.

load.lua
[lua]if ( SERVER ) then
util.AddNetworkString( “bs_Ammo” );
util.AddNetworkString( “bs_Ironsights” );
util.AddNetworkString( “bs_Hunger” );
util.AddNetworkString( “bs_Stamina” );
util.AddNetworkString( “bs_GoodEvil” );

AddCSLuaFile( "core/cl_networking.lua" );
AddCSLuaFile( "core/sh_player_ext.lua" );
AddCSLuaFile( "core/sh_animations.lua" );
AddCSLuaFile( "core/sh_weapon_sounds.lua" );
AddCSLuaFile( "core/cl_hud.lua" );

include( "core/sv_core.lua" );
include( "core/sv_player.lua" );
include( "core/sv_player_ext.lua" );
include( "core/sv_mission.lua" );
include( "core/sv_concommand.lua" );
include( "core/sh_player_ext.lua" );
include( "core/sh_animations.lua" );
include( "core/sh_weapon_sounds.lua" );

else
include( “core/cl_networking.lua” );
include( “core/sh_player_ext.lua” );
include( “core/sh_animations.lua” );
include( “core/sh_weapon_sounds.lua” );
include( “core/cl_hud.lua” );
end[/lua]

cl_networking.lua
[lua]local ply = LocalPlayer();

//Ammunition = {};
net.Receive( “bs_Ammo”, function( len )
//local str = net.ReadString();
//local amt = net.ReadInt( 32 );
local tbl = net.ReadTable();

//print( "Ammo: s = " .. str .. " | a = " .. amt );
//if ( table.HasValue( BrainStock.AmmoType, str ) ) then
//    pl.Ammunition[ str ] = amt;
//end 
ply.Ammunition = tbl;

end );

net.Receive( “bs_Ironsights”, function( len )
local bool = net.ReadBit();

ply.bIronSights = tobool( bool );

end );

net.Receive( “bs_Hunger”, function( len )
local amt = net.ReadInt( 8 );

ply.nHunger = amt;

end );

net.Receive( “bs_Stamina”, function( len )
local amt = net.ReadFloat();

ply.fStamina = amt;

end );

net.Receive( “bs_GoodEvil”, function( len )
local amt = net.ReadInt( 8 );

ply.nGoodEvil = amt;

end );[/lua]

sv_player_ext.lua
[lua]function meta:SetAmmoType( ammo, amt )
//self:SetNetworkedInt( ammo, amt );
self.Ammunition[ ammo ] = amt;
net.Start( “bs_Ammo” );
//net.WriteString( ammo );
//net.WriteInt( amt, 32 );
net.WriteTable( self.Ammunition );
net.Send( self );
end

function meta:AddAmmoType( ammo, amt )
self:SetAmmoType( ammo, self:AmmoType( ammo ) + amt );
end

function meta:SetIronSights( bool )
//self:SetNetworkedBool( “bIronSights”, bool );
self.bIronSights = bool;
net.Start( “bs_Ironsights” );
net.WriteBit( bool );
net.Send( self );
if ( bool ) then
self:SetWalkSpeed( BrainStock.Configuration.WalkSpeed - 40 );
self:SetFOV( self:GetFOV() - 10, 0.2 );
else
self:SetWalkSpeed( BrainStock.Configuration.WalkSpeed );
self:SetFOV( 0, 0.2 );
end
end

function meta:SetHunger( int )
//self:SetNetworkedInt( “HUNGER”, int );
self.nHunger = int;
net.Start( “bs_Hunger” );
net.WriteInt( int, 8 );
net.Send( self );
end

function meta:AddHunger( int )
self:SetHunger( self:GetHunger() + int );
end

function meta:SetStamina( int )
//self:SetNetworkedFloat( “STAMINA”, int );
self.fStamina = int;
net.Start( “bs_Stamina” );
net.WriteFloat( int );
net.Send( self );
end

function meta:AddStamina( int )
self:SetStamina( self:GetStamina() + int );
if ( self:GetStamina() >= BrainStock.Configuration.MaxStamina ) then
self:SetStamina( BrainStock.Configuration.MaxStamina )
end
end

function meta:SetGoodEvil( int )
//self:SetNetworkedInt( “GOODEVIL”, float );
self.nGoodEvil = int;
net.Start( “bs_GoodEvil” );
net.WriteInt( int, 8 );
net.Send( self );
end

function meta:AddGoodEvil( int )
self:SetGoodEvil( self:GetGoodEvil() + int );
if ( self:GetGoodEvil() > BrainStock.Configuration.MaxGoodEvil ) then
self:SetGoodEvil( BrainStock.Configuration.MaxGoodEvil );
elseif ( self:GetGoodEvil() < -BrainStock.Configuration.MaxGoodEvil ) then
self:SetGoodEvil( -BrainStock.Configuration.MaxGoodEvil );
end
end[/lua]

Possibly the string tables are not updates fast enough?

I don’t know what you mean by this…sorry

Addition Note:
This has been tested on both Listen and Dedicated

he means that when you’re testing locallly you’re sending the stuff before it has setup the shit with util.AddNetworkString, try adding a 1 sec timer

I’ve tested both Dedicated and Locally. Made no difference

Timers also didn’t seem to work.

Does anybody know a function I can force on the client similar to gamemode_reload_cl

[lua]local ply = LocalPlayer();[/lua]

There is your problem, LocalPlayer() is a NULL entity whilst Lua files are loaded, just use LocalPlayer() everywhere you used ply instead, it’ll work then.

It works thank you so much. Such a small thing made me pull my hair out.

P.S. I love you