Basically, NetworkVar isn't doing anything but being a fat ugly bitch.
I'm rewriting this thread a 2nd time because for some reason my browser crashed, and I'm sort of stressed out atm so I'm in no mood to deal with this.
This is my problem:
[lua]function SWEP:SetupDataTables( )
local t_Index = 0;
local t_Vars = {};
t_Vars["ConeDefault"] = { "Float", self.Primary.Spread };
t_Vars["Cone"] = { "Float", t_Vars["ConeDefault"] };
t_Vars["RecoilDefault"] = { "Float", self.Primary.Recoil };
t_Vars["Recoil"] = { "Float", t_Vars["RecoilDefault"] };
t_Vars["Silenced"] = { "Bool", false };
t_Vars["SilencedID"] = { "String", "nil" };
for t_Variable, t_Value in pairs( t_Vars ) do
self:NetworkVar( self, t_Value[1], t_Index, t_Variable );
self[ "Set" .. t_Variable ]( t_Value[ 2 ] );
t_Index = t_Index + 1;
end
end[/lua]
NetworkVar():
[lua] self.NetworkVar = function( ent, typename, index, name )
ent.DTVar( ent, typename, index, name )
ent[ 'Set' .. name ] = function( self, value )
self.dt[name] = value
end
ent[ 'Get' .. name ] = function( self )
return self.dt[name]
end
end[/lua]
Spamming in the console:
[code]
[addons/counter-strike source/lua/weapons/weapon_css_base/shared.lua:278] attempt to call method 'GetSilenced' (a nil value)
1. addons/counter-strike source/lua/weapons/weapon_css_base/shared.lua:278 (ConeThink)
2. addons/counter-strike source/lua/weapons/weapon_css_base/shared.lua:232 (unknown)
[addons/counter-strike source/lua/weapons/weapon_css_base/shared.lua:278] attempt to call method 'GetSilenced' (a nil value)
1. addons/counter-strike source/lua/weapons/weapon_css_base/shared.lua:278 (ConeThink)
2. addons/counter-strike source/lua/weapons/weapon_css_base/shared.lua:232 (unknown)
[addons/counter-strike source/lua/weapons/weapon_css_base/cl_init.lua:38] attempt to call method 'GetCone' (a nil value)
1. addons/counter-strike source/lua/weapons/weapon_css_base/cl_init.lua:38 (unknown)
[/code]
Obviously the problem here is that the functions aren't being created, and I have no idea why they aren't.
I've also tried creating my own array as SWEP.Data = {}; and I had problems with variables being synchronized with the server.
Basically if I did that, sometimes if I toggled a variable or set one to something else, it wouldn't change serverside but it would clientside, and vise verse; causing issues.
[lua]
self:NetworkVar( self, t_Value[1], t_Index, t_Variable );
[/lua]
When you use self:function self is already passed as the first value, it's redundant to have it in the arguments as it'll break the function.
[lua]
self:NetworkVar(t_Value[1], t_Index, t_Variable );
[/lua]
Which causes
[lua][@lua/includes/extensions/entity.lua:177] bad key to string index (number expected, got string)
1. [C]:-1 (error)
2. lua/includes/extensions/string.lua:265 (unknown)
3. lua/includes/extensions/entity.lua:177 (?)
4. addons/counter-strike source/lua/weapons/weapon_css_base/shared.lua:124 (unknown)
5. [C]:-1 (Give)
6. addons/counter-strike source/lua/entities/vik_css_base/init.lua:43 (unknown)
[/lua]
:/
Why such convoluted code?
[code]
function SWEP:SetupDataTables()
self:NetworkVar( "Float", 0, "Cone" );
self:NetworkVar( "Float", 1, "Recoil" );
self:NetworkVar( "Bool", 0, "Silenced" );
end
function SWEP:Initialize()
if( SERVER ) then
self:SetCone( self.Primary.Spread );
self:SetRecoil( self.Primary.Recoil );
self:SetSilenced( false );
end
end
[/code]
[QUOTE=Jinto;37914955]Why such convoluted code?
[code]
function SWEP:SetupDataTables()
self:NetworkVar( "Float", 0, "Cone" );
self:NetworkVar( "Float", 1, "Recoil" );
self:NetworkVar( "Bool", 0, "Silenced" );
end
function SWEP:Initialize()
if( SERVER ) then
self:SetCone( self.Primary.Spread );
self:SetRecoil( self.Primary.Recoil );
self:SetSilenced( false );
end
end
[/code][/QUOTE]
Because I have an obsession with automation. :/ Thanks I'll see if this will work.
Oh by the way, the reason why there are two variables for the Cone and Recoil is because I couldn't keep the original values once they were changed. C:
[editline]Derp[/editline] I feel silly, it worked.
Funny how I make simple things overly complicated and wonder why I always stress myself out.
Sorry, you need to Log In to post a reply to this thread.