• SWEP counted as nil value
    4 replies, posted
Well, I'm trying to make my first weapon in Garry's Mod, and the strangest error appears that I can't seem to resolve. It says "attempt to access global 'SWEP' (a nil value)" I know that the code is probably a train wreck, and it's not finished, primarily because I want to test if I can actually fire it first, but here it is: [CODE]if SERVER then AddCSLuaFile ("shared.lua") SWEP.Weight = 5 SWEP.AutoSwitchTo = true SWEP.AutoSwitchFrom = false elseif CLIENT then SWEP.PrintName = "Silly Pistol" SWEP.Slot = 1 SWEP.SlotPos = 1 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true end SWEP.Author = "Teh-Fr33Man" SWEP.Contact = "" SWEP.Purpose = "Mingebags clouding your server? Assassinate those asshats with this!" SWEP.Instructions = "M1 to fire a single bullet. M2 to fire automatically." SWEP.HoldType = "Pistol" SWEP.FiresUnderwater = true SWEP.Category = "Admin Essentials" SWEP.base = "weapon_base" SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.AutoSwitchFrom = false SWEP.AutoSwitchFrom = true SWEP.ViewModel = "models/weapons/v_pist_usp.mdl" SWEP.WorldModel = "models/weapons/w_pist_usp_silencer.mdl" SWEP.ViewModelFOV = 90 //Primary Fire Variables SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "Pistol" SWEP.Primary.TakeAmmo = 0 SWEP.Primary.Delay = 0 SWEP.Primary.Damage = 1000 SWEP.Primary.Recoil = 0 //Secondary Fire Variables SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = true SWEP.Secondary.Ammo = "none" local ShootSound = Sound("sound/weapons/tmp/tmp-1.wav") function SWEP:Initialize() util.PrecacheSound(ShootSound) self:SetWeaponHoldType( self.HoldType ) end function SWEP:Reload() end function SWEP.Think() end //SWEP Primary Fire function SWEP:PrimaryAttack() if ( !self:CanPrimaryAttack() ) then return end local bullet = {} bullet.Num = 1 bullet.Src = self.Owner:GetShootPos() bullet.Dir = self.Owner:GetAimVector() bullet.Spread = Vector( 0, 0, 0 ) bullet.Tracer = 0 bullet.Force = 1 bullet.Damage = self.Primary.Ammo bullet.AmmoType = self.Primary.Ammo local rndb = self.Primary.Recoil * -1 local rndb = self.Primary.Recoil * math.random (-1,1) self:ShootEffects() self.Owner:FireBullets( bullet ) self.Weapon:EmitSound(Sound(ShootSound)) self:TakePrimaryAmmo(self.Primary.TakeAmmo) self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) ) self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay ) end[/CODE] It says the error takes place at line 5, but its probably throughout the whole script. Any and all help appreciated.
Is the SWEP.Base set correctly? Is it referencing a real file?
[QUOTE=DoubleElite;36156576]Is the SWEP.Base set correctly? Is it referencing a real file?[/QUOTE] Probably not, actually. I have very, very, very little knowledge of coding in general, let alone lua.
Ok, so when your working with SWEPS, you have to have the correct folder setup. Hopefully this helps some. Ignore the fact that it's in winrar, I was just to lazy to unzip it to show you. You obviously wouldn't have your folders zipped up for Gmod. [url=http://uppix.net/d/7/9/534d64a5579523579611dd154dda2.html][img]http://uppix.net/d/7/9/534d64a5579523579611dd154dda2.png[/img][/url] [url=http://uppix.net/d/a/4/278a2b77aeb7a018dcb247edfdae3.html][img]http://uppix.net/d/a/4/278a2b77aeb7a018dcb247edfdae3.png[/img][/url] [url=http://uppix.net/a/8/9/9937ce310bb3748b05f4e45752d0c.html][img]http://uppix.net/a/8/9/9937ce310bb3748b05f4e45752d0c.png[/img][/url] [url=http://uppix.net/7/f/6/674aa3a88ad05c582f4d97dc7c43e.html][img]http://uppix.net/7/f/6/674aa3a88ad05c582f4d97dc7c43e.png[/img][/url] [url=http://uppix.net/b/1/7/9533ddc326d75cab23f7ecb0305c7.html][img]http://uppix.net/b/1/7/9533ddc326d75cab23f7ecb0305c7.png[/img][/url]
Thanks. I'll try that.
Sorry, you need to Log In to post a reply to this thread.