//Focus on the car used by the script owner
rcar $car=get scriptowner car
float $rpm
float $throttle
float $upthrottle = 0
float $unthrottle = 0
float $clutch
float $diff
float $finalthrottle
int $gear
float $idle = 675
float $speed
while 1
{
	$rpm = get $car rpm
	$throttle = get $car throttle
	$clutch = get $car clutch
	$diff=($idle/1.0*$rpm)
	$gear = get $car gear
	$speed = get $car tachovelocity
	$speed = $speed*3.60
	if $rpm < $idle
	{
		$upthrottle+=0.05*$diff
	}
	if $rpm > 1.00*$idle
	{
		$upthrottle-=0.05*$diff
	}
	if $rpm > 1.10*$idle
	{
		$upthrottle = 0
	}
	if $upthrottle > 1
	{
		$upthrottle = 1
	}
	if $upthrottle < 0
	{
		$upthrottle = 0
	}
	if $unthrottle < -1
	{
		$unthrottle = -1
	}
	if $unthrottle > 0
	{
		$unthrottle = 0
	}
	$finalthrottle = $throttle + $upthrottle + $unthrottle
	if $finalthrottle > 1
	{
		$finalthrottle = 1
	}
	if $finalthrottle < 0
	{
		$finalthrottle = 0
	}
	if $gear > 2 and $clutch > 0.01 and $speed > 2
	{
		$idle = 750
	}
	else
	{
		$idle = 675
	}
	if $gear > 5 and $rpm > 3502
	{
		//$unthrottle-=0.01
	}
	else
	{
		$unthrottle+=0.01
	}
	set $car throttle $finalthrottle
	interrupt
}