I am very new to Lua coding, and as such I followed a tutorial to make a chair gun to learn the ropes. But, when I ran my code i got the following error in the console:
[ERROR] addons/chairlauncher/lua/weapons/chairgun.lua:51: '(' expected near 'self'
1. unknown - addons/chairlauncher/lua/weapons/chairgun.lua
Like I said, I'm new, but I really don't know why this is showing up, nor do I have a clue how to fix it. Any help would be appreciated, and I really hope this doesn't turn out to be an embarrassingly simply issue. My source code is down below:
_________________________________________________________________________________
[CODE]SWEP.PrintName = "Chair Thrower"
SWEP.Author = "JGAm3r"
SWEP.Instructions = "Left mouse to fire a chair!"
SWEP.Spawnable = true
SWEP.AdminOnly = false
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.Slot = 1
SWEP.SlotPos = 2
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
local ShootSound = Sound( "Metal.SawbladeStick" )
local ShootSound2 = Sound( "HealthKit.Touch" )
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
self:ThrowChair( "models/props/cs_office/Chair_office.mdl" )
end
function SWEP:SecondaryAttack()
self:ThrowChair2( "models/props_c17/FurnitureChair001a.mdl" )
end
function SWEP:Reload
self:ThrowMelon( "models/props_junk/watermelon01.mdl" )
end
function SWEP:ThrowChair( model_file )
self:EmitSound( ShootSound )
if ( CLIENT ) then return end
local ent = ents.Create( "prop_physics" )
if ( !IsValid( ent ) ) then return end
ent:SetModel( model_file )
ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) )
ent:SetAngles( self.Owner:EyeAngles() )
ent:Spawn()
local phys = ent:GetPhysicsObject()
if ( !IsValid( phys ) ) then ent:Remove() return end
local velocity = self.Owner:GetAimVector()
velocity = velocity * 100
velocity = velocity + ( VectorRand() * 10 ) -- a random element
phys:ApplyForceCenter( velocity )
cleanup.Add( self.Owner, "props", ent )
undo.Create( "Thrown_Chair" )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()
end
function SWEP:ThrowChair2( model_file )
self:EmitSound( ShootSound2 )
if ( CLIENT ) then return end
local ent = ents.Create( "prop_physics" )
if ( !IsValid( ent ) ) then return end
ent:SetModel( model_file )
ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) )
ent:SetAngles( self.Owner:EyeAngles() )
ent:Spawn()
local phys = ent:GetPhysicsObject()
if ( !IsValid( phys ) ) then ent:Remove() return end
local velocity = self.Owner:GetAimVector()
velocity = velocity * 100
velocity = velocity + ( VectorRand() * 10 ) -- a random element
phys:ApplyForceCenter( velocity )
cleanup.Add( self.Owner, "props", ent )
undo.Create( "Thrown_Chair" )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()
end
function SWEP:ThrowMelon( model_file )
if ( CLIENT ) then return end
local ent = ents.Create( "prop_physics" )
if ( !IsValid( ent ) ) then return end
ent:SetModel( model_file )
ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) )
ent:SetAngles( self.Owner:EyeAngles() )
ent:Spawn()
local phys = ent:GetPhysicsObject()
if ( !IsValid( phys ) ) then ent:Remove() return end
local velocity = self.Owner:GetAimVector()
velocity = velocity * 1000
velocity = velocity + ( VectorRand() * 10 ) -- a random element
phys:ApplyForceCenter( velocity )
entity to the cleanup and undo lists. This is done like so.
cleanup.Add( self.Owner, "props", ent )
undo.Create( "Thrown_Chair" )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()
end[/CODE]
First of all, wrap your post in code tags
Your error is telling you what is wrong and how to fix it. At line 51 a parentheses was expected but was not found.
This is the fix:
[CODE]function SWEP:Reload()
self:ThrowMelon( "models/props_junk/watermelon01.mdl" )
end [/CODE]
You did not put the () after SWEP:Reload.
[QUOTE=Fortune11709;43576420]First of all, wrap your post in code tags
Your error is telling you what is wrong and how to fix it. At line 51 a parentheses was expected but was not found.
This is the fix:
[CODE]function SWEP:Reload()
self:ThrowMelon( "models/props_junk/watermelon01.mdl" )
end [/CODE]
You did not put the () after SWEP:Reload.[/QUOTE]
Not to mention this.
[code]local velocity = self.Owner:GetAimVector()
velocity = velocity * 1000
velocity = velocity + ( VectorRand() * 10 ) -- a random element
phys:ApplyForceCenter( velocity )
entity to the cleanup and undo lists. This is done like so. --You didn't comment out this line.
cleanup.Add( self.Owner, "props", ent )
undo.Create( "Thrown_Chair" )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()
end[/code]
[QUOTE=Fortune11709;43576420]First of all, wrap your post in code tags
Your error is telling you what is wrong and how to fix it. At line 51 a parentheses was expected but was not found.
This is the fix:
[CODE]function SWEP:Reload()
self:ThrowMelon( "models/props_junk/watermelon01.mdl" )
end [/CODE]
You did not put the () after SWEP:Reload.[/QUOTE]
Thank you for helping me out, for one. I didn't realize I needed parenthesis there, I was reading the error message as (' was expected near 'self'). Like I said, VERY new to this. And second, what is a code tag?
On your posts put [ CODE. ] before and [ ./CODE] after it. Without the fullstops and spaces in the tags.
[QUOTE=code_gs;43576428]Not to mention this.
[code]local velocity = self.Owner:GetAimVector()
velocity = velocity * 1000
velocity = velocity + ( VectorRand() * 10 ) -- a random element
phys:ApplyForceCenter( velocity )
entity to the cleanup and undo lists. This is done like so. --You didn't comment out this line.
cleanup.Add( self.Owner, "props", ent )
undo.Create( "Thrown_Chair" )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()
end[/code][/QUOTE]
OH, alright, I guess I missed that. Thank you.
[editline]17th January 2014[/editline]
[QUOTE=Fortune11709;43576555]On your posts put [ CODE. ] before and [ ./CODE] after it. Without the fullstops and spaces in the tags.[/QUOTE]
Oh, like HTML code? Alright. Are there any other things like I should know?
[editline]17th January 2014[/editline]
Sorry, you need to Log In to post a reply to this thread.