'(' expected near 'if'

I am getting this error:

weapons estswep\shared.lua:52: ‘(’ expected near ‘if’

Here is line 52-56 of the code:



if ( !self:CanPrimaryAttack() ) then return end
self:ShootBullet( 0, 0, 0 )
self:TakePrimaryAmmo( 0 )
self.Owner:ViewPunch( Angle( 0, 0, 0 ) )
self.Weapon:SetNextPrimaryFire( CurTime() + 0.15 )

I see nothing wrong…if you need more, tell me.

That’s not where the error is located, it’s most likely at the other end of your code. A good way to find out where it is yourself is making sure your pairs of parenthesis match properly using Notepad++'s syntax highlighting.

Otherwise post the whole block/file.



if ( SERVER ) then

	AddCSLuaFile( "shared.lua" )
	
	SWEP.HoldType			= "SLAM"
	
end

if ( CLIENT ) then

SWEP.PrintName				= "The Baby-Laser"			
SWEP.Author				= "TacoNinja1995"
SWEP.Category				= "SECRET"
SWEP.Slot				= 5
SWEP.SlotPos				= 1
SWEP.ViewModelFOV			= 60
SWEP.IconLetter				= "c"

end

SWEP.Author   	    			= "TacoNinja1995"
SWEP.Contact        			= ""
SWEP.Purpose        			= "Laser things."
SWEP.Instructions   			= "Use the Laser Baby to wreak havoc!"
SWEP.Spawnable      			= false
SWEP.AdminSpawnable  			= true
SWEP.ViewModel      			= "models/weapons/v_crowbar.mdl"
SWEP.WorldModel   				= "models/weapons/w_crowbar.mdl"
SWEP.Primary.Delay				= .0001 	
SWEP.Primary.Recoil				= .000001		
SWEP.Primary.Damage				= 50	
SWEP.Primary.NumShots			= 10		
SWEP.Primary.Cone				= .0001
SWEP.Primary.ClipSize			= 1	
SWEP.Primary.DefaultClip		= -1	
SWEP.Primary.Automatic   		= true	
SWEP.Primary.Ammo         		= "none"	
 
	function SWEP:Reload()
end 
 
	function SWEP:Think()
end

function SWEP:Initialize()
util.PrecacheSound("sounds/TFAS/BabyLaser/BabyLasershoot.wav")
end

function SWEP.PrimaryAttack


if ( !self:CanPrimaryAttack() ) then return end
self:ShootBullet( 0, 0, 0 )
self:TakePrimaryAmmo( 0 )
self.Owner:ViewPunch( Angle( 0, 0, 0 ) )
self.Weapon:SetNextPrimaryFire( CurTime() + 0.15 )

local trace = self.Owner:GetEyeTrace()
local effectdata = EffectData()
effectdata:SetOrigin( trace.HitPos )
effectdata:SetNormal( trace.HitNormal )
effectdata:SetEntity( trace.Entity )
effectdata:SetAttachment( trace.PhysicsBone )
util.Effect( "super_explosion", effectdata )

local effectdata = EffectData()
effectdata:SetOrigin( trace.HitPos )
effectdata:SetStart( self.Owner:GetShootPos() )
effectdata:SetAttachment( 1 )
effectdata:SetEntity( self.Weapon )
util.Effect( "BabyLaser/Babybeam", effectdata )
if (SERVER) then
local owner=self.Owner
if self.Owner.SENT then
owner=self.Owner.SENT.Entity
end

local explosion = ents.Create( "env_explosion" )
explosion:SetPos(trace.HitPos)
explosion:SetKeyValue( "iMagnitude" , "150" )
explosion:SetPhysicsAttacker(owner)
explosion:SetOwner(owner)
explosion:Spawn()
explosion:Fire("explode","",0)
explosion:Fire("kill","",0 )

end

function SWEP:ShootEffects()
 
	self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
	self.Owner:MuzzleFlash("materials/weapons/babylaser/babybeam.vtf")
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
 	self:ShootEffects();
 	local explode = ents.Create( "env_explosion" )
 	explode:SetPos( eyetrace.HitPos )
 	explode:SetOwner( self.Owner )
 	explode:Spawn()
  	explode:SetKeyValue( "iMagnitude", "125" )
  	explode:Fire( "Explode", 0, 0 )
end

function SWEP:PrimaryAttack()
self.Weapon:EmitSound("sounds/TFAS/BabyLaser/SOUND.wav")
self.Weapon:SendWeaponAnim(ACT_VM_HITKILL)

end

[lua]function SWEP.PrimaryAttack[/lua]

Should be

[lua]function SWEP.PrimaryAttack()[/lua]

EDIT:
The actual function is a bit lower though, put all code in SWEP.PrimaryAttack() in the SWEP:PrimaryAttack() function

What do you mean? Take out double spaces?

No, there are two functions in your code, the first is SWEP.PrimaryFire and the second is SWEP:PrimaryFire(). Copy all code from the first to the second one.

This should work:
[lua]if ( SERVER ) then

AddCSLuaFile( "shared.lua" )

SWEP.HoldType			= "SLAM"

end

if ( CLIENT ) then

SWEP.PrintName = “The Baby-Laser”
SWEP.Author = “TacoNinja1995”
SWEP.Category = “SECRET”
SWEP.Slot = 5
SWEP.SlotPos = 1
SWEP.ViewModelFOV = 60
SWEP.IconLetter = “c”

end

SWEP.Author = “TacoNinja1995”
SWEP.Contact = “”
SWEP.Purpose = “Laser things.”
SWEP.Instructions = “Use the Laser Baby to wreak havoc!”
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.ViewModel = “models/weapons/v_crowbar.mdl”
SWEP.WorldModel = “models/weapons/w_crowbar.mdl”
SWEP.Primary.Delay = .0001
SWEP.Primary.Recoil = .000001
SWEP.Primary.Damage = 50
SWEP.Primary.NumShots = 10
SWEP.Primary.Cone = .0001
SWEP.Primary.ClipSize = 1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = “none”

function SWEP:Reload()

end

function SWEP:Think()

end

function SWEP:Initialize()
util.PrecacheSound(“sounds/TFAS/BabyLaser/BabyLasershoot.wav”)
end

function SWEP:ShootEffects()

self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Owner:MuzzleFlash("materials/weapons/babylaser/babybeam.vtf")
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self:ShootEffects();
local explode = ents.Create( "env_explosion" )
explode:SetPos( eyetrace.HitPos )
explode:SetOwner( self.Owner )
explode:Spawn()
explode:SetKeyValue( "iMagnitude", "125" )
explode:Fire( "Explode", 0, 0 )

end

function SWEP:PrimaryAttack()

if ( !self:CanPrimaryAttack() ) then return end
self:ShootBullet( 0, 0, 0 )
self:TakePrimaryAmmo( 0 )
self.Owner:ViewPunch( Angle( 0, 0, 0 ) )
self.Weapon:SetNextPrimaryFire( CurTime() + 0.15 )

local trace = self.Owner:GetEyeTrace()
local effectdata = EffectData()
effectdata:SetOrigin( trace.HitPos )
effectdata:SetNormal( trace.HitNormal )
effectdata:SetEntity( trace.Entity )
effectdata:SetAttachment( trace.PhysicsBone )
util.Effect( “super_explosion”, effectdata )

local effectdata = EffectData()
effectdata:SetOrigin( trace.HitPos )
effectdata:SetStart( self.Owner:GetShootPos() )
effectdata:SetAttachment( 1 )
effectdata:SetEntity( self.Weapon )
util.Effect( “BabyLaser/Babybeam”, effectdata )
if (SERVER) then
local owner=self.Owner
if self.Owner.SENT then
owner=self.Owner.SENT.Entity
end

local explosion = ents.Create( “env_explosion” )
explosion:SetPos(trace.HitPos)
explosion:SetKeyValue( “iMagnitude” , “150” )
explosion:SetPhysicsAttacker(owner)
explosion:SetOwner(owner)
explosion:Spawn()
explosion:Fire(“explode”,"",0)
explosion:Fire(“kill”,"",0 )

self.Weapon:EmitSound(“sounds/TFAS/BabyLaser/SOUND.wav”)
self.Weapon:SendWeaponAnim(ACT_VM_HITKILL)

end[/lua]

The error was coming from this :
function SWEP.PrimaryAttack

You’re defining a function as part of the SWEP table, but never use () to specify the arguments. This is what was expected.

It should also be a method, so function SWEP:PrimaryAttack() like thejjokerr posted. You should also indent your code better and I suggest you make SWEP.HoldType a shared value. It will save you trouble for later.

Well, that worked, but now I get this:
“weapons\babylaser\shared.lua:51: attempt to index global ‘self’ (a nil value)”

I think I see it…


self:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) 

should ACTUALLY be


self.SendWeaponAnim( ACT_VM_PRIMARYATTACK ) 

That fixed the error, but, how do I make the effect “babybeam.vmt” work?



 local effectdata = EffectData()  
 effectdata:SetOrigin( trace.HitPos )  
 effectdata:SetStart( self.Owner:GetShootPos() )  
 effectdata:SetAttachment( 1 )  
 effectdata:SetEntity( self.Weapon )  
 util.Effect( "BabyLaser/Babybeam", effectdata )  
 if (SERVER) then  
 local owner=self.Owner  
 if self.Owner.SENT then  
owner=self.Owner.SENT.Entity  
end

I have it in garrysmod/garrysmod/addons/addonname/materials/effects/babylaser/babybeam.vmt