

if( SERVER ) then

	AddCSLuaFile( "shared.lua" );

end

SWEP.PrintName = "Medic Syringe";

if( CLIENT ) then

	SWEP.Slot = 5;
	SWEP.SlotPos = 1;
	SWEP.DrawAmmo = false;
	SWEP.DrawCrosshair = false;

end

SWEP.InvSize = 1;
SWEP.InvWeight = .7;

// Variables that are used on both client and server

SWEP.Author			= "Disseminate"
SWEP.Instructions	= "Left click to heal others.\nRight click to heal yourself."
SWEP.Contact		= ""
SWEP.Purpose		= ""
SWEP.Invisible 		= true;

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

SWEP.ViewModelFOV	= 62
SWEP.ViewModelFlip	= false
SWEP.AnimPrefix		= "rpg"

SWEP.Spawnable			= false
SWEP.AdminSpawnable		= true
  
SWEP.Sound = "doors/door_latch3.wav";
  
SWEP.Primary.ClipSize		= -1					// Size of a clip
SWEP.Primary.DefaultClip	= 0				// Default number of bullets in a clip
SWEP.Primary.Automatic		= true				// Automatic/Semi Auto
SWEP.Primary.Ammo			= ""

SWEP.Secondary.ClipSize		= -1				// Size of a clip
SWEP.Secondary.DefaultClip	= 0				// Default number of bullets in a clip
SWEP.Secondary.Automatic	= true				// Automatic/Semi Auto
SWEP.Secondary.Ammo			= ""

SWEP.Healing = false;
local sound_heal = Sound( "items/medcharge4.wav" );

/*---------------------------------------------------------
   Name: SWEP:Initialize( )
   Desc: Called when the weapon is first loaded
---------------------------------------------------------*/
function SWEP:Initialize()
	
	if( SERVER ) then
		
		if( not self.SoundLoop ) then
	
			self.SoundLoop = CreateSound( self, sound_heal );
			
		end
		
		self:SetWeaponHoldType( "normal" );
	
	end

end


/*---------------------------------------------------------
   Name: SWEP:Precache( )
   Desc: Use this function to precache stuff
---------------------------------------------------------*/
function SWEP:Precache()
end

function SWEP:Deploy()

	if( SERVER ) then

		self.Owner:DrawViewModel( false );
		self.Owner:DrawWorldModel( false );
		self.Weapon:SetNextPrimaryFire( CurTime() );
		self.Weapon:SetNextSecondaryFire( CurTime() );
		
	end

end

/*---------------------------------------------------------
   Name: SWEP:PrimaryAttack( )
   Desc: +attack1 has been pressed
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
  
  	if( CLIENT ) then return; end
  	
	if( self.Owner:GetNWInt( "lyingdown" ) == 1 ) then return; end
  
  	if( self.Healing ) then return; end
  
	local trace = { }
	trace.start = self.Owner:EyePos();
	trace.endpos = trace.start + self.Owner:GetAimVector() * 60;
	trace.filter = self.Owner;
		
	local tr = util.TraceLine( trace );
		
	if( tr.Entity:IsValid() and ( tr.Entity:IsPlayer() or tr.Entity:IsPlayerRagdoll() ) ) then
		
		if( tr.Entity:IsPlayerRagdoll() ) then
			tr.Entity = tr.Entity:GetPlayer();
		end
		
		self.SoundLoop:Play();
		tr.Entity:SetHealth( math.Clamp( tr.Entity:Health() + 0.33, 0, 100 ) );
		self.Weapon:SetNextPrimaryFire( CurTime() + 0.1 );
	
	end

end
 
/*---------------------------------------------------------
	SecondaryAttack
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
	
  	if( CLIENT ) then return; end
  	
	if( self.Owner:GetNWInt( "lyingdown" ) == 1 ) then return; end
	
	self.SoundLoop:Play();
	self.Owner:SetHealth( math.Clamp( self.Owner:Health() + 1, 0, 100 ) );
	self.Weapon:SetNextSecondaryFire( CurTime() + 0.3 );
	
end

function SWEP:Think()
	
	if( SERVER ) then
	
		if( not ( self.Owner:KeyDown( IN_ATTACK ) or self.Owner:KeyDown( IN_ATTACK2 ) ) ) then
		
			self.SoundLoop:Stop();
			
		end
		
	end
	
end
	