if SERVER then
   AddCSLuaFile( "shared.lua" )
end

SWEP.HoldType			= "ar2"
   

if CLIENT then

   SWEP.PrintName			= "M4A1"			
   SWEP.Author				= "noPE"
   SWEP.Slot				= 2
   SWEP.SlotPos			= 1
   SWEP.IconLetter			= "w"
end


SWEP.Base				= "weapon_cs_base"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.Primary.Delay			= 0.08
SWEP.Primary.Recoil			= 1.9
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "Pistol"
SWEP.Primary.Damage = 21
SWEP.Primary.Cone = 0.09
SWEP.Primary.ClipSize = 30
SWEP.Primary.ClipMax = 60
SWEP.Primary.DefaultClip = 30
SWEP.AutoSpawnable      = true
SWEP.ViewModel			= "models/weapons/v_rif_m4a1.mdl"
SWEP.WorldModel			= "models/weapons/w_rif_m4a1.mdl"

SWEP.Primary.Sound			= Sound( "Weapon_M4A1.Silenced" )

SWEP.IronSightsPos 		= Vector( 6, 0, 0.95 )
SWEP.IronSightsAng 		= Vector( 2.6, 1.37, 3.5 )

SWEP.PrimaryAnim = ACT_VM_PRIMARYATTACK_SILENCED
SWEP.ReloadAnim = ACT_VM_RELOAD_SILENCED

function SWEP:Deploy()
	self.Weapon:SendWeaponAnim( ACT_VM_DRAW_SILENCED )
	return true
end

function SWEP:CSShootBullet( dmg, recoil, numbul, cone )

	numbul 	= numbul 	or 1
	cone 	= cone 		or 0.01

	local bullet = {}
	bullet.Num 		= numbul
	bullet.Src 		= self.Owner:GetShootPos()			-- Source
	bullet.Dir 		= self.Owner:GetAimVector()			-- Dir of bullet
	bullet.Spread 	= Vector( cone, cone, 0 )			-- Aim Cone
	bullet.Tracer	= 4									-- Show a tracer on every x bullets 
	bullet.Force	= 5									-- Amount of force to give to phys objects
	bullet.Damage	= dmg
	
	self.Owner:FireBullets( bullet )
	self.Weapon:SendWeaponAnim( self.PrimaryAnim ) 		-- View model animation
	self.Owner:MuzzleFlash()								-- Crappy muzzle light
	self.Owner:SetAnimation( PLAYER_ATTACK1 )				-- 3rd Person Animation
	
	if ( self.Owner:IsNPC() ) then return end
	
	-- CUSTOM RECOIL !
	if ( (SinglePlayer() && SERVER) || ( !SinglePlayer() && CLIENT && IsFirstTimePredicted() ) ) then
	
		local eyeang = self.Owner:EyeAngles()
		eyeang.pitch = eyeang.pitch - recoil
		self.Owner:SetEyeAngles( eyeang )
	
	end

end

function SWEP:Reload()
   self.Weapon:DefaultReload( ACT_VM_RELOAD_SILENCED );
end


