• HELP! bad argument #1 to 'insert' (table expected, got nil)
    6 replies, posted
i need help it says like this: [ERROR] addons/keycardscanner/lua/entities/ent_foundationscanner/init.lua:103: bad argument #1 to 'insert' (table expected, got nil) 1. insert - [C]:-1 2. func - addons/keycardscanner/lua/entities/ent_foundationscanner/init.lua:103 3. unknown - lua/includes/extensions/net.lua:65 and from the addon : net.Receive( "netFKeycardSAddLevel", function( len, ply ) local ent = net.ReadEntity() local AddedLevel = net.ReadEntity() table.insert( ent.KeycardSData.AllowedUsers, AddedPly ) end ) net.Receive( "netFKeycardSRemoveLevel", function( len, ply ) local ent = net.ReadEntity() local RemovedLevel = net.ReadEntity() for k, v in pairs( ent.KeycardSData.AllowedUsers ) do if v == RemovedLevel then table.remove( ent.KeycardSData.AllowedUsers, k ) break end end end ) [highlight](User was banned for this post ("Wrong Forum" - Bengley))[/highlight]
ent.KeycardSData.AllowedUsers doesn't exist. Add a check to see if it's nil before inserting -- if it is, create a new table.
[QUOTE=code_gs;51899501]ent.KeycardSData.AllowedUsers doesn't exist. Add a check to see if it's nil before inserting -- if it is, create a new table.[/QUOTE] can you show me how i doing this pls
[CODE]table = table or {}[/CODE] or [CODE]if !table then return end[/CODE]
i fixed the error but when i add are level to adde levels and close the menu and open agian its agian to non added levels here is the code: AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( "shared.lua" ) util.AddNetworkString( "netFKeycardSMenu" ) util.AddNetworkString( "netFKeycardSAddLevel" ) util.AddNetworkString( "netFKeycardSRemoveLevel" ) util.AddNetworkString( "netFKeycardSpawn" ) util.AddNetworkString( "netFKeycardHackSpawn" ) util.AddNetworkString( "netFKeycardAdminSpawn" ) net.Receive( "netFKeycardAdminSpawn", function( len, ply ) local ent = net.ReadEntity() if not IsValid( ply ) or not IsValid( ent ) then return end if ent:GetStatus() ~= ent.Status_None then return end local keycard = ents.Create( "ent_foundationscanner" ) keycard:SetPos( ent:LocalToWorld( Vector(-7.5, 0, -0.1) ) ) keycard:SetAngles( ent:LocalToWorldAngles( Angle(0, 0, 0) ) ) keycard:SetParent( ent ) keycard:Spawn() timer.Simple( 2, function() if not IsValid( ent ) or not IsValid( keycard ) then return end keycard:Remove() end ) ent:Access( true ) end ) net.Receive( "netFKeycardSpawn", function( len, ply ) local ent = net.ReadEntity() if not IsValid( ply ) or not IsValid( ent ) then return end if ent:GetStatus() ~= ent.Status_None then return end local keycard = ents.Create( "ent_keycard" ) keycard:SetPos( ent:LocalToWorld( Vector(-7.5, 0, -0.1) ) ) keycard:SetAngles( ent:LocalToWorldAngles( Angle(0, 0, 0) ) ) keycard:SetParent( ent ) keycard:Spawn() timer.Simple( 2, function() if not IsValid( ent ) or not IsValid( keycard ) then return end keycard:Remove() end ) ScanCard( ply, ent ) end ) net.Receive( "netFKeycardHackSpawn", function( len, ply ) local ent = net.ReadEntity() if not IsValid( ply ) or not IsValid( ent ) then return end if ent:GetStatus() ~= ent.Status_None then return end local keycard = ents.Create( "ent_hacking_keycard" ) keycard:SetPos( ent:LocalToWorld( Vector(-7.5, 0, -0.1) ) ) keycard:SetAngles( ent:LocalToWorldAngles( Angle(0, 0, 0) ) ) keycard:SetParent( ent ) keycard:Spawn() ply:StripWeapon( "weapon_hacking_keycard" ) ent:EmitSound( "buttons/button18.wav" ) ent:SetStatus( ent.Status_Hacking ) timer.Create( "KS_Beep", 0.5, 0, function() if not IsValid( ent ) or not IsValid( keycard ) then if IsValid( ent ) then ent:SetStatus( ent.Status_None ) end if IsValid( ply ) then ply:Give( "weapon_hacking_keycard" ) end return end ent:EmitSound( "buttons/button17.wav" ) end ) timer.Create( "KS_Beep2", 1.5, 0, function() if not IsValid( ent ) or not IsValid( keycard ) then return end ent:EmitSound( "buttons/button17.wav" ) end ) timer.Simple( KS_HackingTime, function() if not IsValid( ent ) or not IsValid( keycard ) then return end ply:Give( "weapon_hacking_keycard" ) timer.Destroy( "KS_Beep" ) timer.Destroy( "KS_Beep2" ) ent:SetStatus( ent.Status_None ) keycard:Remove() ent:Access( true ) end ) end ) net.Receive( "netFKeycardSAddLevel", function( len, ply ) local ent = net.ReadEntity() local AddedLevel = net.ReadEntity() table.insert( ent.KeycardSData.AllowedLevels, AddedPly ) end ) net.Receive( "netFKeycardSRemoveLevel", function( len, ply ) local ent = net.ReadEntity() local RemovedLevel = net.ReadEntity() for k, v in pairs( ent.KeycardSData.AllowedLevels ) do if v == RemovedLevel then table.remove( ent.KeycardSData.AllowedLevels, k ) break end end end ) function ScanCard( ply, ent ) if not IsValid( ply ) or not IsValid( ent ) then return end if ent:GetStatus() ~= ent.Status_None then return end if ply:EyePos():Distance( ent:GetPos() ) >= 120 then return end ply:StripWeapon( "weapon_keycard" ) ent:EmitSound( "buttons/button14.wav" ) ent:SetStatus( ent.Status_Scanning ) timer.Simple( 2, function() if not IsValid( ent ) then return end local allowedLevels = ent.KeycardSData.AllowedLevels or {} if ply == ent.KeycardSData.Owner or table.HasValue( allowedLevels, ply ) then ent:Access( true ) else ent:Access( false ) end end ) timer.Simple( 2, function() ply:Give( "weapon_keycard" ) end ) end function ENT:Initialize() self:SetModel( "models/card/keycard_scanner.mdl" ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) self:SetUseType( SIMPLE_USE ) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end if not self.KeycardSData then self.KeycardSData = self:GetData() end end function ENT:Use( activator, caller ) if not IsValid( activator ) then return end if activator ~= self.KeycardSData.Owner then return end net.Start( "netFKeycardSMenu" ) net.WriteEntity( self ) net.WriteTable( self.KeycardSData ) net.Send( activator ) end function ENT:Access( granted ) local length, initdelay, delay, owner, key if granted then self:SetStatus( self.Status_Granted ) length = self.KeycardSData.LengthGranted initdelay = self.KeycardSData.InitDelayGranted delay = self.KeycardSData.DelayGranted owner = self.KeycardSData.Owner key = tonumber( self.KeycardSData.KeyGranted ) or 0 else self:SetStatus( self.Status_Denied ) length = self.KeycardSData.LengthDenied initdelay = self.KeycardSData.InitDelayDenied delay = self.KeycardSData.DelayDenied owner = self.KeycardSData.Owner key = tonumber( self.KeycardSData.KeyDenied ) or 0 end timer.Simple( math.max(initdelay + length + delay * 0.25, 2), function() if IsValid( self ) then self:Reset() end end ) timer.Simple( initdelay, function() if IsValid( self ) then if IsValid( self ) and IsValid( owner ) then numpad.Activate( owner, key, true ) end timer.Simple( length + delay, function() if IsValid( self ) and IsValid( owner ) then numpad.Deactivate( owner, key, true ) end end ) end end ) if granted then self:EmitSound( "buttons/button9.wav" ) else self:EmitSound( "buttons/button11.wav" ) end end function ENT:SetData( data ) self.KeycardSData = data self:Reset() end function ENT:GetData() return self.KeycardSData end function ENT:Reset() self:SetStatus( self.Status_None ) end
[QUOTE=Sebastian Pos;51912212]i fixed the error but when i add are level to adde levels and close the menu and open agian its agian to non added levels here is the code: [CODE]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( "shared.lua" ) util.AddNetworkString( "netFKeycardSMenu" ) util.AddNetworkString( "netFKeycardSAddLevel" ) util.AddNetworkString( "netFKeycardSRemoveLevel" ) util.AddNetworkString( "netFKeycardSpawn" ) util.AddNetworkString( "netFKeycardHackSpawn" ) util.AddNetworkString( "netFKeycardAdminSpawn" ) net.Receive( "netFKeycardAdminSpawn", function( len, ply ) local ent = net.ReadEntity() if not IsValid( ply ) or not IsValid( ent ) then return end if ent:GetStatus() ~= ent.Status_None then return end local keycard = ents.Create( "ent_foundationscanner" ) keycard:SetPos( ent:LocalToWorld( Vector(-7.5, 0, -0.1) ) ) keycard:SetAngles( ent:LocalToWorldAngles( Angle(0, 0, 0) ) ) keycard:SetParent( ent ) keycard:Spawn() timer.Simple( 2, function() if not IsValid( ent ) or not IsValid( keycard ) then return end keycard:Remove() end ) ent:Access( true ) end ) net.Receive( "netFKeycardSpawn", function( len, ply ) local ent = net.ReadEntity() if not IsValid( ply ) or not IsValid( ent ) then return end if ent:GetStatus() ~= ent.Status_None then return end local keycard = ents.Create( "ent_keycard" ) keycard:SetPos( ent:LocalToWorld( Vector(-7.5, 0, -0.1) ) ) keycard:SetAngles( ent:LocalToWorldAngles( Angle(0, 0, 0) ) ) keycard:SetParent( ent ) keycard:Spawn() timer.Simple( 2, function() if not IsValid( ent ) or not IsValid( keycard ) then return end keycard:Remove() end ) ScanCard( ply, ent ) end ) net.Receive( "netFKeycardHackSpawn", function( len, ply ) local ent = net.ReadEntity() if not IsValid( ply ) or not IsValid( ent ) then return end if ent:GetStatus() ~= ent.Status_None then return end local keycard = ents.Create( "ent_hacking_keycard" ) keycard:SetPos( ent:LocalToWorld( Vector(-7.5, 0, -0.1) ) ) keycard:SetAngles( ent:LocalToWorldAngles( Angle(0, 0, 0) ) ) keycard:SetParent( ent ) keycard:Spawn() ply:StripWeapon( "weapon_hacking_keycard" ) ent:EmitSound( "buttons/button18.wav" ) ent:SetStatus( ent.Status_Hacking ) timer.Create( "KS_Beep", 0.5, 0, function() if not IsValid( ent ) or not IsValid( keycard ) then if IsValid( ent ) then ent:SetStatus( ent.Status_None ) end if IsValid( ply ) then ply:Give( "weapon_hacking_keycard" ) end return end ent:EmitSound( "buttons/button17.wav" ) end ) timer.Create( "KS_Beep2", 1.5, 0, function() if not IsValid( ent ) or not IsValid( keycard ) then return end ent:EmitSound( "buttons/button17.wav" ) end ) timer.Simple( KS_HackingTime, function() if not IsValid( ent ) or not IsValid( keycard ) then return end ply:Give( "weapon_hacking_keycard" ) timer.Destroy( "KS_Beep" ) timer.Destroy( "KS_Beep2" ) ent:SetStatus( ent.Status_None ) keycard:Remove() ent:Access( true ) end ) end ) net.Receive( "netFKeycardSAddLevel", function( len, ply ) local ent = net.ReadEntity() local AddedLevel = net.ReadEntity() table.insert( ent.KeycardSData.AllowedLevels, AddedPly ) end ) net.Receive( "netFKeycardSRemoveLevel", function( len, ply ) local ent = net.ReadEntity() local RemovedLevel = net.ReadEntity() for k, v in pairs( ent.KeycardSData.AllowedLevels ) do if v == RemovedLevel then table.remove( ent.KeycardSData.AllowedLevels, k ) break end end end ) function ScanCard( ply, ent ) if not IsValid( ply ) or not IsValid( ent ) then return end if ent:GetStatus() ~= ent.Status_None then return end if ply:EyePos():Distance( ent:GetPos() ) >= 120 then return end ply:StripWeapon( "weapon_keycard" ) ent:EmitSound( "buttons/button14.wav" ) ent:SetStatus( ent.Status_Scanning ) timer.Simple( 2, function() if not IsValid( ent ) then return end local allowedLevels = ent.KeycardSData.AllowedLevels or {} if ply == ent.KeycardSData.Owner or table.HasValue( allowedLevels, ply ) then ent:Access( true ) else ent:Access( false ) end end ) timer.Simple( 2, function() ply:Give( "weapon_keycard" ) end ) end function ENT:Initialize() self:SetModel( "models/card/keycard_scanner.mdl" ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) self:SetUseType( SIMPLE_USE ) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end if not self.KeycardSData then self.KeycardSData = self:GetData() end end function ENT:Use( activator, caller ) if not IsValid( activator ) then return end if activator ~= self.KeycardSData.Owner then return end net.Start( "netFKeycardSMenu" ) net.WriteEntity( self ) net.WriteTable( self.KeycardSData ) net.Send( activator ) end function ENT:Access( granted ) local length, initdelay, delay, owner, key if granted then self:SetStatus( self.Status_Granted ) length = self.KeycardSData.LengthGranted initdelay = self.KeycardSData.InitDelayGranted delay = self.KeycardSData.DelayGranted owner = self.KeycardSData.Owner key = tonumber( self.KeycardSData.KeyGranted ) or 0 else self:SetStatus( self.Status_Denied ) length = self.KeycardSData.LengthDenied initdelay = self.KeycardSData.InitDelayDenied delay = self.KeycardSData.DelayDenied owner = self.KeycardSData.Owner key = tonumber( self.KeycardSData.KeyDenied ) or 0 end timer.Simple( math.max(initdelay + length + delay * 0.25, 2), function() if IsValid( self ) then self:Reset() end end ) timer.Simple( initdelay, function() if IsValid( self ) then if IsValid( self ) and IsValid( owner ) then numpad.Activate( owner, key, true ) end timer.Simple( length + delay, function() if IsValid( self ) and IsValid( owner ) then numpad.Deactivate( owner, key, true ) end end ) end end ) if granted then self:EmitSound( "buttons/button9.wav" ) else self:EmitSound( "buttons/button11.wav" ) end end function ENT:SetData( data ) self.KeycardSData = data self:Reset() end function ENT:GetData() return self.KeycardSData end function ENT:Reset() self:SetStatus( self.Status_None ) end[/CODE][/QUOTE] On behalf on everyone who is trying to help you, please put your code in [*CODE] [*/CODE] [B]*without the *[/B] tags please :happy:
[QUOTE=Bings;51918608]On behalf on everyone who is trying to help you, please put your code in [*CODE] [*/CODE] [B]*without the *[/B] tags please :happy:[/QUOTE] okay:cat:
Sorry, you need to Log In to post a reply to this thread.