SWEP.WepSelectIcon = Material("vgui/entities/hud_ump_icon.png")

if CLIENT then
	function SWEP:DrawWeaponSelection(x, y, w, h, a)
		surface.SetDrawColor(255, 255, 255, a)
		surface.SetMaterial(self.WepSelectIcon)
		
		local size = math.min(w, h)
		surface.DrawTexturedRect(x + 40, y, size - 25, size - 25)
	end
end

SWEP.PrintName = ".45 PDW NPC"
    
SWEP.Author = "MAC10"
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = ""

SWEP.Category = "what"

SWEP.Spawnable= false
SWEP.AdminSpawnable= false
SWEP.AdminOnly = false

SWEP.CSMuzzleFlashes = true
SWEP.ViewModelFOV = 60
SWEP.ViewModel = "models/weapons/cstrike/c_smg_ump45.mdl"
SWEP.WorldModel = "models/weapons/w_rif_ak47.mdl"


SWEP.ViewModelFlip = false
SWEP.ShowWorldModel = true


SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = true

SWEP.Slot = 1
SWEP.SlotPos = 1
 
SWEP.UseHands = true

SWEP.HoldType = "smg" 

SWEP.FiresUnderwater = true

SWEP.DrawCrosshair = true

SWEP.DrawAmmo = true

SWEP.Base = "weapon_base"

SWEP.Primary.Sound = Sound("Lonely.AK47_FireNPC") 
SWEP.Primary.Damage = 8
SWEP.Primary.TakeAmmo = 1
SWEP.Primary.ClipSize = 45
SWEP.Primary.Ammo = "Pistol"
SWEP.Primary.DefaultClip = 90
SWEP.Primary.Spread = 0.3
SWEP.Primary.NumberofShots = 1
SWEP.Primary.Automatic = true
SWEP.Primary.Recoil = 0.4
SWEP.Primary.Delay = 1
SWEP.Primary.Force = 1
SWEP.ShowWorldModel = true
SWEP.ShowViewModel = true

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"

function SWEP:Initialize()
		util.PrecacheSound("Lonely.AK47_FireNPC")
        self:SetWeaponHoldType("ar2")
end 

function SWEP:Deploy()
	self:SendWeaponAnim( ACT_VM_DRAW )
	self:SetNextPrimaryFire( CurTime() + self:SequenceDuration() )

	return true
end 

function SWEP:PrimaryAttack()
 
if ( !self:CanPrimaryAttack() ) then return end

		local fx = EffectData()
		fx:SetEntity(self.Weapon)
		fx:SetOrigin(self.Owner:GetPos())
		fx:SetNormal(self.Owner:GetAimVector())
		fx:SetAttachment(1)
		fx:SetFlags(7)
		util.Effect("MuzzleFlash",fx)
 
local bullet = {} 
bullet.Num = self.Primary.NumberofShots 
bullet.Src = self.Owner:GetShootPos() 
bullet.Dir = self.Owner:GetAimVector() 
bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
bullet.Tracer = 1
bullet.TracerName = "Tracer" 
bullet.Force = self.Primary.Force 
bullet.Damage = self.Primary.Damage 
bullet.AmmoType = self.Primary.Ammo 

self.Owner:EmitSound(Sound(self.Primary.Sound))
 
self:ShootEffects()
 
self.Owner:FireBullets( bullet ) 
self:TakePrimaryAmmo(self.Primary.TakeAmmo) 
 
self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self:SetNextSecondaryFire( CurTime() + self.Primary.Delay ) 

end

function SWEP:OnDrop()
	self:Remove()
end

function SWEP:SecondaryAttack()
end

function SWEP:GetNPCRestTimes()

	-- Handles the time between bursts
	-- Min rest time in seconds, max rest time in seconds

	return 0.4, 0.9

end

function SWEP:GetNPCBurstSettings()

	-- Handles the burst settings
	-- Minimum amount of shots, maximum amount of shots, and the delay between each shot
	-- The amount of shots can end up lower than specificed

	return 4, 12, 0.15

end

function SWEP:GetNPCBulletSpread( proficiency )

	-- Handles the bullet spread based on the given proficiency
	-- return value is in degrees

	return 7

end