epsilonScript.Holster = {};
epsilonScript.Holster.Stored = {};

epsilonScript.Holster.Stored.NeverHolsteredWeapons = 
{
	"weapon_physcannon",
	"weapon_physgun",
	"gmod_tool",
	"eps_keys"
};

epsilonScript.Holster.Stored.WeaponsUseableHolstered =
{
	"eps_keys"
};

function epsilonScript.Holster.AddNewHolstertype( wep, original, holster )
	local Tbl = {};
	Tbl.OriginalHoldType = original;
	Tbl.HolsterHoldType = holster;
	
	epsilonScript.Holster.Stored[ wep ] = Tbl;
end;

function epsilonScript.Holster.GetWeaponHolsterType( wep, holstertype )
	if ( epsilonScript.Holster.Stored[ wep ] ) then
		return epsilonScript.Holster.Stored[ wep ][ holstertype ];
	else
		Error( "epsilonScript Holster system error: Weapon '" .. wep .. "' holster type was not found in database!" );
	end;
end;

function epsilonScript.Holster.PlayerHolster( ply )
	ply:DrawViewModel( false );
	ply:SetNWBool( "Holstered", true );
	
	if ( table.HasValue( epsilonScript.Holster.Stored.NeverHolsteredWeapons, ply:GetActiveWeapon():GetClass() ) ) then return; end;
	if ( ply:GetActiveWeapon():IsValid() ) then
		local weaponHolsterType = epsilonScript.Holster.GetWeaponHolsterType( ply:GetActiveWeapon():GetClass(), "HolsterHoldType" );
		
		ply:GetActiveWeapon():SetWeaponHoldType( weaponHolsterType );
	end;
end;

function epsilonScript.Holster.PlayerUnHolster( ply )
	ply:DrawViewModel( true );
	ply:SetNWBool( "Holstered", false );
	
	if ( ply:GetActiveWeapon():IsValid() ) then
		local weaponHolsterType = epsilonScript.Holster.GetWeaponHolsterType( ply:GetActiveWeapon():GetClass(), "OriginalHoldType" );
		
		ply:GetActiveWeapon():SetWeaponHoldType( weaponHolsterType );
	end;
end;

function epsilonScript.Holster.ToggleHolster( ply, cmd, args )
	local ActiveWeapon = ply:GetActiveWeapon();
	
	if ( ActiveWeapon:IsValid() ) then
		if ( table.HasValue( epsilonScript.Holster.Stored.NeverHolsteredWeapons, ActiveWeapon:GetClass() ) ) then return; end;
		
		if ( ply:GetNWBool( "Holstered" ) ) then
			epsilonScript.Holster.PlayerUnHolster( ply );
		else
			epsilonScript.Holster.PlayerHolster( ply );
		end;
	end;
end;
concommand.Add( "rp_toggleholster", epsilonScript.Holster.ToggleHolster );

epsilonScript.Holster.AddNewHolstertype( "eps_mp7", "smg", "passive" );
epsilonScript.Holster.AddNewHolstertype( "eps_9mm", "pistol", "normal" );
epsilonScript.Holster.AddNewHolstertype( "eps_shotgun", "shotgun", "passive" );
epsilonScript.Holster.AddNewHolstertype( "eps_hands", "fists", "normal" );
epsilonScript.Holster.AddNewHolstertype( "eps_stunstick", "melee", "normal" );