• Spamming error when dying
    10 replies, posted
Whenever I use some guns from my base and I die or suicide while i have then in my inventory, Each gun spams this in console: [ERROR] addons/gunpack1/lua/weapons/my_base/shared.lua:682: bad argument #2 to 'SetNetworkedInt' (number expected, got nil) 1. SetNetworkedInt - [C]:-1 2. SetFireMode - addons/gunpack1/lua/weapons/my_base/shared.lua:682 3. ResetVars - addons/gunpack1/lua/weapons/my_base/shared.lua:414 4. unknown - addons/gunpack1/lua/weapons/my_base/shared.lua:420 below line 682 and further below the function itself where this line belongs [lua] self.Weapon:SetNetworkedInt("FireMode",self.CurFireMode) [/lua] [lua]function SWEP:SetFireMode() local FireMode = self.AvailableFireModes[self.CurFireMode] self.Weapon:SetNetworkedInt("FireMode",self.CurFireMode) -- Set the firemode's fire function (for shooting bullets, grenades, etc.). This function is called under SWEP:PrimaryAttack() self.FireFunction = self.FireModes[FireMode].FireFunction -- Run the firemode's init function (for updating delay and other variables) self.FireModes[FireMode].InitFunction(self) end [/lua] If anyone knows why this script is wrong, please give a reply. Thanks.
The second argument to [URL="http://wiki.garrysmod.com/page/Entity/SetNetworkedInt"]SetNetworkedInt[/URL] should be an integer.
I dont have much experience with functions like these I tried before but didnt work, Could you give me the code line that will fix this function? I would be very gratefull -Dev
What is CurFireMode defined as? If you don't know, CTRL+F through the code until you find what it's equal to.
it leads me to many places: [lua]self.CurFireMode = 1 [/lua] [lua]self.FireFunction = self.FireModes[self.AvailableFireModes[self.CurFireMode]].FireFunction [/lua] [lua] local FireMode = self.AvailableFireModes[self.CurFireMode] self.Weapon:SetNetworkedInt("FireMode",self.CurFireMode) [/lua] [lua]local FireMode = self.AvailableFireModes[self.CurFireMode] [/lua] [lua]self.CurFireMode = math.fmod(self.CurFireMode, NumberOfFireModes) + 1[/lua]
Try this then [code]self.Weapon:SetNetworkedInt("FireMode", 1)[/code]
[ERROR] addons/gunpack1/lua/weapons/my_base/shared.lua:685: attempt to index a nil value 1. SetFireMode - addons/gunpack1/lua/weapons/my_base/shared.lua:685 2. ResetVars - addons/gunpack1/lua/weapons/my_base/shared.lua:414 3. unknown - addons/gunpack1/lua/weapons/my_base/shared.lua:420 line 685: [lua] self.FireFunction = self.FireModes[FireMode].FireFunction[/lua] I can remember that someone had a similair problem with this line: [lua](2*self.BurstDelay, self.BaseAttack, self)[/lua] changed into this v [lua](2*self.BurstDelay, function() self:BaseAttack() end )[/lua] in order to be compatible with gmod13
Can you please post the whole code? I need a lot more context than what you're posting.
[QUOTE=code_gs;43266457]Can you please post the whole code? I need a lot more context than what you're posting.[/QUOTE] Shared: [lua] if SERVER then AddCSLuaFile("shared.lua") AddCSLuaFile("cl_init.lua") SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false end SWEP.Author = "" SWEP.Contact = "" SWEP.Purpose = "." SWEP.Instructions = "." SWEP.Spawnable = false SWEP.AdminSpawnable = false SWEP.Primary.Sound = Sound("Weapon_TMP.Single") SWEP.Primary.Damage = 40 SWEP.Primary.NumShots = 1 SWEP.AutoRPM = 200 SWEP.SemiRPM = 200 SWEP.BurstRPM = 200 SWEP.MuzzleVelocity = 920 SWEP.AvailableFireModes = {} SWEP.DrawFireModes = true SWEP.FiresUnderwater = false SWEP.MuzzleEffect = "rg_muzzle_pistol" SWEP.ShellEjectEffect = "rg_shelleject" SWEP.MuzzleAttachment = "1" SWEP.ShellEjectAttachment = "2" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.GrenadeDamage = 100 SWEP.GrenadeVelocity = 1400 SWEP.GrenadeRPM = 50 SWEP.Secondary.Sound = Sound("Weapon_AR2.Double") -- For grenade launching SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false -- Best left at false, as secondary is used for ironsights/switching firemodes SWEP.Secondary.Ammo = "none" SWEP.IronSightZoom = 1.2 SWEP.ScopeZooms = {5} SWEP.UseScope = false SWEP.ScopeScale = 0.4 SWEP.DrawParabolicSights = false SWEP.MinRecoil = 0.1 SWEP.MaxRecoil = 0.5 SWEP.DeltaRecoil = 0.1 SWEP.RecoverTime = 1 SWEP.MinSpread = 0.01 SWEP.MaxSpread = 0.08 SWEP.DeltaSpread = 0.003 SWEP.MinSpray = 0.2 SWEP.MaxSpray = 1.5 SWEP.DeltaSpray = 0.2 SWEP.CrouchModifier = 0.7 SWEP.IronSightModifier = 0.7 SWEP.RunModifier = 1.5 SWEP.JumpModifier = 1.5 --------------------------------------------------------- --------------------Firemodes------------------------ --------------------------------------------------------- SWEP.FireModes = {} --------------------------------------- -- Firemode: Semi Automatic -- --------------------------------------- SWEP.FireModes.Semi = {} SWEP.FireModes.Semi.FireFunction = function(self) self:BaseAttack() end SWEP.FireModes.Semi.InitFunction = function(self) self.Primary.Automatic = false self.Primary.Delay = 60/self.SemiRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.922*surface.ScreenHeight() end end -- We don't need to do anything for these revert functions, as self.Primary.Automatic, self.Primary.Delay, self.FireModeDrawTable.x, and self.FireModeDrawTable.y are set in every init function SWEP.FireModes.Semi.RevertFunction = function(self) return end SWEP.FireModes.Semi.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("p") -- "p" corresponds to the hl2 pistol ammo icon in this font end --------------------------------------- -- Firemode: Fully Automatic -- --------------------------------------- SWEP.FireModes.Auto = {} SWEP.FireModes.Auto.FireFunction = function(self) self:BaseAttack() end SWEP.FireModes.Auto.InitFunction = function(self) self.Primary.Automatic = true self.Primary.Delay = 60/self.AutoRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.922*surface.ScreenHeight() end end SWEP.FireModes.Auto.RevertFunction = function(self) return end SWEP.FireModes.Auto.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("ppppp") end ------------------------------------------- -- Firemode: Three-Round Burst -- ------------------------------------------- SWEP.FireModes.Burst = {} SWEP.FireModes.Burst.FireFunction = function(self) local clip = self.Weapon:Clip1() if not self:CanFire(clip) then return end self:BaseAttack() timer.Simple(self.BurstDelay, function() self:BaseAttack() end ) if clip > 1 then timer.Simple(2*self.BurstDelay, function() self:BaseAttack() end ) end end SWEP.FireModes.Burst.InitFunction = function(self) self.Primary.Automatic = true self.Primary.Delay = 60/self.SemiRPM + 3*self.BurstDelay -- Burst delay is derived from self.BurstRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.912*surface.ScreenHeight() end end SWEP.FireModes.Burst.RevertFunction = function(self) return end SWEP.FireModes.Burst.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("ppp") end ------------------------------------------ -- Firemode: Grenade Launcher -- ------------------------------------------ SWEP.FireModes.Grenade = {} SWEP.FireModes.Grenade.FireFunction = function(self) if not self:CanFire(self.Weapon:Ammo2()) then return end local PlayerAim = self.Owner:GetAimVector() local PlayerAng = PlayerAim:Angle() local PlayerPos = self.Owner:GetShootPos() - PlayerAng:Up()*20 if not self.Weapon:GetNetworkedBool("Ironsights",false) then -- For some reason getattachement is fucked serverside, so we have to do this to get an estimate of the muzzle pos. PlayerPos = PlayerPos + PlayerAng:Right()*20 end if SERVER then local grenade = ents.Create("sent_rg_grenade") grenade:SetPos(PlayerPos) grenade:SetAngles(PlayerAim:Angle()) grenade:SetOwner(self.Owner) grenade:SetVar("Damage",self.GrenadeDamage) grenade:Spawn() local grenphys = grenade:GetPhysicsObject() grenphys:SetVelocity(PlayerAim*self.GrenadeVelocity) grenphys:ApplyForceOffset(VectorRand()*math.Rand(15,30),PlayerPos + VectorRand()*math.Rand(0.5,1.5)) -- Add spinniness end self:TakeSecondaryAmmo(1) -- Shoot Effects self.Weapon:EmitSound(self.Secondary.Sound) self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK) -- View model animation self.Owner:SetAnimation(PLAYER_ATTACK1) -- 3rd Person Animation local fx = EffectData() fx:SetEntity(self.Weapon) fx:SetOrigin(PlayerPos) fx:SetNormal(PlayerAim) fx:SetAttachment(self.MuzzleAttachment) util.Effect("rg_muzzle_grenade",fx) -- Additional muzzle effects end SWEP.FireModes.Grenade.InitFunction = function(self) self.Primary.Automatic = false self.Primary.Delay = 60/self.GrenadeRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.912*surface.ScreenHeight() end end SWEP.FireModes.Grenade.RevertFunction = function(self) return end SWEP.FireModes.Grenade.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("t") -- "t" corresponds to the hl2 smg grenade ammo icon in this font end --------------------------------------------------------- -----------------Init Functions---------------------- --------------------------------------------------------- local sndZoomIn = Sound("Weapon_AR2.Special1") local sndZoomOut = Sound("Weapon_AR2.Special2") local sndCycleZoom = Sound("Default.Zoom") local sndCycleFireMode = Sound("Weapon_Pistol.Special2") function SWEP:Initialize() self:SetWeaponHoldType(self.HoldType) if SERVER then self:SetNPCMinBurst(3) self:SetNPCMaxBurst(6) self:SetNPCFireRate(60/self.AutoRPM) end if CLIENT then -- We need to get these so we can scale everything to the player's current resolution. local iScreenWidth = surface.ScreenWidth() local iScreenHeight = surface.ScreenHeight() -- The following code is only s
Try this [code] if SERVER then AddCSLuaFile("shared.lua") AddCSLuaFile("cl_init.lua") SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false end SWEP.Author = "Teta_Bonita" SWEP.Contact = "" SWEP.Purpose = "To crush your enemies." SWEP.Instructions = "Aim away from face." SWEP.Spawnable = false SWEP.AdminSpawnable = false SWEP.Primary.Sound = Sound("Weapon_TMP.Single") SWEP.Primary.Damage = 40 SWEP.Primary.NumShots = 1 SWEP.AutoRPM = 200 SWEP.SemiRPM = 200 SWEP.BurstRPM = 200 SWEP.MuzzleVelocity = 920 SWEP.AvailableFireModes = {} SWEP.DrawFireModes = true SWEP.FiresUnderwater = false SWEP.MuzzleEffect = "rg_muzzle_pistol" SWEP.ShellEjectEffect = "rg_shelleject" SWEP.MuzzleAttachment = "1" SWEP.ShellEjectAttachment = "2" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.GrenadeDamage = 100 SWEP.GrenadeVelocity = 1400 SWEP.GrenadeRPM = 50 SWEP.Secondary.Sound = Sound("Weapon_AR2.Double") -- For grenade launching SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false -- Best left at false, as secondary is used for ironsights/switching firemodes SWEP.Secondary.Ammo = "none" SWEP.IronSightZoom = 1.2 SWEP.ScopeZooms = {5} SWEP.UseScope = false SWEP.ScopeScale = 0.4 SWEP.DrawParabolicSights = false SWEP.MinRecoil = 0.1 SWEP.MaxRecoil = 0.5 SWEP.DeltaRecoil = 0.1 SWEP.RecoverTime = 1 SWEP.MinSpread = 0.01 SWEP.MaxSpread = 0.08 SWEP.DeltaSpread = 0.003 SWEP.MinSpray = 0.2 SWEP.MaxSpray = 1.5 SWEP.DeltaSpray = 0.2 SWEP.CrouchModifier = 0.7 SWEP.IronSightModifier = 0.7 SWEP.RunModifier = 1.5 SWEP.JumpModifier = 1.5 --------------------------------------------------------- --------------------Firemodes------------------------ --------------------------------------------------------- SWEP.FireModes = {} --------------------------------------- -- Firemode: Semi Automatic -- --------------------------------------- SWEP.FireModes.Semi = {} SWEP.FireModes.Semi.FireFunction = function(self) self:BaseAttack() end SWEP.FireModes.Semi.InitFunction = function(self) self.Primary.Automatic = false self.Primary.Delay = 60/self.SemiRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.922*surface.ScreenHeight() end end -- We don't need to do anything for these revert functions, as self.Primary.Automatic, self.Primary.Delay, self.FireModeDrawTable.x, and self.FireModeDrawTable.y are set in every init function SWEP.FireModes.Semi.RevertFunction = function(self) return end SWEP.FireModes.Semi.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("p") -- "p" corresponds to the hl2 pistol ammo icon in this font end --------------------------------------- -- Firemode: Fully Automatic -- --------------------------------------- SWEP.FireModes.Auto = {} SWEP.FireModes.Auto.FireFunction = function(self) self:BaseAttack() end SWEP.FireModes.Auto.InitFunction = function(self) self.Primary.Automatic = true self.Primary.Delay = 60/self.AutoRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.922*surface.ScreenHeight() end end SWEP.FireModes.Auto.RevertFunction = function(self) return end SWEP.FireModes.Auto.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("ppppp") end ------------------------------------------- -- Firemode: Three-Round Burst -- ------------------------------------------- SWEP.FireModes.Burst = {} SWEP.FireModes.Burst.FireFunction = function(self) local clip = self.Weapon:Clip1() if not self:CanFire(clip) then return end self:BaseAttack() timer.Simple(self.BurstDelay, function() self:BaseAttack() end ) if clip > 1 then timer.Simple(2*self.BurstDelay, function() self:BaseAttack() end ) end end SWEP.FireModes.Burst.InitFunction = function(self) self.Primary.Automatic = true self.Primary.Delay = 60/self.SemiRPM + 3*self.BurstDelay -- Burst delay is derived from self.BurstRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.912*surface.ScreenHeight() end end SWEP.FireModes.Burst.RevertFunction = function(self) return end SWEP.FireModes.Burst.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("ppp") end ------------------------------------------ -- Firemode: Grenade Launcher -- ------------------------------------------ SWEP.FireModes.Grenade = {} SWEP.FireModes.Grenade.FireFunction = function(self) if not self:CanFire(self.Weapon:Ammo2()) then return end local PlayerAim = self.Owner:GetAimVector() local PlayerAng = PlayerAim:Angle() local PlayerPos = self.Owner:GetShootPos() - PlayerAng:Up()*20 if not self.Weapon:GetNetworkedBool("Ironsights",false) then -- For some reason getattachement is fucked serverside, so we have to do this to get an estimate of the muzzle pos. PlayerPos = PlayerPos + PlayerAng:Right()*20 end if SERVER then local grenade = ents.Create("sent_rg_grenade") grenade:SetPos(PlayerPos) grenade:SetAngles(PlayerAim:Angle()) grenade:SetOwner(self.Owner) grenade:SetVar("Damage",self.GrenadeDamage) grenade:Spawn() local grenphys = grenade:GetPhysicsObject() grenphys:SetVelocity(PlayerAim*self.GrenadeVelocity) grenphys:ApplyForceOffset(VectorRand()*math.Rand(15,30),PlayerPos + VectorRand()*math.Rand(0.5,1.5)) -- Add spinniness end self:TakeSecondaryAmmo(1) -- Shoot Effects self.Weapon:EmitSound(self.Secondary.Sound) self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK) -- View model animation self.Owner:SetAnimation(PLAYER_ATTACK1) -- 3rd Person Animation local fx = EffectData() fx:SetEntity(self.Weapon) fx:SetOrigin(PlayerPos) fx:SetNormal(PlayerAim) fx:SetAttachment(self.MuzzleAttachment) util.Effect("rg_muzzle_grenade",fx) -- Additional muzzle effects end SWEP.FireModes.Grenade.InitFunction = function(self) self.Primary.Automatic = false self.Primary.Delay = 60/self.GrenadeRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.912*surface.ScreenHeight() end end SWEP.FireModes.Grenade.RevertFunction = function(self) return end SWEP.FireModes.Grenade.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("t") -- "t" corresponds to the hl2 smg grenade ammo icon in this font end --------------------------------------------------------- -----------------Init Functions---------------------- --------------------------------------------------------- local sndZoomIn = Sound("Weapon_AR2.Special1") local sndZoomOut = Sound("Weapon_AR2.Special2") local sndCycleZoom = Sound("Default.Zoom") local sndCycleFireMode = Sound("Weapon_Pistol.Special2") function SWEP:Initialize() self:SetWeaponHoldType(self.HoldType) if SERVER then self:SetNPCMinBurst(3) self:SetNPCMaxBurst(6) self:SetNPCFireRate(60/self.AutoRPM) end if CLIENT then -- We need to get these so we can scale everything to the player's current resolution. local iScreenWidth = surface.ScreenWidth() local iScreenHeight = surface.ScreenHeight() -- The following code is only slightly riped off from Night Eagle -- These tables are used
Thanks for your help but the code you sended broke the entire base, it became "non existant" and soon just a broken version of what i had, i should not use firemodes and ironsights.
Sorry, you need to Log In to post a reply to this thread.