Scripting a grenade-type SWEP

This is my code, in the shared.lua file:

//Made by WEEGEE

//General Variables\
SWEP.Weight = 0
SWEP.DrawCrosshair = true
SWEP.SlotPos = 0
SWEP.HoldType = “melee”
SWEP.Slot = 0
SWEP.ViewModelFOV = 64
SWEP.Purpose = “BONUS”
SWEP.AutoSwitchTo = false
SWEP.WorldModel = “models/weapons/w_grenade.mdl”
SWEP.Contact = “STEAM crick3497”
SWEP.Author = “WEEGEE”
SWEP.FiresUnderwater = true
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.ReloadSound = “Weapon_Pistol.Reload”
SWEP.Instructions = “Mouse 1 = Auto, Mouse 2 = Semi-Auto”
SWEP.ViewModel = “models/weapons/v_grenade.mdl”
SWEP.AutoSwitchFrom = false
SWEP.base = “weapon_base”
SWEP.Category = “Super Weapons”
SWEP.DrawAmmo = true
SWEP.PrintName = “Super Grenade”
SWEP.PrimaryThrow = True
SWEP.SecondaryThrow = True
//General Variables\

//Primary Fire Variables\
SWEP.Primary.ClipSize = 1
SWEP.Primary.Ammo = “fraggrenade”
SWEP.Primary.NumberofShots = 1
SWEP.Primary.Spread = 0
SWEP.Primary.Force = 1
SWEP.Primary.Damage = 10
SWEP.Primary.Delay = 0.1
SWEP.Primary.Recoil = 1
SWEP.Primary.DefaultClip = 32
SWEP.Primary.Automatic = true
SWEP.Primary.TakeAmmo = 0
SWEP.Primary.Sound = “WeaponFrag.Throw”
SWEP.Primary.Model = “models/Items/grenadeAmmo.mdl”
SWEP.Primary.AngVelocity = Angle(0,0,0)
//Primary Fire Variables\

//Secondary Fire Variables\
SWEP.Secondary.Automatic = “false”
SWEP.Secondary.Force = 10
SWEP.Secondary.Recoil = 1
SWEP.Secondary.Damage = 10
SWEP.Secondary.Ammo = “fraggrenade”
SWEP.Secondary.NumberofShots = 1
SWEP.Secondary.Spread = 0
SWEP.Secondary.DefaultClip = 32
SWEP.Secondary.Delay = 0
SWEP.Secondary.Sound = “WeaponFrag.Throw”
SWEP.Primary.AngVelocity = Angle(0,0,0)
SWEP.Secondary.Model = “models/Items/grenadeAmmo.mdl”
SWEP.Secondary.TakeAmmo = 0
SWEP.Secondary.ClipSize = 1
//Secondary Fire Variables\

//SWEP:Initialize()\
function SWEP:Initialize()
util.PrecacheSound(self.Primary.Sound)
util.PrecacheSound(self.Secondary.Sound)
if ( SERVER ) then
self:SetWeaponHoldType( self.HoldType )
end
end
//SWEP:Initialize()\

//SWEP:PrimaryFire()\
function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end
local bullet = {}
bullet.Num = self.Primary.NumberofShots
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
bullet.Tracer = 0
bullet.Force = self.Primary.Force
bullet.Damage = self.Primary.Damage
bullet.AmmoType = self.Primary.Ammo
local rnda = self.Primary.Recoil * -1
local rndb = self.Primary.Recoil * math.random(-1, 1)
self:ShootEffects()
self.Owner:FireBullets( bullet )
self.Weapon:EmitSound(Sound(self.Primary.Sound))
self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
self:TakePrimaryAmmo(self.Primary.TakeAmmo)
self:TakePrimaryAmmo(self.Primary.TakeAmmo)
self:Throw_Attack (self.Primary.Model, self.Primary.Sound, self.Primary.AngVelocity)
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
end
//SWEP:PrimaryFire()\

//SWEP:SecondaryFire()\
function SWEP:SecondaryAttack()
if ( !self:CanSecondaryAttack() ) then return end
local bullet = {}
bullet.Num = self.Secondary.NumberofShots
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector( self.Secondary.Spread * 0.1 , self.Secondary.Spread * 0.1, 0)
bullet.Tracer = 0
bullet.Force = self.Secondary.Force
bullet.Damage = self.Secondary.Damage
bullet.AmmoType = self.Secondary.Ammo
local rnda = self.Secondary.Recoil * -1
local rndb = self.Secondary.Recoil * math.random(-1, 1)
self:ShootEffects()
self.Owner:FireBullets( bullet )
self.Weapon:EmitSound(Sound(self.Secondary.Sound))
self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
self:TakeSecondaryAmmo(self.Secondary.TakeAmmo)
self:TakePrimaryAmmo(self.Primary.TakeAmmo)
self:Throw_Attack (self.Primary.Model, self.Primary.Sound, self.Primary.AngVelocity)
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )

end

//SWEP:Throw_Attack(Model, Sound, Angle)\
function SWEP:Throw_Attack (Model, Sound, Angle)
local tr = self.Owner:GetEyeTrace()
self.Weapon:EmitSound (Sound)
self.BaseClass.ShootEffects (self)
if (!SERVER) then return end
local ent = ents.Create (“prop_physics”)
ent:SetModel (Model)
ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
ent:SetAngles (self.Owner:EyeAngles())
ent:Spawn()
local phys = ent:GetPhysicsObject()
local shot_length = tr.HitPos:Length()
phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 7))
phys:AddAngleVelocity(Angle)
cleanup.Add (self.Owner, “props”, ent)
undo.Create (“Thrown model”)
undo.AddEntity (ent)
undo.SetPlayer (self.Owner)
undo.Finish()
end
//Throw_Attack(Model, Sound, Angle)\

//Made by WEEGEE

But it doesn’t seem to work. Can someone teach me how do script it correctly or at least give me some functions?

First off, surround your code by [lua] and [/lua ].

Now, what exactly is not working? Any errors?

Well, it’s in my cloud workshop, and it doesn’t want to spawn.

[editline]06:01PM[/editline]

Here’s an error I got:

[!toybox_1862_6:31] attempt to index field ‘SWEP’ (a nil value)

Line 31:


SWEP.Primary.NumberOfShots =

to


SWEP.Primary.NumShots =

I hope this helps.