--Automatic Transmission

function Auto()
	local maxSpin=0
	for i,v in pairs(Drive) do if v.RotVelocity.Magnitude>maxSpin then maxSpin = v.RotVelocity.Magnitude end end
	if _IsOn then
		_ClutchOn = true
		if _CGear >= 1 then
			if _GBrake > 0  and car.DriveSeat.Velocity.Magnitude < 5 then
				_CGear = 1
			else
				if _Tune.AutoShiftMode == "RPM" then
					if _RPM>(_Tune.PeakRPM+_Tune.AutoUpThresh) then
						if (_CGear ~= 0) and (_CGear ~= #_Tune.Ratios-2) then
							_GThrotShift = 0
							wait(_Tune.ShiftTime)
							_GThrotShift = 1
						end
						_CGear=math.min(_CGear+1,#_Tune.Ratios-2) 
					elseif math.max(math.min(maxSpin*_Tune.Ratios[_CGear+1]*fFDr,_Tune.Redline+100),_Tune.IdleRPM)<(_Tune.PeakRPM-_Tune.AutoDownThresh) then
						if _CGear ~= 1 then
							_GThrotShift = 0
							wait(_Tune.ShiftTime/2)
							_GThrotShift = 1
						end
						_CGear=math.max(_CGear-1,1)
					end
				else
					if car.DriveSeat.Velocity.Magnitude > math.ceil(wDRatio*(_Tune.PeakRPM+_Tune.AutoUpThresh)/_Tune.Ratios[_CGear+2]/fFD) then
						if (_CGear ~= 0) and (_CGear ~= #_Tune.Ratios-2) then
							_GThrotShift = 0
							wait(_Tune.ShiftTime)
							_GThrotShift = 1
						end
						_CGear=math.min(_CGear+1,#_Tune.Ratios-2)
					elseif car.DriveSeat.Velocity.Magnitude < math.ceil(wDRatio*(_Tune.PeakRPM-_Tune.AutoDownThresh)/_Tune.Ratios[_CGear+1]/fFD) then
						if _CGear ~= 1 then
							_GThrotShift = 0
							wait(_Tune.ShiftTime/2)
							_GThrotShift = 1
						end
						_CGear=math.max(_CGear-1,1)
					end
				end
			end
		end
	end 
end

local tqTCS = 1
local sthrot = 0