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

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

SWEP.Base = "eps_base";

SWEP.PrintName			= "Keys";
SWEP.Author				= "Chewgum";
SWEP.Instructions = "Left click to lock your door.\nRight click to unlock your door.";

SWEP.AdminSpawnable		= true;

SWEP.WorldModel = Model( "models/weapons/w_fists.mdl" );
SWEP.ViewModel = Model( "models/weapons/v_fists.mdl" );

SWEP.Primary.Sound = Sound( "doors/door_latch1.wav" );
SWEP.Primary.ClipSize		= - 1;
SWEP.Primary.Delay			= 1;
SWEP.Primary.DefaultClip	= 0;
SWEP.Primary.Automatic		= true;
SWEP.Primary.Ammo			= "";

SWEP.Secondary.Sound = Sound( "doors/door_latch3.wav" );
SWEP.Secondary.ClipSize		= - 1;
SWEP.Secondary.DefaultClip	= 0;
SWEP.Secondary.Automatic	= true;
SWEP.Secondary.Ammo			= "";

function SWEP:PrimaryAttack()
	if ( SERVER ) then if ( !self.Owner:GetNWBool( "Holstered" ) and !epsilonScript..Holster.Stored.WeaponsUseableHolstered[ self.Weapon:GetClass() ] ) then return end; end;
	
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay );
	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK );
	
	local Door = self.Owner:TraceDoor( 90 );
	
	if ( SERVER ) then
		if ( Door ) then
			if ( self.Owner:OwnsDoor( Door ) ) then
				self.Owner:SetAnimation( PLAYER_ATTACK1 );
				Door:Fire( "lock", "", 0 );
				self.Owner:EmitSound( self.Primary.Sound );
			else
				self.Owner:ChatPrint( "You do not own this door!" ) return;
			end;
		end;
	end;
end;

function SWEP:SecondaryAttack()
	if ( SERVER ) then if ( !self.Owner:GetNWBool( "Holstered" ) and !epsilonScript..Holster.Stored.WeaponsUseableHolstered[ self.Weapon:GetClass() ] ) then return end; end;
	
	self.Weapon:SetNextSecondaryFire( CurTime() + 1 );
	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK );
	
	local Door = self.Owner:TraceDoor( 90 )
	
	if ( SERVER ) then
		if ( Door ) then
			if ( self.Owner:OwnsDoor( Door ) ) then
				self.Owner:SetAnimation( PLAYER_ATTACK1 );
				Door:Fire( "unlock", "", 0 );
				self.Owner:EmitSound( self.Secondary.Sound );
			else
				self.Owner:ChatPrint( "You do not own this door!" ) return;
			end;
		end;
	end;
end;
