SWEP help

I’m trying to make a SWEP that only fires when crouched.

Here’s the important part…


function SWEP:CanPrimaryAttack()
   if not IsValid(self.Owner) then return end

   if self.Weapon:Clip1() <= 0 or self:GetIronsights() == false then
      self:DryFire(self.SetNextPrimaryFire)
	  self:SetNextSecondaryFire(CurTime() +0.05)
      return false
   end
   return true
end


I wanted to just do this:


function SWEP:CanPrimaryAttack()
   if not IsValid(self.Owner) then return end

   if self.Weapon:Clip1() <= 0 or self:GetIronsights() == false or Player:Crouching() == false then
      self:DryFire(self.SetNextPrimaryFire)
	  self:SetNextSecondaryFire(CurTime() +0.05)
      return false
   end
   return true
end


But I get that “attempt to index global ‘player’ (a function value)” error…

you need to define player. or just be lazy.



function SWEP:CanPrimaryAttack()
   if not IsValid(self.Owner) then return end

   if self.Weapon:Clip1() <= 0 or self:GetIronsights() == false or self.Owner:Crouching() == false then
      self:DryFire(self.SetNextPrimaryFire)
	  self:SetNextSecondaryFire(CurTime() +0.05)
      return false
   end
   return true
end


Wow, how did I miss that.
Well, anyway, thnx, your’s worked.