Hi everybody, I am creating a SWEP of a whistle that if you hold left will sound. When I enter gmod, I get this error:
[ERROR] lua/weapons/weapon_whistle.lua:46: '=' expected near 'then'
1. unknown - lua/weapons/weapon_whistle.lua:0
Here I leave my script
AddCSLuaFile()
SWEP.PrintName = "Police Whistle"
SWEP.Author = "ItzDannio25"
SWEP.Contact = "inklingsplat25@gmail.com"
SWEP.Purpose = "Whistle for cops!"
SWEP.Instructions = "Left click to sound"
SWEP.Category = "HL2"
SWEP.Spawnable= true
SWEP.AdminSpawnable= true
SWEP.AdminOnly = false
SWEP.ViewModelFOV = 70
SWEP.ViewModel = "models/weapons/v_smg1.mdl"
SWEP.WorldModel = "models/weapons/w_smg1.mdl"
SWEP.ViewModelFlip = false
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.UseHands = true
SWEP.HoldType = "Pistol"
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
if SERVER then
AddCSLuaFile(weapon_whistle.lua)
resource.AddFile( "sound/weapons/whistle/whistlesound.mp3" )
resource.AddFile( "model/weapons/sv_smg1.mdl" )
resource.AddFile( "materials/whistle/selectionwhistle.png" )
resource.AddFile( "materials/whistle/whistle.vtf" )
endif CLIENT then
SWEP.SlotPos = 3
SWEP.Slot = 1
SWEP.WepSelectIcon = Material( "nyan/selection.png" )
SWEP.BounceWeaponIcon = false
SWEP.DrawWeaponInfoBox = falseend
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"
endfunction SWEP:PrimaryAttack()if ( !self:CanPrimaryAttack() ) thenreturnendif (self.Owner:IsNPC()) then
self:EmitSound( "sound/whistle/whistlesound.mp3" .. math.random( 1, 2 ) .. ".mp3", 100, math.random( 60, 80 ) )
elseif ( self.LoopSound ) then
self.LoopSound:ChangeVolume( 1, 0.1 )
else
self.LoopSound = CreateSound( self.Owner, Sound( "sound/whistle/whistlesound.mp3" ) )
if ( self.LoopSound ) then self.LoopSound:Play() endendif ( self.BeatSound ) then self.BeatSound:ChangeVolume( 0, 0.1 )
SWEP.EquipMenuData = {
name = "Whistle",
type = "item_weapon",
desc = "Play a whistle sound"
};
SWEP.Kind = WEAPON_EQUIP
SWEP.CanBuy = {ROLE_DETECTIVE, ROLE_TRAITOR}
SWEP.LimitedStock = false
SWEP.Icon = "whistle\selectionwhistle.png"
Why this happens? anyone knows? i'm new at Lua programming.
How about you read the Error message? I went down to line 45/46 and instantly found the mistake.
You wrote end and if together. It says
endif CLIENT then
Thanks lmao, i didn't see it, sorry about that (i started learning Lua today lol)
then i suggest learning lua a bit first, getting the basics, instead of doing something and then coming here as soon as theres a problem?
Sorry, you need to Log In to post a reply to this thread.