-- Handy table function.
function table.CleanUpKeys( Tbl )
	local i = 1;
	local Output = {};
	
	for k, v in pairs( Tbl ) do
		if ( v ) then
			Output[ i ] = v;
			i = i + 1;
		end;
	end;

	return Output;
end;

-- Trace a entity on given distance, easier of use function.
function _R.Player:EyeTrace( dis )
	local tr = {};
	tr.start = self:GetShootPos();
	tr.endpos = tr.start + ( self:GetCursorAimVector() * dis );
	tr.filter = self;
	tr = util.TraceLine( tr );
	return tr;
end;

-- Function to trace a door.
function _R.Player:TraceDoor( dist )
	local tr = self:EyeTrace( dist );
	local Entity = tr.Entity;
	
	if ( Entity:IsValid() and Entity:IsDoor() ) then
		return Entity;
	end;
end;

-- Easier to use function to trace a player.
function _R.Player:TracePlayer( dist )
	local tr = self:EyeTrace( dist );
	local Entity = tr.Entity;
	
	if ( Entity:IsValid() and Entity:IsPlayer() ) then
		return Entity;
	end;
end;


local ValidDoorTypes =
{
	"func_door",
	"func_door_rotating",
	"prop_door_rotating"
};

-- Function to check if a entity class is a door.
function _R.Entity:IsDoor()
	for k, v in pairs( ValidDoorTypes ) do
		if ( self:GetClass() == v ) then
			return true;
		end;
	end;
	
	return false;
end;