func void shift(float $mindownrpm,float $maxdownrpm,float $minuprpm,float $maxuprpm,float $factor)
{
	rcar $car = get scriptowner car
	int $i
	int $gear = get $car gear
	float $rpm = get $car rpm
	float $brake = get $car brake
  	float $throttle = get $car throttle
	float $unthrottle = 1-$throttle
	float $shiftdown = $unthrottle*$mindownrpm+$throttle*$throttle*$maxdownrpm*$factor
    float $shiftup = $unthrottle*$minuprpm+$throttle*$maxuprpm*$factor //Used variables
	int $kickdown = 0
	rcarmodel $up = get generic model 10 of $car
	rcarmodel $down = get generic model 11 of $car
	set $up scriptcontrolled 1
	set $down scriptcontrolled 1
	float $clutch = get $car clutch
	if $gear < 1 or $clutch > 0.00
	{
		set $up position float[3]{0.0,-0.1,0.0}
		set $down position float[3]{0.0,-0.1,0.0}
	}
	if $rpm > $shiftdown and $rpm < $shiftup
	{
		set $up position float[3]{0.0,-0.1,0.0}
		set $down position float[3]{0.0,-0.1,0.0}
	}
	if ($shiftdown < $mindownrpm) //Avoid to low downshift...
	{
		$shiftdown=$mindownrpm
	}
	if ($shiftdown > $maxdownrpm)
	{
		$shiftdown=$maxdownrpm
	}
	if ($shiftup > $maxuprpm)
	{
		$shiftup = $maxuprpm
	}
	if $shiftup < $minuprpm
	{
		$shiftup = $minuprpm
	}
	if $rpm < $shiftdown 
	{
		//Downshift
		set $down position float[3]{0.0,0.0,0.0}
		set $up position float[3]{0.0,-0.1,0.0}
	}
	if $rpm > $shiftup and $throttle > 0.10 and $clutch == 0.0
	{
		//Up shift
		set $up position float[3]{0.0,00.0,0.0}
		set $down position float[3]{0.0,-0.1,0.0}
	}
}
rcar $car = get scriptowner car
rcar $localcar = get local car
float $gear
float $brake
float $throttle
int $interval = 500
while 1
{
	if $car == $localcar
	{
		float $indice_moteur = get system "car0.engine.inertia"
		$brake = get $car brake
		$throttle = get $car throttle
		float $rpm = get $car rpm
		$gear = get $car gear
		if $indice_moteur == 0.291
		{
			//Moteur 2.0dCi 180
			
			if $gear== 2 //Gear 1
			{
				shift(-10000,-10000,1700,3900,1.00) //0 and 0 first argument to avoid downshift in 1st :D
				wait($interval)
			}
			if $gear == 3 //Gear 2
			{
				shift(1200,2200,1800,3900,1.0)
				wait($interval)
			}
			if $gear == 4 //Gear 3
			{
				shift(1250,2100,1800,3900,1.0)
				wait($interval)
			}
			if $gear == 5 //Gear 4
			{
				shift(1275,2200,1800,3750,1.0)
				wait($interval)
			}
			if $gear == 6 //Gear 5
			{
				shift(1400,2300,1700,3750,1.0)
				wait($interval)
			}
			if $gear == 7 // Gear 6
			{
				shift(1600,2500,10000,10000,1.0)
				wait($interval)
			}	
		}
		if $indice_moteur == 0.185
		{
			//Moteur 2.0T 205
			
			if $gear== 2 //Gear 1
			{
				shift(-10000,-10000,1700,5000,1.00) //0 and 0 first argument to avoid downshift in 1st :D
				wait($interval)
			}
			if $gear == 3 //Gear 2
			{
				shift(1200,2900,1800,5000,1.0)
				wait($interval)
			}
			if $gear == 4 //Gear 3
			{
				shift(1250,3100,1800,5000,1.0)
				wait($interval)
			}
			if $gear == 5 //Gear 4
			{
				shift(1275,3300,1800,500,1.0)
				wait($interval)
			}
			if $gear == 6 //Gear 5
			{
				shift(1400,3500,1700,5000,1.0)
				wait($interval)
			}
			if $gear == 7 // Gear 6
			{
				shift(1600,3600,10000,10000,1.0)
				wait($interval)
			}	
		}
	}
interrupt
}
