What is wrong with my code?

I have made my SWEP and called it weapon_c13.lua and put in in the Lua>Weapons folder in g-mod
This is the error in the console:

Here is the code of my file

What did i do wrong here? Any idea?
This is my first mod

[editline]8th December 2014[/editline]

how come there are 2 users viewing this post (excluding me) for like 20 minutes but still no reply?

put it in code tags and we’ll help.

Well considering console gives you a lua error… You should probably start therr

Line 58 of weapon_c13.lua has something wrong near an equals sign

-snip-

was a ‘half asleep’ job, failed to notice multiple issues.

Hey dude, the ammo doesnt deplete, and the model isnt what i wanted its an ak. and how am i supposed to enable ironsights when secondary fires a shotgun? and primary is like a 1hit kill auto rifle.

nevermind i’ll just steal some gun with Gmad and re-modell it

The community of facepunch will not spoon feed you code, especially with that attitude, I suggest you look up the gmod wiki and start with the tutorials.

So instead of learning how to make a SWEP, one of the easier things to do, you resort to “stealing” a gun and just changing the model? Why are you even making this gun? If it’s for a server you are making/developing I would suggest stopping now before you waste your time, because obviously you are not doing this to learn.

Also


self:EmitSount

is probably why the primary fire isnt working on the gun, it errors out there and never takes ammo or sets the delay.

[lua]
AddCSLuaFile()

SWEP.Base = “weapon_base”
SWEP.PrintName = “C13 Optimist”
SWEP.Instructions = “Advanced combat device with enhanced firing system. Fires 3 bullets per shot.”
SWEP.Author = “Professor Smiley”
SWEP.Spawnable = true
SWEP.AdminSpawnable = false
SWEP.ViewModelFlip = false
SWEP.HoldType = “ar2”
SWEP.ViewModelFOV = 75
SWEP.ViewModelFlip = true
SWEP.ViewModel = “models/weapons/v_rif_ak47.mdl”
SWEP.WorldModel = “models/weapons/w_rif_ak47.mdl”
SWEP.ShowViewModel = true
SWEP.ShowWorldModel = true
SWEP.ViewModelBoneMods = {}
SWEP.IronSightsPos = Vector(5.51, -8.242, -0.84)
SWEP.IronSightsAng = Vector(0, 0, 0)

SWEP.Primary.Recoil = 1.50
SWEP.Primary.Damage = 25
SWEP.Primary.NumShots = 3
SWEP.Primary.Spread = 0.10
SWEP.Primary.Cone = 0.10
SWEP.Primary.ClipSize = 45
SWEP.Primary.DefaultClip = 90
SWEP.Primary.Ammo = “ar2”
SWEP.Primary.Automatic = true
SWEP.Primary.Delay = 0.5

function SWEP:Initialize()
util.PrechacheSound( “cynosure/blast.wav” )
self:SetWeaponHoldType( self.HoldType )
end

function SWEP:PrimaryAttack()

if ( not self:CanPrimaryAttack() ) then return end

local Bullet = {}
Bullet.Num = self.Primary.NumShots
Bullet.Src = self.Owner:GetShootPos()
Bullet.Dir = self.Owner:GetAimVector()
Bullet.Spread = Vector( self.Primary.Spread, self.Primary.Spread, 0 )
Bullet.Tracer = 1
Bullet.Damage = self.Primary.Damage
Bullet.AmmoType = self.Primary.Ammo

self:ShootEffects()
self:FireBullets( Bullet )
self:EmitSount( Sound("cynosure/blast.wav") )
self:TakePrimaryAmmo( 3 )
self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )

end

SWEP.VElements = {
[“barrel”] = { type = “Model”, model = “models/props_c17/canister02a.mdl”, bone = “v_weapon.AK47_Clip”, rel = “”, pos = Vector(0, 0, 0), angle = Angle(0, 0, 0), size = Vector(0.5, 0.5, 0.5), color = Color(60, 60, 60, 255), surpresslightning = false, material = “bmw”, skin = 0, bodygroup = {} },
[“sight”] = { type = “Model”, model = “models/props_c17/pulleywheels_small01.mdl”, bone = “v_weapon.AK47_Parent”, rel = “”, pos = Vector(-0.519, 3.635, 10.909), angle = Angle(-87.663, 0, 22.208), size = Vector(0.5, 0.5, 0.5), color = Color(120, 120, 120, 255), surpresslightning = false, material = “metal2”, skin = 0, bodygroup = {} }
}

SWEP.WElements = {
[“barrel”] = { type = “Model”, model = “models/props_c17/canister02a.mdl”, bone = “ValveBiped.Bip01_R_Hand”, rel = “”, pos = Vector(5.714, 1.557, -4.676), angle = Angle(106.363, -108.701, -71.3), size = Vector(0.755, 0.755, 0.755), color = Color(60, 60, 60, 255), surpresslightning = false, material = “bmw”, skin = 0, bodygroup = {} },
[“sight”] = { type = “Model”, model = “models/props_c17/pulleywheels_small01.mdl”, bone = “ValveBiped.Bip01_R_Hand”, rel = “”, pos = Vector(18.181, 1.5, -11.948), angle = Angle(-12.858, 0, -160.131), size = Vector(0.5, 0.5, 0.5), color = Color(120, 120, 120, 255), surpresslightning = false, material = “metal2”, skin = 0, bodygroup = {} }
}
[/lua]

This should be fixed, self:EmitSound() needs an argument of the sound, “cynosure/blast.wav” is just a string, Sound(“cynosure/blast.wav”) is a path and a file for the sound to play, also you don’t GetNextPrimaryFire() when trying to set Delay, that function just gets the number of when the NextPrimaryFire can be performed, you use SetNextPrimaryFire() to set it.

Also util.Precache sound also takes an arguemnt of Sound() not just string.

There is still the typo in that code that says EmitSount instead of EmitSound


self:EmitSount()

oh and don’t forget

util.PrecacheSound instead of


util.PrechacheSound()

Honestly it looks like this code he submitted in the OP was already stolen if he has no clue how to code.

You’re the epitome of everything wrong with the workshop community. We didn’t immediately give you code, so now you’re going to go to someone else’s addon that THEY worked on and you’re going to download it, slap some GB model onto it and call it your own.