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

if ( CLIENT ) then
	SWEP.Slot				= 1;
	SWEP.SlotPos			= 1;
	SWEP.ViewModelFOV		= 60;
	SWEP.DrawAmmo = false;
end;

SWEP.Base = "eps_base";

SWEP.PrintName			= "Stunstick";
SWEP.Author				= "Chewgum";
SWEP.Instructions = "Left click to hit someone.";

SWEP.AdminSpawnable	= true;

SWEP.WorldModel = Model( "models/weapons/w_stunbaton.mdl" );
SWEP.ViewModel = Model( "models/weapons/v_stunstick.mdl" );

SWEP.Primary.ClipSize		= - 1;
SWEP.Primary.Delay			= 1;
SWEP.Primary.DefaultClip	= 0;
SWEP.Primary.Automatic		= true;
SWEP.Primary.Ammo			= "";

SWEP.Secondary.ClipSize		= - 1;
SWEP.Secondary.DefaultClip	= 0;
SWEP.Secondary.Automatic	= true;
SWEP.Secondary.Ammo			= "";

function SWEP:Initialize()
	self.HitSounds = {
		Sound( "weapons/stunstick/stunstick_fleshhit2.wav" ),
		Sound( "weapons/stunstick/stunstick_impact2.wav" ),
		Sound( "weapons/stunstick/stunstick_fleshhit1.wav" )
	};
	
	self.SwingSounds = {
		Sound( "weapons/stunstick/stunstick_swing1.wav" ),
		Sound( "weapons/stunstick/stunstick_swing2.wav" )
	};
end;

SWEP.Primary.Delay = 1;
function SWEP:PrimaryAttack()
	if ( CurTime() < self.Primary.Delay ) then return end
	
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
	self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )

	self.Primary.Delay = CurTime() + 1

	local tr = self.Owner:EyeTrace( 90 )

	if( tr.Hit or tr.Entity:IsValid() ) then
		if ( tr.Entity:IsPlayer() ) then
			local bullet = {}
			bullet.Num = 1
			bullet.Src = self.Owner:GetShootPos()
			bullet.Dir = self.Owner:GetAimVector()
			bullet.Spread = Vector( 0, 0, 0 )
			bullet.Tracer = 0
			bullet.Force = 54
			bullet.Damage = math.random( 1, 6 )
			self.Owner:FireBullets( bullet )
		end
		
		if( SERVER ) then
			if( tr.Entity:IsValid() ) then
				local norm = ( tr.Entity:GetPos() - self.Owner:GetPos() ):Normalize()
				local push = 8000 * norm
				
				if( tr.Entity:IsPlayer() ) then
					push = 100 * norm
					tr.Entity:SetVelocity( push )
					if ( tr.Entity:Health() < 30 and tr.Entity:Health() > 6 ) then
						tr.Entity:Ragdoll( 30 )
					end
				else
					tr.Entity:GetPhysicsObject():ApplyForceOffset( push, tr.HitPos )
				end
			end
		end
		self.Weapon:EmitSound( self.HitSounds[ math.random( 1, #self.HitSounds ) ] )
	else
		self.Weapon:EmitSound( self.SwingSounds[ math.random( 1, #self.SwingSounds ) ] )
	end
end

function SWEP:SecondaryAttack()
end;