//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 = 900.0
float $speed
float $temp = 20.0
rcarmodel $cam = get generic model 24 of $car
set $cam scriptcontrolled 1
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
	$temp+=0.008*((2.0*$throttle+0.01)*$rpm/50000.0)
	float $maxtorque = get $car maxtorque factor
	//echo $temp
	if $temp > 89.0
	{
		$temp = 89
	}
	if $temp > 0.0 and $temp < 30.0
	{
		$idle=925.0+((3.10*(30.0-$temp)))
		if $idle < 925.0
		{
			$idle = 925.0
		}
	}
	if $temp > 30.0 and $temp < 40.0
	{
		$idle=875.0+((3.80*(40.0-$temp)))
		if $idle < 875.0
		{
			$idle = 875.0
		}
	}
	if $temp > 40.0 and $temp < 50.0
	{
		$idle=850.0+((3.70*(50.0-$temp)))
		if $idle < 850.0
		{
			$idle = 850.0
		}
	}
	if $temp > 50.0 and $temp < 60.0
	{
		$idle=840.0+(3.80*(60.0-$temp))
		if $idle < 840.0
		{
			$idle = 840.0
		}
	}
	if $temp > 60.0 and $temp < 70.0
	{
		$idle=830.0+(5.0*(70.0-$temp))
		if $idle < 830.0
		{
			$idle = 830.0
		}
	}
	if $temp > 70.0 and $temp < 90.0
	{
		$idle=825.0
	}
	if $rpm < $idle
	{
		$upthrottle+=0.05*$diff
	}
	if $rpm > $idle
	{
		if $upthrottle > 0
		{
			$upthrottle-=0.05*$diff
		}
	}
	if $rpm > 1.12*$idle
	{
		$upthrottle = 0
	}
	if $upthrottle > 1
	{
		$upthrottle = 1
	}
	if $upthrottle < -1
	{
		$upthrottle = -1
	}
	$finalthrottle = $throttle + $upthrottle + $unthrottle
	if $finalthrottle > 1.01
	{
		$finalthrottle = 1.01
	}
	if $finalthrottle < 0
	{
		$finalthrottle = 0
	}
	if $gear > 2 and $clutch < 0.01 and $speed < 5 and $rpm < 850
	{
		$idle*=1.10
	}
	if $clutch > 0.05
	{
		$finalthrottle = ($throttle + $upthrottle + $unthrottle)*(1.00/$maxtorque)
	}
	if $clutch <= 0.05
	{
		$finalthrottle = ($throttle + $upthrottle + $unthrottle)*(1.00)
	}
	if $rpm < 600
	{
		$finalthrottle = $throttle
	}
	if $gear == 1
	{
		set $cam position float[3]{0,0,0.0}
	}
	else
	{
		set $cam position float[3]{0,-10,0.0}
	}
	if is key 70 pressed and $speed < 5
	{
		//Key F to stop engine
		send "stop engine" to console
	}
	if $finalthrottle > 1
	{
		$finalthrottle = 1
	}
	if $finalthrottle < 0
	{
		$finalthrottle = 0
	}
	//int $i = 0
	if $temp > -100
	{
		//$i++
		//echo "temperature moteur :"+$temp
		//echo $idle
		//echo $i
	}
	set $car throttle $finalthrottle
	interrupt
}